Пример #1
0
def test_make_mask_mult_rect(data_for_reg_calcs):
    mask_bounds = (region_land_mask.mask_bounds[0], [0, 360, -20, -5])
    region = Region(name='mult_rect', mask_bounds=mask_bounds)
    result = region._make_mask(data_for_reg_calcs)
    expected_values = [[True, True],
                       [True, False],
                       [True, False],
                       [True, False]]
    expected = xr.DataArray(expected_values, dims=[LAT_STR, LON_STR],
                            coords={LAT_STR: data_for_reg_calcs[LAT_STR],
                                    LON_STR: data_for_reg_calcs[LON_STR]})
    xr.testing.assert_equal(result.transpose(), expected)
Пример #2
0
def test_make_mask_mult_rect(data_for_reg_calcs):
    mask_bounds = (region_land_mask.mask_bounds[0], [0, 360, -20, -5])
    region = Region(name='mult_rect', mask_bounds=mask_bounds)
    result = region._make_mask(data_for_reg_calcs)
    expected_values = [[True, True], [True, False], [True, False],
                       [True, False]]
    expected = xr.DataArray(expected_values,
                            dims=[LAT_STR, LON_STR],
                            coords={
                                LAT_STR: data_for_reg_calcs[LAT_STR],
                                LON_STR: data_for_reg_calcs[LON_STR]
                            })
    xr.testing.assert_equal(result.transpose(), expected)
Пример #3
0
def test_region_init_mult_rect():
    bounds_in = [[1, 2, 3, 4], (-12, -30, 2.3, 9)]
    region = Region(name='test', mask_bounds=bounds_in)
    assert isinstance(region.mask_bounds, tuple)
    assert len(region.mask_bounds) == 2
    for (w, e, s, n), bounds in zip(bounds_in, region.mask_bounds):
        assert isinstance(bounds, tuple)
        assert np.all(bounds == (Longitude(w), Longitude(e), s, n))
Пример #4
0
def test_region_init():
    region = Region(name='test',
                    description='region description',
                    west_bound=0.,
                    east_bound=5,
                    south_bound=0,
                    north_bound=90.,
                    do_land_mask=True)
    assert region.name == 'test'
    assert region.description == 'region description'
    assert isinstance(region.mask_bounds, tuple)
    assert len(region.mask_bounds) == 1
    assert isinstance(region.mask_bounds[0], BoundsRect)
    assert np.all(region.mask_bounds[0] == (Longitude(0.), Longitude(5), 0,
                                            90.))
    assert region.do_land_mask is True
Пример #5
0
    sfc_area = xr.DataArray(sfc_area, dims=[LAT_STR], coords=[lat])
    land_mask = xr.DataArray(land_mask, dims=[LAT_STR], coords=[lat])

    sfc_area, _ = xr.broadcast(sfc_area, lon)
    land_mask, _ = xr.broadcast(land_mask, lon)

    da = xr.DataArray([[2., 2.], [np.nan, 5.], [3., 3.], [4., 4.]],
                      coords=[lat, lon])
    da[SFC_AREA_STR] = sfc_area
    da[LAND_MASK_STR] = land_mask
    return da


region_no_land_mask = Region(name='test',
                             description='Test region with no land mask',
                             lat_bounds=(0., 90.),
                             lon_bounds=(0., 5.),
                             do_land_mask=False)

region_land_mask = Region(name='test',
                          description='Test region with no land mask',
                          lat_bounds=(0., 90.),
                          lon_bounds=(0., 5.),
                          do_land_mask=True)


@pytest.mark.parametrize('region', [region_no_land_mask, region_land_mask],
                         ids=['no-land-mask', 'land-mask'])
def test_mask_var(data_for_reg_calcs, region):
    # Test region masks first row and second column
    # of test data.  Note that first element of
Пример #6
0
    def_time=True,
    func=total_precip,
    variables=(precip_largescale, precip_convective),
)

precip_conv_frac = Var(
    name='precip_conv_frac',
    def_time=True,
    func=conv_precip_frac,
    variables=(precip_largescale, precip_convective),
)

globe = Region(name='globe',
               description='Entire globe',
               west_bound=0,
               east_bound=360,
               south_bound=-90,
               north_bound=90,
               do_land_mask=False)

tropics = Region(name='tropics',
                 description='Tropics, defined as 30S-30N',
                 west_bound=0,
                 east_bound=360,
                 south_bound=-30,
                 north_bound=30,
                 do_land_mask=False)

