Beispiel #1
0
def test_wind_dir_from_components(path_uas_cnrmcm5, path_vas_cnrmcm5, direct_uas_cnrmcm5, direct_vas_cnrmcm5):
    with nc.Dataset(path_uas_cnrmcm5, 'r') as uas_reader, \
         nc.Dataset(path_vas_cnrmcm5, 'r') as vas_reader:
        wind_dir = NCdata.wind_dir_from_components(uas_reader, vas_reader)
    wind_dir_truth = tools.degfromnorth(np.asarray(direct_uas_cnrmcm5.variables['uas'][:]),
                                        np.asarray(direct_vas_cnrmcm5.variables['vas'][:]))
    assert wind_dir.var_name == 'wdir'
    assert wind_dir.var_units == 'degrees clockwise from north'
    assert_almost_equal(wind_dir.variable, wind_dir_truth)
    assert wind_dir.model_id == 'CNRM-CM5'
    assert wind_dir.globalattrs['frequency'] == 'day'
    assert wind_dir.globalattrs['parent_experiment_rip'] == 'r1i1p1'
    assert wind_dir.globalattrs['creation_date_uas'] == '2011-05-10T10:54:55Z'
Beispiel #2
0
def test_wind_dir_from_comp_model_misaligned_error(path_uas_cmcccm, path_vas_cnrmcm5):
    with nc.Dataset(path_uas_cmcccm, 'r') as uas_reader, \
         nc.Dataset(path_vas_cnrmcm5, 'r') as vas_reader:
        with pytest.raises(TypeError):
            NCdata.wind_dir_from_components(uas_reader, vas_reader)
Beispiel #3
0
def test_wind_dir_from_comp_coord_misaligned_error(path_uas_cnrmcm5, path_vas_cnrmcm5_modified_lats):
    with nc.Dataset(path_uas_cnrmcm5, 'r') as uas_reader, \
         nc.Dataset(path_vas_cnrmcm5_modified_lats, 'r') as vas_reader:
        with pytest.raises(TypeError):
            NCdata.wind_dir_from_components(uas_reader, vas_reader)
Beispiel #4
0
def test_wind_dir_from_comp_vas_type_error(path_uas_cmcccm, path_pr_access10):
    with nc.Dataset(path_uas_cmcccm, 'r') as uas_reader, \
         nc.Dataset(path_pr_access10, 'r') as vas_reader:
        with pytest.raises(TypeError):
            NCdata.wind_dir_from_components(uas_reader, vas_reader)
Beispiel #5
0
def wdir_ncdata_cnrmcm5(path_uas_cnrmcm5, path_vas_cnrmcm5):
    with nc.Dataset(path_uas_cnrmcm5, 'r') as uas_reader, \
         nc.Dataset(path_vas_cnrmcm5, 'r') as vas_reader:
        return NCdata.wind_dir_from_components(uas_reader, vas_reader)
Beispiel #6
0
def wdir_ncdata_access13(path_uas_access13, path_vas_access13):
    with nc.Dataset(path_uas_access13, 'r') as uas_reader, \
         nc.Dataset(path_vas_access13, 'r') as vas_reader:
        return NCdata.wind_dir_from_components(uas_reader, vas_reader)
Beispiel #7
0
uas_test_file_lin = os.path.join(
    folder, r"ACCESS1-3/uas_day_ACCESS1-3_rcp85_r1i1p1_1year_spatial_clip.nc")
vas_test_file_lin = os.path.join(
    folder, r"ACCESS1-3/vas_day_ACCESS1-3_rcp85_r1i1p1_1year_spatial_clip.nc")

# 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'][:])