示例#1
0
from wnpmonsoon.ncdata import NCdata
import numpy as np

uas = NCdata(file_, 'uas')
vas = NCdata(file_, 'uas')

wind_sp = np.sqrt(np.square(uas.variable) + np.square(vas.variable))

# TODO decide if this is a good idea / if there is a better way to do this
# Inheriting from another object?
variable = 'ws'
ws = NCdata('notrealfile', variable, create_new=True)
ws.var_name = variable
ws.model = uas.model_id
ws.var_units = uas.var_units
ws.variable = wind_sp
ws.lats = uas.lats
ws.lons = uas.lons
ws.time = uas.time
ws.calendar = uas.calendar
ws.t_units = uas.t_units

ws.write(outfile)
示例#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] \