Skip to content

Commit

Permalink
Update unit labels in Scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
kemccusker committed Sep 20, 2021
1 parent 6ea7084 commit 6bdb27e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions fair/Scenario/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# https://www.google.com/url?q=https%3A%2F%2Frcmip-protocols-au.s3-ap-southeast-2.amazonaws.com%2Fv5.1.0%2Frcmip-emissions-annual-means-v5-1-0.csv&sa=D&sntz=1&usg=AFQjCNHJCbRZjljHC4Y_Qe8QtRlNlXlkNQ
emissions_filename = os.path.join(
os.path.dirname(__file__), 'data/rcmip-emissions-annual-means-v5-1-0-ssprcp-only.csv')

# TODO: add implementation of concentrations and forcings


Expand All @@ -41,7 +42,10 @@ def _convert_emissions_to_fair_units(emissions_df):
unit_convert = np.ones(40)
unit_convert[1] = molwt.C/molwt.CO2/1000 # CO2 fossil
unit_convert[2] = molwt.C/molwt.CO2/1000 # CO2 land use
unit_convert[4] = molwt.N2/molwt.N2O/1000 # N2O
# Notes about N2O
# previous (CMIP5) RCPs units: MtN2O-N/yr.
# current (CMIP6) SSP units: ktN20/yr
unit_convert[4] = molwt.N2/molwt.N2O/1000 # N2O # this is for CMIP6. converts from ktN2O to T N2
unit_convert[5] = molwt.S/molwt.SO2 # SO2
unit_convert[8] = molwt.N/molwt.NO2 # NOx

Expand All @@ -55,7 +59,8 @@ def _read_emissions(ssp):
# obtained from https://www.rcmip.org/
rcemissions = pd.read_csv(emissions_filename)
emissions = rcemissions.loc[rcemissions.Scenario==ssp]
emissions = emissions.loc[emissions.Region=='World'].set_index('Variable').drop(columns=['Activity_Id', 'Mip_Era', 'Region', 'Model','Scenario', 'Unit']).T
emissions = emissions.loc[emissions.Region=='World'].set_index('Variable').drop(
columns=['Activity_Id', 'Mip_Era', 'Region', 'Model','Scenario', 'Unit']).T
emissions.index = emissions.index.rename('Years')
emissions.index = emissions.index.astype('int')

Expand Down Expand Up @@ -123,11 +128,22 @@ def _get_ordered_gas_column_names():
'Emissions|Montreal Gases|CH3Cl' ]

def _get_ordered_emissions_units(ssp):
# Returns FaIR emissions units

# rcmip emissions have some gases that require unit conversions
# so they match what fair expects. Manually update those units to fair units here
# (see _convert_emissions_to_fair_units() above)
# Here the first index is a gas (not "year")

rcemissions = _get_emissions_units(ssp=ssp)
ordered_names = _get_ordered_gas_column_names()

return rcemissions[ordered_names]
units = rcemissions[ordered_names]
units[0] = "Gt C/year"
units[1] = "Gt C/year"
units[3] = "tonnes N2/year"
units[4] = "Mt S/year"
units[7] = "Mt N/year"
return units

def _prepare_rcmip_scenario(ssp, interp=True):

Expand Down Expand Up @@ -256,10 +272,16 @@ def get_gas_species_names(self):


def get_gas_species_units(self):

# return the gas unit strings
units = _get_ordered_emissions_units(ssp=self.scenario).values

return ['year',] + list(units)
return list(units)

def get_emissions_unit_labels(self):
# returns unit label string for all 40 members of FaIR emissions (including year at idx=0)
gas_names = self.get_gas_species_names()

return ['Year'] + gas_names

def get_emissions_array_labels(self):

Expand Down

0 comments on commit 6bdb27e

Please sign in to comment.