example_proj = Proj('example_proj',
                    direc_out='example-output',
                    tar_direc_out='example-tar-output',
Пример #7
0
def test_region_init_bad_bounds():
    with pytest.raises(ValueError):
        Region(mask_bounds=[(1, 2, 3)])
        Region(mask_bounds=[(1, 2, 3, 4), (1, 2, 3)])
Пример #8
0
    LON_STR: 'LONS',
    LAT_STR: 'LATS',
    LAND_MASK_STR: 'lm',
    SFC_AREA_STR: 'AREA'
}


@pytest.fixture()
def data_reg_alt_names(data_for_reg_calcs):
    return data_for_reg_calcs.rename(_alt_names)


region_no_land_mask = Region(name='test',
                             description='Test region with no land mask',
                             west_bound=0.,
                             east_bound=5,
                             south_bound=0,
                             north_bound=90.,
                             do_land_mask=False)

region_land_mask = Region(name='test',
                          description='Test region with land mask',
                          west_bound=0.,
                          east_bound=5,
                          south_bound=0,
                          north_bound=90.,
                          do_land_mask=True)

_expected_mask = [[False, False], [True, False], [True, False], [True, False]]

Пример #9
0
             variables=(convection_rain, condensation_rain))

ps = Var(name='ps',
         def_time=True,
         description=('surface pressure'),
         def_vert=False)

sphum = Var(name='sphum',
            def_time=True,
            description=('specific humidity'),
            def_vert=True)

globe = Region(name='globe',
               description='Entire globe',
               west_bound=0,
               east_bound=360,
               south_bound=-90,
               north_bound=90,
               do_land_mask=False)

sahel = Region(name='sahel',
               description='African Sahel',
               mask_bounds=[(0, 40, 10, 20), (342, 360, 10, 20)],
               do_land_mask=True)

bk = Var(name='bk',
         description=('hybrid coefficients'),
         def_time=False,
         def_vert=True,
         def_lon=False,
         def_lat=False)
Пример #10
0
    name='precip_total',
    def_time=True,
    func=total_precip,
    variables=(precip_largescale, precip_convective),
)

precip_conv_frac = Var(
    name='precip_conv_frac',
    def_time=True,
    func=conv_precip_frac,
    variables=(precip_largescale, precip_convective),
)

globe = Region(name='globe',
               description='Entire globe',
               lat_bounds=(-90, 90),
               lon_bounds=(0, 360),
               do_land_mask=False)

tropics = Region(name='tropics',
                 description='Tropics, defined as 30S-30N',
                 lat_bounds=(-30, 30),
                 lon_bounds=(0, 360),
                 do_land_mask=False)

example_proj = Proj('example_proj',
                    direc_out='example-output',
                    tar_direc_out='example-tar-output',
                    models=[example_model],
                    regions=(globe, tropics))
Пример #11
0
    def_time=True,
    description=('convection rain'),
)

precip = Var(name='total_precipitation',
             def_time=True,
             description=('total precipitation rate'),
             func=total_precipitation,
             variables=(convection_rain, condensation_rain))

ps = Var(name='ps',
         def_time=True,
         description=('surface pressure'),
         def_vert=False)

sphum = Var(name='sphum',
            def_time=True,
            description=('specific humidity'),
            def_vert=True)

globe = Region(name='globe',
               description='Entire globe',
               lat_bounds=(-90, 90),
               lon_bounds=(0, 360),
               do_land_mask=False)

sahel = Region(name='sahel',
               description='African Sahel',
               mask_bounds=[((10, 20), (0, 40)), ((10, 20), (342, 360))],
               do_land_mask=True)
Пример #12
0
base = GFDLDataLoader(
    data_direc=rootdir,
    data_dur=5,
    data_start_date=datetime(1980, 1, 1),
    data_end_date=datetime(1999, 12, 31),
)

example_run = Run(
    name='relative humidity examination',
    description='An examination of relative humidity 1980 => 2000',
    data_loader=base)

example_model = Model(name='example_model',
                      runs=[example_run],
                      grid_file_paths=(os.path.join(rootdir, 'atmos', 'ts',
                                                    'monthly',
                                                    'zg_A1.199501-199912.nc')))

example_proj = Proj('example_proj',
                    direc_out=output_dir,
                    models=[example_model])

hur = Var(name='hur', def_time=True, description='Relative humidity')

globe = Region(name='globe',
               description='Entire globe',
               west_bound=0,
               east_bound=360,
               south_bound=-90,
               north_bound=90,
               do_land_mask=False)