From 952a608c472aea66c64464c1985b7b420622cacb Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Tue, 9 Nov 2021 22:54:36 +0000
Subject: [PATCH] cleanup list comparisons

---
 binarycpython/utils/grid.py | 42 +++++++------------------------------
 1 file changed, 7 insertions(+), 35 deletions(-)

diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index 18bd0dc84..240f9f78b 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -1324,8 +1324,7 @@ class Population:
             self.grid_options["evolution_type"]
             in self.grid_options["_evolution_type_options"]
         ):
-            if self.grid_options["evolution_type"] == "grid" or \
-               self.grid_options["evolution_type"] == "custom_generator":
+            if self.grid_options["evolution_type"] in ["grid", "custom_generator"]:
                 self._evolve_population_grid()
 
             # elif self.grid_options["evolution_type"] == "mc":
@@ -2619,16 +2618,7 @@ class Population:
             # if we're sampling a continuous variable, we
             # have one fewer grid point than the length of the
             # sampled_values list
-            if (
-                    grid_variable["gridtype"] == "centred"
-                    or grid_variable["gridtype"] == "centre"
-                    or grid_variable["gridtype"] == "center"
-                    or grid_variable["gridtype"] == "edge"
-                    or grid_variable["gridtype"] == "left edge"
-                    or grid_variable["gridtype"] == "left"
-                    or grid_variable["gridtype"] == "right"
-                    or grid_variable["gridtype"] == "right edge"
-            ):
+            if ( grid_variable["gridtype"] in ["centred", "centre", "center", "edge", "left edge", "left", "right", "right edge"] ):
                 offset = -1
             elif grid_variable["gridtype"] == "discrete":
             # discrete variables sample all the points
@@ -2687,12 +2677,7 @@ class Population:
                     "\n",
                 )
 
-            elif (grid_variable["gridtype"] == "centred"
-                  or grid_variable["gridtype"] == "centre"
-                  or grid_variable["gridtype"] == "center"
-                  or grid_variable["gridtype"] == "edge"
-                  or grid_variable["gridtype"] == "left"
-                  or grid_variable["gridtype"] == "left edge"):
+            elif (grid_variable["gridtype"] in [ "centred","centre","center","edge","left","left edge" ] ):
 
                # left and centred grids
                 self._add_code("if {}_sample_number == 0:\n".format(grid_variable["name"]))
@@ -2705,8 +2690,7 @@ class Population:
                 self._add_code("{name}_next_index = {name}_this_index + 1".format(name=grid_variable["name"]))
                 self._add_code("\n")
 
-            elif(grid_variable["gridtype"] == "right" or
-                 grid_variable["gridtype"] == "right edge"):
+            elif(grid_variable["gridtype"] in [ "right", "right edge" ] ):
 
                 # right edged grid
                 self._add_code("if {name}_sample_number == 0:\n".format(name=grid_variable["name"]))
@@ -2724,8 +2708,7 @@ class Population:
                 # no phase volume required so set it to 1.0
                 self._add_code("dphasevol_{name} = 1.0 # 666\n".format(name=grid_variable["name"]))
 
-            elif(grid_variable["gridtype"] == "right" or
-                 grid_variable["gridtype"] == "right edge"):
+            elif(grid_variable["gridtype"] in [ "right", "right edge" ] ):
                 # right edges always have this and prev defined
                 self._add_code(
                     "dphasevol_{name} = (sampled_values_{name}[{name}_this_index] - sampled_values_{name}[{name}_prev_index])".format(name=grid_variable["name"])
@@ -2767,24 +2750,13 @@ class Population:
                 )
 
             # select sampled point location based on gridtype (left, centre or right)
-            if (
-                grid_variable["gridtype"] == "edge"
-                or grid_variable["gridtype"] == "left"
-                or grid_variable["gridtype"] == "left edge"
-                or grid_variable["gridtype"] == "right"
-                or grid_variable["gridtype"] == "right edge"
-                or grid_variable['gridtype'] == 'discrete'
-            ):
+            if ( grid_variable["gridtype"] in ["edge", "left", "left edge", "right", "right edge", "discrete" ] ):
                 self._add_code(
                     "{name} = sampled_values_{name}[{name}_this_index]".format(
                         name=grid_variable["name"])
                     + "\n"
                 )
-            elif (
-                grid_variable["gridtype"] == "centred"
-                or grid_variable["gridtype"] == "centre"
-                or grid_variable["gridtype"] == "center"
-            ):
+            elif ( grid_variable["gridtype"] in ["centred", "centre", "center"] ):
                 self._add_code(
                     "{name} = 0.5 * (sampled_values_{name}[{name}_next_index] + sampled_values_{name}[{name}_this_index])".format(name=grid_variable["name"])
                     + "\n"
-- 
GitLab