Beispiel #1
0
    def __init__(self,
                 dt_seconds=1800,
                 nx=64,
                 ny=32,
                 nz=10,
                 state=None,
                 input_fields_to_store=input_vars,
                 output_fields_to_store=output_vars,
                 input_save_fn=None,
                 output_save_fn=None,
                 save_interval=6,
                 convection=None,
                 extra_components=[]):
        """
        Initialize model. Uses SSTs from Andersen and Kuang 2012.
        Creates initial state unless state is given.
        """
        climt.set_constants_from_dict(
            {'stellar_irradiance': {
                'value': 200,
                'units': 'W m^-2'
            }})

        self.model_time_step = timedelta(seconds=dt_seconds)
        self.step_counter = 0
        self.save_interval = save_interval

        # Create components
        if convection is None:
            convection = climt.EmanuelConvection(
                tendencies_in_diagnostics=True)
        simple_physics = TimeDifferencingWrapper(
            climt.SimplePhysics(tendencies_in_diagnostics=True))

        radiation = climt.GrayLongwaveRadiation(tendencies_in_diagnostics=True)

        components = [simple_physics, radiation, convection] + extra_components

        self.dycore = climt.GFSDynamicalCore(components,
                                             number_of_damped_levels=2)
        grid = climt.get_grid(nx=nx, ny=ny, nz=nz)

        if state is None:
            self.create_initial_state(grid)
        else:
            self.state = state

        if not input_save_fn is None:
            self.input_netcdf_monitor = NetCDFMonitor(
                input_save_fn,
                write_on_store=True,
                store_names=input_fields_to_store)
        if not output_save_fn is None:
            self.output_netcdf_monitor = NetCDFMonitor(
                output_save_fn,
                write_on_store=True,
                store_names=output_fields_to_store)
Beispiel #2
0
def test_adding_constant():

    set_constants_from_dict(sample_constants)

    for constant in sample_constants.keys():

        constant_value = get_constant(constant,
                                      sample_constants[constant]['units'])

        assert constant_value == sample_constants[constant]['value']
NUM_TILES = NUM_ROWS*NUM_COLS
TILE_WIDTH = 5
LOOP_MS = 150  # ms per frame
CURRENT_DRAW = 'alt'


# Set up the climate model

fields_to_store = ['air_temperature', 'air_pressure', 'eastward_wind',
                   'northward_wind', 'air_pressure_on_interface_levels',
                   'surface_pressure', 'upwelling_longwave_flux_in_air',
                   'specific_humidity', 'surface_temperature',
                   'latitude', 'longitude',
                   'convective_heating_rate']

climt.set_constants_from_dict({
    'stellar_irradiance': {'value': 200, 'units': 'W m^-2'}})

model_time_step = timedelta(seconds=600)
# Create components


convection = climt.EmanuelConvection()
simple_physics = TimeDifferencingWrapper(climt.SimplePhysics())

constant_duration = 6

radiation_lw = UpdateFrequencyWrapper(
    climt.RRTMGLongwave(), constant_duration*model_time_step)

radiation_sw = UpdateFrequencyWrapper(
    climt.RRTMGShortwave(), constant_duration*model_time_step)
Beispiel #4
0
    def init_radiative_state(self, atmosphere, surface):

        climt.set_constants_from_dict({
            "stellar_irradiance": {
                "value": self.solar_constant,
                "units": 'W m^-2'
            }
        })
        if self._is_mcica:
            overlap = 'maximum_random'
        else:
            overlap = 'random'
        self._rad_lw = climt.RRTMGLongwave(
            cloud_optical_properties=self._cloud_optical_properties,
            cloud_ice_properties=self._cloud_ice_properties,
            cloud_liquid_water_properties='radius_dependent_absorption',
            cloud_overlap_method=overlap,
            mcica=self._is_mcica)
        self._rad_sw = climt.RRTMGShortwave(
            ignore_day_of_year=True,
            cloud_optical_properties=self._cloud_optical_properties,
            cloud_ice_properties=self._cloud_ice_properties,
            cloud_liquid_water_properties='radius_dependent_absorption',
            cloud_overlap_method=overlap,
            mcica=self._is_mcica)
        state_lw = {}
        state_sw = {}

        plev = atmosphere['plev']
        phlev = atmosphere['phlev']
        numlevels = len(plev)

        for state0 in state_lw, state_sw:
            state0['mid_levels'] = DataArray(np.arange(0, numlevels),
                                             dims=('mid_levels', ),
                                             attrs={'label': 'mid_levels'})

            state0['interface_levels'] = DataArray(
                np.arange(0, numlevels + 1),
                dims=('interface_levels', ),
                attrs={'label': 'interface_levels'})

            state0['air_pressure'] = DataArray(plev,
                                               dims=('mid_levels', ),
                                               attrs={'units': 'Pa'})

            state0['air_pressure_on_interface_levels'] = DataArray(
                phlev, dims=('interface_levels', ), attrs={'units': 'Pa'})

            state0['time'] = datetime.datetime(2000, 1, 1)

        ### Aerosols ###
        # TODO: Should all the aerosol values be zero?!
        # Longwave specific
        num_lw_bands = self._rad_lw.num_longwave_bands

        state_lw['longwave_optical_thickness_due_to_aerosol'] = DataArray(
            np.zeros((num_lw_bands, numlevels)),
            dims=('num_longwave_bands', 'mid_levels'),
            attrs={'units': 'dimensionless'})
        state_lw['surface_longwave_emissivity'] = DataArray(
            surface.longwave_emissivity * np.ones((num_lw_bands, )),
            dims=('num_longwave_bands'),
            attrs={'units': 'dimensionless'})

        # Shortwave specific changes
        num_sw_bands = self._rad_sw.num_shortwave_bands

        num_aerosols = self._rad_sw.num_ecmwf_aerosols
        state_sw['aerosol_optical_depth_at_55_micron'] = DataArray(
            np.zeros((num_aerosols, numlevels)),
            dims=('num_ecmwf_aerosols', 'mid_levels'),
            attrs={'units': 'dimensionless'})
        state_sw['solar_cycle_fraction'] = DataArray(
            0, attrs={'units': 'dimensionless'})
        state_sw['flux_adjustment_for_earth_sun_distance'] = DataArray(
            1, attrs={'units': 'dimensionless'})

        for surface_albedo in [
                'surface_albedo_for_diffuse_near_infrared',
                'surface_albedo_for_direct_near_infrared',
                'surface_albedo_for_diffuse_shortwave',
                'surface_albedo_for_direct_shortwave'
        ]:
            state_sw[surface_albedo] = DataArray(
                np.array(float(surface.albedo)),
                attrs={'units': 'dimensionless'})

        for quant in [
                'shortwave_optical_thickness_due_to_aerosol',
                'single_scattering_albedo_due_to_aerosol',
                'aerosol_asymmetry_parameter'
        ]:
            state_sw[quant] = DataArray(np.zeros((num_sw_bands, numlevels)),
                                        dims=('num_shortwave_bands',
                                              'mid_levels'),
                                        attrs={'units': 'dimensionless'})

        return state_lw, state_sw
