Пример #1
0
# Inspecting the netcdf object
###############################

# ESTABLISHING DATA LOCATION
# folder = r"C:\repos\wnpmonsoon\tests\data"
folder = '/home/rwegener/repos/wnpmonsoon/tests/data/'
# precip_test_file = folder + r"\ACCESS1-0\pr_day_ACCESS1-0_rcp85_r1i1p1_1year_spatial_clip.nc"
# uas_test_file = folder + r"\CMCC-CM\uas_day_CMCC-CM_rcp85_r1i1p1_1year_spatial_clip.nc"
# vas_test_file = folder + r"\CMCC-CM\vas_day_CMCC-CM_rcp85_r1i1p1_1year_spatial_clip.nc"
precip_test_file_lin = folder + r"/ACCESS1-0/pr_day_ACCESS1-0_rcp85_r1i1p1_1year_spatial_clip.nc"
uas_test_file_lin = folder + r"/CNRM-CM5/uas_day_CNRM-CM5_rcp85_r1i1p1_1year_spatial_clip.nc"
vas_test_file_lin = folder + r"/CNRM-CM5/vas_day_CNRM-CM5_rcp85_r1i1p1_1year_spatial_clip.nc"

# EXAMPLE WIND DIRECTION
save_at = '/home/rwegener/repos/wnpmonsoon/winddir-tst.nc'
wdir_obj = wind_direction(uas_test_file, vas_test_file, save_location=save_at)

print('model:', wdir_obj.model_id)
print('variable:', wdir_obj.var_name)
print('max and min of variable data:', wdir_obj.variable.max(),
      wdir_obj.variable.min())

# EXAMPLE PRECIPITATION RATE
with nc.Dataset(precip_test_file_lin, 'r') as dataset_reader:
    precip_obj = NCdata(dataset_reader)
precip_obj.pr_unit_conversion()

print('model:', precip_obj.model_id)
print('variable:', precip_obj.var_name)
print('variable units:', precip_obj.var_units)
Пример #2
0
import netCDF4 as nc
import os
from wnpmonsoon.netcdf import NetCDFWriter
from wnpmonsoon.ncdata import NCdata

model_precip = NCdata(file_, 'pr')
model_precip.pr_unit_conversion()
model_precip.write(output_filename)

print("processing data for file:", file_)
# set up output directory and filename
output_file = directory_saved_files + '/../../../pr_rate/' + os.path.basename(
    file_).replace("pr", "pr_rate")

# open up the file and extract data
dataset = nc.Dataset(file_, 'r+')
model_pr = dataset.variables['pr'][:]
lats = dataset.variables['lat']
lons = dataset.variables['lon']
time = dataset.variables['time']
# establish "before" test points
# I: make sure appropriate translation is applied to test points
z_len = model_pr.shape[0] - 1
x_len = model_pr.shape[1] - 1
y_len = model_pr.shape[2] - 1
test_point_1_before = model_pr[z_len, x_len, y_len]
test_point_2_before = model_pr[z_len // 2, x_len // 3, 0]
print('test point 1 value (before):', test_point_1_before, '\n',
      'test point 2 value(before)', test_point_2_before)
# multiply by the number of seconds in a month to get the rain rate in average mm/day;
# *** if you would like to change from the default cmip5 produced pr unit of mm/s to some other unit [ex. mm/h] \