예제 #1
0
def test_get_diagnostics_with_real_component():
    dummy = RRTMGLongwave()
    state = get_default_state([dummy])

    diag = dummy.create_state_dict_for('_climt_diagnostics', state)

    for quantity in dummy._climt_diagnostics:
        assert quantity in diag
예제 #2
0
    def test_rrtmg_logging(self, caplog):
        caplog.set_level(logging.INFO)
        RRTMGLongwave(mcica=True, cloud_overlap_method='clear_only')
        assert 'no clouds' in caplog.text
        caplog.clear()

        RRTMGLongwave(mcica=True, cloud_optical_properties='single_cloud_type')
        assert "must be 'direct_input' or " \
               "'liquid_and_ice_clouds'" in caplog.text
예제 #3
0
def test_get_inputs_with_real_component():
    dummy = RRTMGLongwave()
    state = get_default_state([dummy])

    diag = dummy.create_state_dict_for('_climt_inputs', state)

    for quantity in dummy._climt_inputs:
        assert quantity in diag
        assert diag[quantity].dims == state[quantity].dims
예제 #4
0
def test_extracting_arrays_from_real_component():
    dummy = RRTMGLongwave()
    state = get_default_state([dummy])

    arrays = dummy.get_numpy_arrays_from_state('_climt_inputs', state)

    for quantity in dummy._climt_inputs.keys():
        units = dummy._climt_inputs[quantity]
        state_values = state[quantity].to_units(units).values
        assert np.all(arrays[quantity] == state_values)
예제 #5
0
    def get_component_instance(self, state_modification_func=lambda x: x):
        dycore = GFSDynamicalCore(number_of_longitudes=68,
                                  number_of_latitudes=32)
        radiation = RRTMGLongwave()
        dycore.prognostics = [radiation]

        return dycore
예제 #6
0
 def get_component_instance(self):
     # Create Radiation Prognostic
     radiation = RRTMGLongwave()
     # Create Convection Prognostic
     convection = EmanuelConvection()
     # Create a SimplePhysics Prognostic
     boundary_layer = TimeDifferencingWrapper(SimplePhysics())
     return GFSDynamicalCore([radiation, convection, boundary_layer])
예제 #7
0
def test_get_diagnostics_with_real_component_with_2d_coordinates():
    dummy = RRTMGLongwave()
    state = get_default_state([dummy],
                              x=dict(label='shore',
                                     values=np.random.randn(2, 2),
                                     units='km'),
                              y=dict(label='latitude',
                                     values=np.random.randn(2, 2),
                                     units='degrees east'))

    diag = dummy.create_state_dict_for('_climt_diagnostics', state)

    for quantity in dummy.diagnostics:
        assert quantity in diag
        assert 'shore' in diag[quantity].coords
        assert 'latitude' in diag[quantity].coords
        assert diag[quantity].coords['shore'].ndim == 2
        assert diag[quantity].coords['latitude'].ndim == 2
예제 #8
0
def tests_dycore_with_prognostic_attrs_are_sane():

    dycore = GFSDynamicalCore(number_of_longitudes=68, number_of_latitudes=32)
    radiation = RRTMGLongwave()
    dycore.prognostics = [radiation]

    for quantity in radiation.diagnostics:
        assert quantity in dycore.diagnostics

    for quantity in radiation.inputs:
        assert quantity in dycore.inputs
예제 #9
0
def test_piecewise_constant_component():

    radiation = RRTMGLongwave()
    radiation = radiation.piecewise_constant_version(timedelta(seconds=1000))

    state = climt.get_default_state([radiation])

    current_tendency, current_diagnostic = radiation(state)

    # Perturb state
    state['air_temperature'] += 3

    new_tendency, new_diagnostic = radiation(state)

    assert np.all(current_tendency['air_temperature'].values ==
                  new_tendency['air_temperature'].values)

    state['time'] += timedelta(seconds=1500)

    new_tendency, new_diagnostic = radiation(state)

    assert np.any(current_tendency['air_temperature'].values !=
                  new_tendency['air_temperature'].values)
예제 #10
0
    def get_3d_input_state(self):

        component = self.get_component_instance()
        prognostic = RRTMGLongwave()
        state = climt.get_default_state(
            [component, prognostic],
            x=component.grid_definition['x'],
            y=component.grid_definition['y'],
            mid_levels=component.grid_definition['mid_levels'],
            interface_levels=component.grid_definition['interface_levels'])

        dcmip = climt.DcmipInitialConditions()
        out = dcmip(state, add_perturbation=True)
        state.update(out)

        return state
예제 #11
0
    Lsun = 3.828e26
    AU = 149597870700.0
    distance = distance * AU
    return Lsun / (4 * math.pi * distance**2.0)


def getAU(lum):
    Lsun = 3.828e26
    AU = 149597870700.0
    return math.sqrt(Lsun / (4 * math.pi * lum)) / AU


monitor = PlotFunctionMonitor(plot_function)
rad_sw = RRTMGShortwave(cloud_overlap_method=0,
                        solar_constant=solarConstant(0.65))
