From c8140374e378a935a218c5ffa6646af0621cc178 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:27:08 +0000 Subject: [PATCH 1/7] refactor fill_species_configs --- src/fair/fair.py | 126 ++------------------------ src/fair/structure/species_configs.py | 29 ++++++ 2 files changed, 36 insertions(+), 119 deletions(-) create mode 100644 src/fair/structure/species_configs.py diff --git a/src/fair/fair.py b/src/fair/fair.py index 3c221fd6..fcfcb8f3 100644 --- a/src/fair/fair.py +++ b/src/fair/fair.py @@ -35,6 +35,7 @@ from .gas_cycle.inverse import unstep_concentration from .interface import fill from .structure.species import multiple_allowed, species_types, valid_input_modes +from .structure.species_configs import SPECIES_CONFIGS_EXCL_GASBOX from .structure.units import ( compound_convert, desired_concentration_units, @@ -582,26 +583,12 @@ def fill_species_configs(self, filename=DEFAULT_SPECIES_CONFIG_FILE): """ df = pd.read_csv(filename, index_col=0) for specie in self.species: - fill( - self.species_configs["tropospheric_adjustment"], - df.loc[specie].tropospheric_adjustment, - specie=specie, - ) - fill( - self.species_configs["forcing_efficacy"], - df.loc[specie].forcing_efficacy, - specie=specie, - ) - fill( - self.species_configs["forcing_temperature_feedback"], - df.loc[specie].forcing_temperature_feedback, - specie=specie, - ) - fill( - self.species_configs["forcing_scale"], - df.loc[specie].forcing_scale, - specie=specie, - ) + for config in SPECIES_CONFIGS_EXCL_GASBOX: + fill( + self.species_configs[config], + df.loc[specie, config], + specie=specie, + ) for gasbox in range(self._n_gasboxes): fill( self.species_configs["partition_fraction"], @@ -615,105 +602,6 @@ def fill_species_configs(self, filename=DEFAULT_SPECIES_CONFIG_FILE): specie=specie, gasbox=gasbox, ) - fill( - self.species_configs["molecular_weight"], - df.loc[specie].molecular_weight, - specie=specie, - ) - fill( - self.species_configs["baseline_concentration"], - df.loc[specie].baseline_concentration, - specie=specie, - ) - fill( - self.species_configs["forcing_scale"], - df.loc[specie].forcing_scale, - specie=specie, - ) - fill( - self.species_configs["forcing_reference_concentration"], - df.loc[specie].forcing_reference_concentration, - specie=specie, - ) - fill(self.species_configs["iirf_0"], df.loc[specie].iirf_0, specie=specie) - fill( - self.species_configs["iirf_airborne"], - df.loc[specie].iirf_airborne, - specie=specie, - ) - fill( - self.species_configs["iirf_uptake"], - df.loc[specie].iirf_uptake, - specie=specie, - ) - fill( - self.species_configs["iirf_temperature"], - df.loc[specie].iirf_temperature, - specie=specie, - ) - fill( - self.species_configs["baseline_emissions"], - df.loc[specie].baseline_emissions, - specie=specie, - ) - fill(self.species_configs["g0"], df.loc[specie].g0, specie=specie) - fill(self.species_configs["g1"], df.loc[specie].g1, specie=specie) - fill( - self.species_configs["greenhouse_gas_radiative_efficiency"], - df.loc[specie].greenhouse_gas_radiative_efficiency, - specie=specie, - ) - fill( - self.species_configs["contrails_radiative_efficiency"], - df.loc[specie].contrails_radiative_efficiency, - specie=specie, - ) - fill( - self.species_configs["erfari_radiative_efficiency"], - df.loc[specie].erfari_radiative_efficiency, - specie=specie, - ) - fill( - self.species_configs["h2o_stratospheric_factor"], - df.loc[specie].h2o_stratospheric_factor, - specie=specie, - ) - fill( - self.species_configs["lapsi_radiative_efficiency"], - df.loc[specie].lapsi_radiative_efficiency, - specie=specie, - ) - fill( - self.species_configs["land_use_cumulative_emissions_to_forcing"], - df.loc[specie].land_use_cumulative_emissions_to_forcing, - specie=specie, - ) - fill( - self.species_configs["ozone_radiative_efficiency"], - df.loc[specie].ozone_radiative_efficiency, - specie=specie, - ) - fill( - self.species_configs["cl_atoms"], df.loc[specie].cl_atoms, specie=specie - ) - fill( - self.species_configs["br_atoms"], df.loc[specie].br_atoms, specie=specie - ) - fill( - self.species_configs["fractional_release"], - df.loc[specie].fractional_release, - specie=specie, - ) - fill( - self.species_configs["ch4_lifetime_chemical_sensitivity"], - df.loc[specie].ch4_lifetime_chemical_sensitivity, - specie=specie, - ) - fill( - self.species_configs["aci_shape"], - df.loc[specie].aci_shape, - specie=specie, - ) fill( self.species_configs["aci_scale"], df.loc[df["type"] == "aci"].aci_scale, diff --git a/src/fair/structure/species_configs.py b/src/fair/structure/species_configs.py new file mode 100644 index 00000000..82b8564d --- /dev/null +++ b/src/fair/structure/species_configs.py @@ -0,0 +1,29 @@ +SPECIES_CONFIGS_EXCL_GASBOX = [ + "tropospheric_adjustment", + "forcing_efficacy", + "forcing_temperature_feedback", + "forcing_scale", + "molecular_weight", + "baseline_concentration", + "forcing_scale", + "forcing_reference_concentration", + "iirf_0", + "iirf_airborne", + "iirf_uptake", + "iirf_temperature", + "baseline_emissions", + "g0", + "g1", + "greenhouse_gas_radiative_efficiency", + "contrails_radiative_efficiency", + "erfari_radiative_efficiency", + "h2o_stratospheric_factor", + "lapsi_radiative_efficiency", + "land_use_cumulative_emissions_to_forcing", + "ozone_radiative_efficiency", + "cl_atoms", + "br_atoms", + "fractional_release", + "ch4_lifetime_chemical_sensitivity", + "aci_shape", +] From b609ff6ade2c467defd2f4c72af62e27a0fd7dbe Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:29:52 +0000 Subject: [PATCH 2/7] update changelog --- CHANGELOG.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6af1929a..b5aa3e03 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,8 @@ Changelog master ------ +(`#151 `_) Refactor + (`#150 `_) Reformat for black update (`#149 `_) Add nightly tests @@ -19,7 +21,7 @@ v2.1.3 v2.1.2 ------ -(`#138 `_) Zenodo DOI error when using `pooch` fixed +(`#138 `_) Zenodo DOI error when using `pooch` fixed v2.1.1 ------ From 0e7c6b863e002661574931ba7d2026e46fd812ff Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:31:20 +0000 Subject: [PATCH 3/7] add docstring --- src/fair/structure/species_configs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fair/structure/species_configs.py b/src/fair/structure/species_configs.py index 82b8564d..ef4fda50 100644 --- a/src/fair/structure/species_configs.py +++ b/src/fair/structure/species_configs.py @@ -1,3 +1,7 @@ +""" +Module that lists the species_configs +""" + SPECIES_CONFIGS_EXCL_GASBOX = [ "tropospheric_adjustment", "forcing_efficacy", From db5e660217bf74731752acd67de8320ed92588c1 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:32:12 +0000 Subject: [PATCH 4/7] correct PR number@ --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b5aa3e03..e55ea8ea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog master ------ -(`#151 `_) Refactor +(`#152 `_) Refactor (`#150 `_) Reformat for black update From fa01f4db02f2bbe1affb5ea373ce25d976d9f717 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:35:20 +0000 Subject: [PATCH 5/7] this is getting old --- src/fair/structure/species_configs.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fair/structure/species_configs.py b/src/fair/structure/species_configs.py index ef4fda50..42c4681d 100644 --- a/src/fair/structure/species_configs.py +++ b/src/fair/structure/species_configs.py @@ -1,6 +1,4 @@ -""" -Module that lists the species_configs -""" +"""Module that lists the species_configs""" SPECIES_CONFIGS_EXCL_GASBOX = [ "tropospheric_adjustment", From 83a31771c5182b9da96253331cf46a9134bc1555 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 22:37:45 +0000 Subject: [PATCH 6/7] moan moan moan --- src/fair/structure/species_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fair/structure/species_configs.py b/src/fair/structure/species_configs.py index 42c4681d..ce36791b 100644 --- a/src/fair/structure/species_configs.py +++ b/src/fair/structure/species_configs.py @@ -1,4 +1,4 @@ -"""Module that lists the species_configs""" +"""Module that lists the species_configs.""" SPECIES_CONFIGS_EXCL_GASBOX = [ "tropospheric_adjustment", From 3a6b5b07d154d609b90dd635be682d7808674c45 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 15 Feb 2024 23:27:02 +0000 Subject: [PATCH 7/7] only fill aci_scale and lifetime_temperature if we request ACI or CH4 --- src/fair/fair.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/fair/fair.py b/src/fair/fair.py index fcfcb8f3..c6b0c4fb 100644 --- a/src/fair/fair.py +++ b/src/fair/fair.py @@ -195,7 +195,7 @@ def define_species(self, species, properties): "co2 ffi", "co2 afolu", "co2", "ch4", "n2o", "cfc-11", "other halogen", "f-gas", "sulfur", "black carbon", "organic carbon", "other slcf", "nox aviation", "eesc", "ozone", - "ari", "aci", "contrails", "lapsi","h2o stratospheric", "land use", + "ari", "aci", "contrails", "lapsi", "h2o stratospheric", "land use", "volcanic", "solar", "unspecified", ``input_mode`` : {'emissions', 'concentration', 'forcing', 'calculated'} describes how the specie is input into the model. @@ -602,14 +602,16 @@ def fill_species_configs(self, filename=DEFAULT_SPECIES_CONFIG_FILE): specie=specie, gasbox=gasbox, ) - fill( - self.species_configs["aci_scale"], - df.loc[df["type"] == "aci"].aci_scale, - ) - fill( - self.species_configs["lifetime_temperature_sensitivity"], - df.loc[df["type"] == "ch4"].lifetime_temperature_sensitivity, - ) + if len(df.loc[df["type"] == "aci"]) > 0: + fill( + self.species_configs["aci_scale"], + df.loc[df["type"] == "aci"].aci_scale, + ) + if len(df.loc[df["type"] == "ch4"]) > 0: + fill( + self.species_configs["lifetime_temperature_sensitivity"], + df.loc[df["type"] == "ch4"].lifetime_temperature_sensitivity, + ) self.calculate_concentration_per_emission() # greenhouse gas convenience functions