Skip to content

Commit

Permalink
Merge pull request #152 from OMS-NetZero/fix-sc
Browse files Browse the repository at this point in the history
refactor fill_species_configs
  • Loading branch information
chrisroadmap authored Feb 15, 2024
2 parents c09bee8 + 3a6b5b0 commit 94dc9a2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 125 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
master
------

(`#152 <https://github.com/OMS-NetZero/FAIR/pull/152>`_) Refactor

(`#150 <https://github.com/OMS-NetZero/FAIR/pull/150>`_) Reformat for black update

(`#149 <https://github.com/OMS-NetZero/FAIR/pull/149>`_) Add nightly tests
Expand All @@ -19,7 +21,7 @@ v2.1.3
v2.1.2
------

(`#138 <https://github.com/OMS-NetZero/FAIR/pull/138>`_) Zenodo DOI error when using `pooch` fixed
(`#138 <https://github.com/OMS-NetZero/FAIR/pull/138>`_) Zenodo DOI error when using `pooch` fixed

v2.1.1
------
Expand Down
138 changes: 14 additions & 124 deletions src/fair/fair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -194,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.
Expand Down Expand Up @@ -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"],
Expand All @@ -615,113 +602,16 @@ def fill_species_configs(self, filename=DEFAULT_SPECIES_CONFIG_FILE):
specie=specie,
gasbox=gasbox,
)
if len(df.loc[df["type"] == "aci"]) > 0:
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,
self.species_configs["aci_scale"],
df.loc[df["type"] == "aci"].aci_scale,
)
fill(self.species_configs["g0"], df.loc[specie].g0, specie=specie)
fill(self.species_configs["g1"], df.loc[specie].g1, specie=specie)
if len(df.loc[df["type"] == "ch4"]) > 0:
fill(
self.species_configs["greenhouse_gas_radiative_efficiency"],
df.loc[specie].greenhouse_gas_radiative_efficiency,
specie=specie,
self.species_configs["lifetime_temperature_sensitivity"],
df.loc[df["type"] == "ch4"].lifetime_temperature_sensitivity,
)
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,
)
fill(
self.species_configs["lifetime_temperature_sensitivity"],
df.loc[df["type"] == "ch4"].lifetime_temperature_sensitivity,
)
self.calculate_concentration_per_emission()

# greenhouse gas convenience functions
Expand Down
31 changes: 31 additions & 0 deletions src/fair/structure/species_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Module that lists the species_configs."""

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",
]

0 comments on commit 94dc9a2

Please sign in to comment.