OMS-NetZero / FAIR

Finite-amplitude Impulse Response simple climate model
https://docs.fairmodel.net
Apache License 2.0
132 stars 63 forks source link

Forcing scale affecting forcing from Aerosol-radiation interactions #168

Closed colemanmr closed 1 week ago

colemanmr commented 2 weeks ago

Describe the bug

A clear and concise description of what the bug is.

The 'forcing_scale' species config scales the 'erfari_radiative_efficiency', not just the 'greenhouse_gas_radiative_efficiency', which may not be intended functionality. This changes the 'Aerosol-radiation interactions' species forcing when FaIR is run. This happens for both CH4 and a custom species I made (H2). Note: the scaling does not scale the 'ozone_radiative_efficiency' or 'h2o_stratospheric_factor', which is correct.

Failing Test

Please put the code (ideally in the form of a unit test) which fails below

from fair import FAIR f = FAIR()

f.define_time(2000, 2005, 1)

f.define_scenarios(['scenario_1'])

f.define_configs(['config_1'])

species = ['CH4', 'Ozone', 'Aerosol-radiation interactions']

from fair.io import read_properties species, properties = read_properties(species=species) f.define_species(species, properties)

f.ghg_method = 'leach2021' f.ch4_method = 'thornhill2021'

f.allocate()

from fair.interface import initialise, fill

fill(f.climate_configs["ocean_heat_transfer"], [1.1, 1.6, 0.9], config='config_1') fill(f.climate_configs["ocean_heat_capacity"], [8, 14, 100], config='config_1') fill(f.climate_configs["deep_ocean_efficacy"], 1.1, config='config_1')

initialise(f.concentration, 0, specie='CH4') initialise(f.forcing, 0) initialise(f.temperature, 0) initialise(f.cumulative_emissions, 0) initialise(f.airborne_emissions, 0) initialise(f.ocean_heat_content_change, 0)

fill(f.species_configs["baseline_concentration"], 0, specie="CH4") fill(f.species_configs["forcing_reference_concentration"], 0, specie="CH4")

fill(f.emissions, 500, specie='CH4')

f.fill_species_configs() f.species_configs

fill(f.species_configs['forcing_scale'], 1, specie='CH4')

f.run()

import copy no_scale_forcing = copy.deepcopy(f.forcing)

f.gas_partitions.data[:, :, :, 0] = 0

fill(f.species_configs['forcing_scale'], 1.5, specie='CH4')

f.run()

with_scale_forcing = copy.deepcopy(f.forcing)

print('Without scaling:') print('ch4 forcing: ', no_scale_forcing[:,0,0,0].data) print('o3 forcing: ' , no_scale_forcing[:,0,0,1].data) print('aer forcing: ', no_scale_forcing[:,0,0,2].data)

print('With scaling:') print('ch4 forcing: ', with_scale_forcing[:,0,0,0].data) print('o3 forcing: ' , with_scale_forcing[:,0,0,1].data) print('aer forcing: ', with_scale_forcing[:,0,0,2].data)

from numpy.testing import assert_array_equal

assert_array_equal(with_scale_forcing[:,0,0,2],\ no_scale_forcing[:,0,0,2], verbose=True)

Expected behavior

I think expected behaviour would be that the forcing scale does not affect the radiative forcing associated with the 'Aerosol-radiation interactions specie'. So the assert test above should pass.

Screenshots

If applicable, add screenshots to help explain your problem.

n/a

System (please complete the following information):

Additional context

Add any other context about the problem here.

n/a

chrisroadmap commented 1 week ago

yep, looks like this is the offending line

https://github.com/OMS-NetZero/FAIR/blob/bb2efd186307bc6d185da3247965a172b4457e45/src/fair/fair.py#L1451C1-L1451C58

which should probably be

forcing_scale_array[None, None, :, self._ari_indices]

will test this out

colemanmr commented 1 week ago

Great thank you for resolving that Chris