Beispiel #5
0
    def init_radiative_state(self, atmosphere, surface):

        climt.set_constants_from_dict({
            "stellar_irradiance": {
                "value": self.solar_constant,
                "units": "W m^-2"
            }
        })
        if self._is_mcica:
            overlap = "maximum_random"
        else:
            overlap = "random"
        self._rad_lw = climt.RRTMGLongwave(
            cloud_optical_properties=self._cloud_optical_properties,
            cloud_ice_properties=self._cloud_ice_properties,
            cloud_liquid_water_properties="radius_dependent_absorption",
            cloud_overlap_method=overlap,
            mcica=self._is_mcica,
        )
        self._rad_sw = climt.RRTMGShortwave(
            ignore_day_of_year=True,
            cloud_optical_properties=self._cloud_optical_properties,
            cloud_ice_properties=self._cloud_ice_properties,
            cloud_liquid_water_properties="radius_dependent_absorption",
            cloud_overlap_method=overlap,
            mcica=self._is_mcica,
        )
        state_lw = {}
        state_sw = {}

        plev = atmosphere["plev"]
        phlev = atmosphere["phlev"]
        numlevels = len(plev)

        for state0 in state_lw, state_sw:
            state0["mid_levels"] = DataArray(
                np.arange(0, numlevels),
                dims=("mid_levels", ),
                attrs={"label": "mid_levels"},
            )

            state0["interface_levels"] = DataArray(
                np.arange(0, numlevels + 1),
                dims=("interface_levels", ),
                attrs={"label": "interface_levels"},
            )

            state0["air_pressure"] = DataArray(plev,
                                               dims=("mid_levels", ),
                                               attrs={"units": "Pa"})

            state0["air_pressure_on_interface_levels"] = DataArray(
                phlev, dims=("interface_levels", ), attrs={"units": "Pa"})

            state0["time"] = datetime.datetime(2000, 1, 1)

        ### Aerosols ###
        # TODO: Should all the aerosol values be zero?!
        # Longwave specific
        num_lw_bands = self._rad_lw.num_longwave_bands

        state_lw["longwave_optical_thickness_due_to_aerosol"] = DataArray(
            np.zeros((num_lw_bands, numlevels)),
            dims=("num_longwave_bands", "mid_levels"),
            attrs={"units": "dimensionless"},
        )
        state_lw["surface_longwave_emissivity"] = DataArray(
            surface.longwave_emissivity * np.ones((num_lw_bands, )),
            dims=("num_longwave_bands"),
            attrs={"units": "dimensionless"},
        )

        # Shortwave specific changes
        num_sw_bands = self._rad_sw.num_shortwave_bands

        num_aerosols = self._rad_sw.num_ecmwf_aerosols
        state_sw["aerosol_optical_depth_at_55_micron"] = DataArray(
            np.zeros((num_aerosols, numlevels)),
            dims=("num_ecmwf_aerosols", "mid_levels"),
            attrs={"units": "dimensionless"},
        )
        state_sw["solar_cycle_fraction"] = DataArray(
            0, attrs={"units": "dimensionless"})
        state_sw["flux_adjustment_for_earth_sun_distance"] = DataArray(
            1, attrs={"units": "dimensionless"})

        for surface_albedo in [
                "surface_albedo_for_diffuse_near_infrared",
                "surface_albedo_for_direct_near_infrared",
                "surface_albedo_for_diffuse_shortwave",
                "surface_albedo_for_direct_shortwave",
        ]:
            state_sw[surface_albedo] = DataArray(
                np.array(float(surface.albedo)),
                attrs={"units": "dimensionless"})

        for quant in [
                "shortwave_optical_thickness_due_to_aerosol",
                "single_scattering_albedo_due_to_aerosol",
                "aerosol_asymmetry_parameter",
        ]:
            state_sw[quant] = DataArray(
                np.zeros((num_sw_bands, numlevels)),
                dims=("num_shortwave_bands", "mid_levels"),
                attrs={"units": "dimensionless"},
            )

        return state_lw, state_sw