## Validating rain along the trajectory.

Topics about the HYSPLIT trajectory model.
midhun
Posts: 8
Joined: April 11th, 2016, 9:37 pm
Registered HYSPLIT User: Yes

### Re: Validating rain along the trajectory.

Hi Barbara,
Thanks!
Now it is clear

yaqiang
Posts: 53
Joined: October 5th, 2015, 10:20 pm
Registered HYSPLIT User: Yes

### Re: Validating rain along the trajectory.

Please look at below sample script:

Code: Select all

#--------------------------------------------------------
# Author: Yaqiang Wang
# Date: 2016-5-6
# Purpose: Convert ARL data to netCDF data
# Note: Sample
#-----------------------------------------------------------

infn = 'D:/Temp/arl/gdas1.jul09.w5'    #Input ARL file
outfn = 'D:/Temp/arl/pr_gdas1.jul09.w5.nc'    #Output netCDF file

#Open ARL data file
rain = f['TPP6']
tnum = rain.dimlen(0)
ynum = rain.dimlen(2)
xnum = rain.dimlen(3)
lat = rain.dimvalue(2)
lon = rain.dimvalue(3)

#New netCDF file

yvar = ncfile.addvar('lat', 'float', [ydim])    #Latitude

xvar = ncfile.addvar('lon', 'float', [xdim])    #Longitude

tvar = ncfile.addvar('time', 'int', [tdim])    #Time

prvar = ncfile.addvar('PR', 'float', [tdim, ydim, xdim])

#Create netCDF file
ncfile.create()

#Write variable data
ncfile.write(xvar, lon)
ncfile.write(yvar, lat)
sst = datetime.datetime(1900,1,1)
for t in range(0, tnum):
st = f.gettime(t)
print st.strftime('%Y-%m-%d %H:00')
hours = (st - sst).total_seconds() // 3600
origin = [t]
ncfile.write(tvar, array([hours]), origin=origin)
print 'Variable: ' + prvar.name
data = f['TPP6'][t,:,:,:]
origin = [t, 0, 0]
shape = [1, ynum, xnum]
data = data.reshape(shape)
ncfile.write(prvar, data, origin=origin)

#Close netCDF file
ncfile.close()

print 'Finished!'

yaqiang
Posts: 53
Joined: October 5th, 2015, 10:20 pm
Registered HYSPLIT User: Yes

### Re: Validating rain along the trajectory.

I forgot to add attribute to precipitation variable in above script. See revised one:

Code: Select all

#--------------------------------------------------------
# Author: Yaqiang Wang
# Date: 2016-5-6
# Purpose: Convert ARL data to netCDF data
# Note: Sample
#-----------------------------------------------------------

infn = 'D:/Temp/arl/gdas1.jul09.w5'    #Input ARL file
outfn = 'D:/Temp/arl/pr_gdas1.jul09.w5.nc'    #Output netCDF file

#Open ARL data file
rain = f['TPP6']
tnum = rain.dimlen(0)
ynum = rain.dimlen(2)
xnum = rain.dimlen(3)
lat = rain.dimvalue(2)
lon = rain.dimvalue(3)

#New netCDF file

yvar = ncfile.addvar('lat', 'float', [ydim])    #Latitude

xvar = ncfile.addvar('lon', 'float', [xdim])    #Longitude

tvar = ncfile.addvar('time', 'int', [tdim])    #Time

prvar = ncfile.addvar('PR', 'float', [tdim, ydim, xdim])
prvar.addattr('long_name', 'Accumulated precipitation (6 h accumulation)')

#Create netCDF file
ncfile.create()

#Write variable data
ncfile.write(xvar, lon)
ncfile.write(yvar, lat)
sst = datetime.datetime(1900,1,1)
for t in range(0, tnum):
st = f.gettime(t)
print st.strftime('%Y-%m-%d %H:00')
hours = (st - sst).total_seconds() // 3600
origin = [t]
ncfile.write(tvar, array([hours]), origin=origin)
print 'Variable: ' + prvar.name
data = f['TPP6'][t,:,:,:]
origin = [t, 0, 0]
shape = [1, ynum, xnum]
data = data.reshape(shape)
ncfile.write(prvar, data, origin=origin)

#Close netCDF file
ncfile.close()

print 'Finished!'

midhun
Posts: 8
Joined: April 11th, 2016, 9:37 pm
Registered HYSPLIT User: Yes

### Re: Validating rain along the trajectory.

Dear Yaqiang,
Thank you for the help.
It is a great tool!

barbara.stunder
Posts: 415
Joined: November 9th, 2012, 4:23 pm
Registered HYSPLIT User: Yes

### Re: Validating rain along the trajectory.

The latitude and longitude of each gridpoint are not directly in the GDAS1 files. Instead the grid specification parameters are in the ASCII part of the index (INDX) record for each time period. The grid specs are in Table 1 at http://www.ready.noaa.gov/gdas1.php.
In linux 'head -c152 gda1.mar16.w1' gives the 1st 152 characters in the 1st record of the file.

The date/time are the first 8 characters of the record.

danny67
Posts: 1
Joined: July 11th, 2016, 7:50 pm
Registered HYSPLIT User: No

### Re: Validating rain along the trajectory.

midhun wrote:Dear Yaqiang,

Thank you!
Great! It worked!

Please see my script below. I have defined the lat/lon/time according to the description given at http://ready.arl.noaa.gov/gdas1.php. Is there any way to get the lat/lon/time values directly from the input file? That's why I wanted to see here for some details.

Code: Select all

rain=inf['TPP6'][:,:,:,:]

#New netCDF file
#create variables
lat = ncfile.addvar('lat', 'float', [y])    #Latitude

lon = ncfile.addvar('lon', 'float', [x])    #Longitude

pr = ncfile.addvar('PR', 'float', [t,y,x])    #
pr.addattr('long_name', 'Accumulated precipitation (6 h accumulation)')