diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 4c0dac2141d388fff987deb0d1190ca040ed291e..49324572cebfbe34c1901c9f06890a1d7c6d1b04 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -466,19 +466,20 @@ class Population: raise ValueError(msg) def add_grid_variable( - self, - name: str, - longname: str, - valuerange: Union[list, str], - resolution: str, - spacingfunc: str, - probdist: str, - dphasevol: Union[str, int], - parameter_name: str, - gridtype: str = "centred", - branchpoint: int = 0, - precode: Union[str, None] = None, - condition: Union[str, None] = None, + self, + name: str, + longname: str, + valuerange: Union[list, str], + resolution: str, + spacingfunc: str, + probdist: str, + dphasevol: Union[str, int], + parameter_name: str, + gridtype: str = "centred", + branchpoint: int = 0, + precode: Union[str, None] = None, + postcode: Union[str, None] = None, + condition: Union[str, None] = None, ) -> None: """ Function to add grid variables to the grid_options. @@ -532,6 +533,8 @@ class Population: Examples: precode = 'M_1=math.exp(lnm1);' + postcode: + Code executed after the probability is calculated. probdist: Function determining the probability that gets assigned to the sampled parameter @@ -560,6 +563,7 @@ class Population: "resolution": resolution, "spacingfunc": spacingfunc, "precode": precode, + "postcode": postcode, "probdist": probdist, "dphasevol": dphasevol, "parameter_name": parameter_name, @@ -2473,6 +2477,7 @@ class Population: + "\n", ) + if grid_variable["grid_variable_number"] == 0: self._add_code( "probabilities_list[0] = d{}".format(grid_variable["name"]) + "\n" @@ -2487,6 +2492,18 @@ class Population: + "\n" ) + ############## + # postcode + if grid_variable["postcode"]: + self._add_code( + "{}".format( + grid_variable["postcode"].replace( + "\n", "\n" + self._indent_block(0) + ) + ) + + "\n" + ) + ####################### # Increment starcount for this parameter self._add_code( @@ -2614,7 +2631,10 @@ class Population: self.grid_options["gridcode_filename"] = gridcode_filename verbose_print( - "Writing grid code to {}".format(gridcode_filename), + "{}Writing grid code to {} [dry_run = {}]{}".format(self.ANSI_colours['blue'], + gridcode_filename, + dry_run, + self.ANSI_colours['reset']), self.grid_options["verbosity"], 1, )