From b0bcb8972dbeea3aa987cb95460c5c06acfaa4f2 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Mon, 11 Oct 2021 22:42:56 +0100
Subject: [PATCH] add postcode

make gridcode filename blue
---
 binarycpython/utils/grid.py | 48 ++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index 4c0dac214..49324572c 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,
         )
-- 
GitLab