Пример #1
0
def test_criteria_blank_pr_full_wind(fake_pr_matrix, fake_wdir_matrix):
    criteria = criteria_generator(wd_min=165, wd_max=200)
    passing_pr = criteria['precip'](fake_pr_matrix)
    passing_wd = criteria['wind_dir'](fake_wdir_matrix)
    truth_pr = np.ones(fake_pr_matrix.shape)
    truth_wdir = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0],
                           [1, 0, 0, 0], [0, 0, 0, 0]])
    truth_combined = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0],
                               [1, 0, 0, 0], [0, 0, 0, 0]])
    assert_almost_equal(truth_pr, passing_pr)
    assert_almost_equal(truth_wdir, passing_wd)
    assert_almost_equal(truth_combined, (passing_pr & passing_wd))
Пример #2
0
def test_criteria_full_pr_max_wind(fake_pr_matrix, fake_wdir_matrix):
    criteria = criteria_generator(pr_min=2, pr_max=7, wd_max=90)
    passing_pr = criteria['precip'](fake_pr_matrix)
    passing_wd = criteria['wind_dir'](fake_wdir_matrix)
    truth_pr = np.array([[0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1],
                         [1, 1, 1, 0], [1, 1, 0, 0]])
    truth_wdir = np.array([[0, 1, 0, 1], [0, 0, 1, 1], [0, 0, 1, 0],
                           [0, 0, 0, 0], [0, 0, 0, 1]])
    truth_combined = np.array([[0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 1, 0],
                               [0, 0, 0, 0], [0, 0, 0, 0]])
    assert_almost_equal(truth_pr, passing_pr)
    assert_almost_equal(truth_wdir, passing_wd)
    assert_almost_equal(truth_combined, (passing_pr & passing_wd))
Пример #3
0
def test_criteria_max_pr_min_wind(fake_pr_matrix, fake_wdir_matrix):
    # TODO add testing for the criteria dic
    criteria = criteria_generator(pr_max=5, wd_min=270)
    passing_pr = criteria['precip'](fake_pr_matrix)
    passing_wd = criteria['wind_dir'](fake_wdir_matrix)
    truth_pr = np.array([[1, 1, 0, 1], [1, 1, 0, 1], [0, 0, 0, 1],
                         [0, 0, 1, 1], [0, 0, 1, 1]])
    truth_wdir = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1],
                           [0, 0, 1, 1], [1, 1, 0, 0]])
    truth_combined = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1],
                               [0, 0, 1, 1], [0, 0, 0, 0]])
    assert_almost_equal(truth_pr, passing_pr)
    assert_almost_equal(truth_wdir, passing_wd)
    assert_almost_equal(truth_combined, (passing_pr & passing_wd))
Пример #4
0
def test_monsoon_compute_nc_input(precip_rate_ncdata_access13,
                                  wdir_ncdata_access13,
                                  truth_monsoon_indx_access13):
    criteria = criteria_generator(pr_min=5, wd_min=180, wd_max=270)
    monsoon = MonsoonData.compute(precip_rate_ncdata_access13,
                                  wdir_ncdata_access13, criteria)
    assert_almost_equal(truth_monsoon_indx_access13, monsoon.variable)
    assert monsoon.var_name == 'monsoon'
    assert_almost_equal(monsoon.lats, precip_rate_ncdata_access13.lats)
    assert monsoon.time_units == wdir_ncdata_access13.time_units
    assert monsoon.globalattrs[
        'frequency'] == precip_rate_ncdata_access13.globalattrs['frequency']
    assert monsoon.globalattrs[
        'institute_id'] == wdir_ncdata_access13.globalattrs['institute_id']
    assert monsoon.globalattrs['monsoon_criteria'] == criteria['summary_dict']
Пример #5
0
def test_monsoon_compute_misaligned_models(precip_rate_ncdata_access13,
                                           wdir_ncdata_cnrmcm5):
    with pytest.raises(TypeError):
        MonsoonData.compute(
            precip_rate_ncdata_access13, wdir_ncdata_cnrmcm5,
            criteria_generator(pr_min=5, wd_min=180, wd_max=270))
Пример #6
0
def test_monsoon_compute_wdir_typeerror(precip_rate_ncdata_access13,
                                        path_uas_access13):
    with pytest.raises(TypeError):
        MonsoonData.compute(
            precip_rate_ncdata_access13, path_uas_access13,
            criteria_generator(pr_min=5, wd_min=180, wd_max=270))
Пример #7
0
# Generate precipitation rate
with nc.Dataset(precip_test_file_lin, 'r') as p_flux_reader:
    print(p_flux_reader.__class__)
    p_rate = NCdata.pr_rate_from_flux(p_flux_reader)
p_rate_path = os.path.join(folder, r"created/pr_from_flux_ACCESS1-3.nc")
# p_rate.write(p_rate_path)

# Generate wind direction
with nc.Dataset(uas_test_file_lin, 'r') as uas_reader, \
     nc.Dataset(vas_test_file_lin, 'r') as vas_reader:
    wdir = NCdata.wind_dir_from_components(uas_reader, vas_reader)
wdir_path = os.path.join(folder, r"created/wdir_ACCESS1-3.nc")
# wdir.write(wdir_path)

# Compute monsoon
criteria = criteria_generator(pr_min=5, wd_min=180, wd_max=270)

with nc.Dataset(p_rate_path, 'r') as pr_reader, \
     nc.Dataset(wdir_path, 'r') as wd_reader:
    output = MonsoonData.compute(pr_reader, wd_reader, criteria)

filepath = '/home/rwegener/repos/wnpmonsoon/tests/data/created/monsoon_index_access13_pr5plus_180270wd_nomask.nc'
# output.write(filepath)
src = nc.Dataset(filepath, 'r')
print(src.variables['monsoon'][:])

output.variable = output.variable * 5

from wnpmonsoon.netcdf import NetCDFWriter

writer = NetCDFWriter(filepath)