rad_lw = RRTMGLongwave(cloud_overlap_method=0)
time_stepper = AdamsBashforth([rad_sw, rad_lw])
timestep = timedelta(hours=1)

mid_levels = {'label': 'mid_level', 'values': np.arange(60), 'units': ''}

int_levels = {'label': 'interface_level', 'values': np.arange(61), 'units': ''}
state = get_default_state([rad_sw, rad_lw],
                          mid_levels=mid_levels,
                          interface_levels=int_levels)

tp_profiles = np.load('thermodynamic_profiles.npz')
mol_profiles = np.load('molecule_profiles.npz')
co2_input_array = mol_profiles["carbon_dioxide"]

state["g"] = 25.0
예제 #12
0
 def get_component_instance(self):
     return RRTMGLongwave(cloud_optical_properties='single_cloud_type')
예제 #13
0
 def get_component_instance(self, state_modification_func=lambda x: x):
     return RRTMGLongwave(cloud_optical_properties='single_cloud_type')
예제 #14
0
 def get_component_instance(self, state_modification_func=lambda x: x):
     return RRTMGLongwave(calculate_interface_temperature=False)
예제 #15
0
 def get_component_instance(self, state_modification_func=lambda x: x):
     return RRTMGLongwave()
        state['air_pressure_on_interface_levels'].to_units(
            'mbar').values.flatten(), '-o')
    ax.set_title('Net Flux')
    ax.axes.invert_yaxis()
    ax.set_xlabel('W/m^2')
    ax.grid()
    plt.tight_layout()


monitor = PlotFunctionMonitor(plot_function)

timestep = timedelta(minutes=5)

convection = EmanuelConvection()
radiation_sw = RRTMGShortwave()
radiation_lw = RRTMGLongwave()
slab = SlabSurface()
simple_physics = SimplePhysics()

store_quantities = [
    'air_temperature', 'air_pressure', 'specific_humidity',
    'air_pressure_on_interface_levels',
    'air_temperature_tendency_from_convection',
    'air_temperature_tendency_from_longwave',
    'air_temperature_tendency_from_shortwave'
]
netcdf_monitor = NetCDFMonitor('rad_conv_eq.nc',
                               store_names=store_quantities,
                               write_on_store=True)
convection.current_time_step = timestep
예제 #17
0
    ax = fig.add_subplot(1, 2, 2)
    ax.plot(state['air_temperature'].values.flatten(),
            state['air_pressure'].values.flatten(), '-o')
    ax.axes.invert_yaxis()

    ax.set_yscale('log')
    ax.set_ylim(1e5, 1.)
    ax.set_title('Temperature')
    ax.grid()
    ax.set_xlabel('K')
    ax.set_yticklabels([])


monitor = PlotFunctionMonitor(plot_function)
rad_sw = RRTMGShortwave()
rad_lw = RRTMGLongwave()
time_stepper = AdamsBashforth([rad_sw, rad_lw])
timestep = timedelta(hours=1)

mid_levels = {'label': 'mid_level', 'values': np.arange(60), 'units': ''}

int_levels = {'label': 'interface_level', 'values': np.arange(61), 'units': ''}
state = get_default_state([rad_sw, rad_lw],
                          mid_levels=mid_levels,
                          interface_levels=int_levels)

tp_profiles = np.load('thermodynamic_profiles.npz')
mol_profiles = np.load('molecule_profiles.npz')

state['air_pressure'].values[0, 0, :] = tp_profiles['air_pressure']
state['air_temperature'].values[0, 0, :] = tp_profiles['air_temperature']
예제 #18
0
 def get_component_instance(self):
     radiation = RRTMGLongwave()
     return GFSDynamicalCore([radiation], moist=True)
예제 #19
0
 def get_component_instance(self):
     return RRTMGLongwave(mcica=True)
예제 #20
0
 def get_component_instance(self):
     return RRTMGLongwave(calculate_interface_temperature=False)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
from climt import RRTMGShortwave, RRTMGLongwave, get_default_state
from sympl import get_constant

prop_cycle = rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']

rad_sw = RRTMGShortwave(mcica=True)
state_sw = get_default_state([rad_sw])

rad_lw = RRTMGLongwave(mcica=True)
state_lw = get_default_state([rad_lw])

p = state_lw['air_pressure'][:]
p_interface = state_lw['air_pressure_on_interface_levels'][:]
T = state_lw['air_temperature'][:]
R = get_constant('gas_constant_of_dry_air', 'J kg^-1 K^-1')
g = get_constant('gravitational_acceleration', 'm s^-2')
density = p / (R * T)
dz = -np.diff(p_interface, axis=0) / (density * g)  # [m]
z = np.cumsum(dz) * 10**-3  # [km]
ice_density = 0.5 * 10**-3  # [kg m^-3]
cloud_base = 10  # [km]
cloud_top = 15  # [km]
cloud_loc = np.where((z > cloud_base) & (z < cloud_top))
i = 0
for area_fraction in np.arange(0, 1.1, 0.25):
    mass_ice_array = area_fraction * ice_density * dz
    for state in state_sw, state_lw: