Exemple #1
0
def test_get_numpy_version_with_numpy_array_in_state():

    component = RRTMGShortwave()
    state = get_default_state([component])

    state['test_values'] = np.arange(100)

    raw_array = numpy_version_of(state)

    assert np.all(raw_array['test_values'] == np.arange(100))
    def test_rrtmg_logging(self, caplog):
        caplog.set_level(logging.INFO)
        RRTMGShortwave(mcica=True, cloud_overlap_method='clear_only')
        assert 'no clouds' in caplog.text
        caplog.clear()

        RRTMGShortwave(mcica=True, cloud_optical_properties='single_cloud_type')
        assert "must be 'direct_input' or " \
               "'liquid_and_ice_clouds'" in caplog.text
        caplog.clear()

        RRTMGShortwave(mcica=True,
                       cloud_optical_properties='liquid_and_ice_clouds',
                       cloud_ice_properties='ebert_curry_one')
        assert "not be set to 'ebert_curry_one'" in caplog.text
        caplog.clear()

        RRTMGShortwave(mcica=True,
                       cloud_optical_properties='liquid_and_ice_clouds',
                       cloud_liquid_water_properties='radius_independent_absorption')
        assert "must be set to 'radius_dependent_absorption'" in caplog.text
def test_3d_initialization_is_full_based_on_wildcard():
    grid_state = get_grid(nx=10, ny=10, nz=20)
    rrtmg_shortwave = RRTMGShortwave()
    instellation = Instellation()
    state = get_default_state([rrtmg_shortwave, instellation],
                              grid_state=grid_state)
    for quantity_name, properties in rrtmg_shortwave.input_properties.items():
        if '*' in properties['dims']:
            assert len(
                state[quantity_name].dims) == len(properties['dims']) + 1
        if tuple(properties['dims']) == ('*', ):
            assert set(state[quantity_name].dims) == {'lat', 'lon'}
        elif tuple(properties['dims']) == ('mid_levels', '*'):
            assert state[quantity_name].dims[0] == 'mid_levels'
            assert set(state[quantity_name].dims[1:]) == {'lat', 'lon'}
Exemple #4
0
 def get_component_instance(self, state_modification_func=lambda x: x):
     return RRTMGShortwave()
Exemple #5
0
    ax.set_ylim(1e5, 1.)
    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']
Exemple #6
0
 def get_component_instance(self):
     return RRTMGShortwave(mcica=True)
        net_flux.values.flatten(),
        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
def solarConstant(distance):
    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"]
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: