-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerra.py
More file actions
90 lines (59 loc) · 3.07 KB
/
merra.py
File metadata and controls
90 lines (59 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import datetime
import numpy as np
from pydap.client import open_url
class Merra():
def __init__(self, day, month, year, lat, lon, ndays):
self.day = day
self.month = month
self.year = year
self.lat = lat
self.lon = lon
self.ndays = ndays
self.datetime_date = datetime.date(self.year, self.month, self.day)
path = self.construct_path('http://goldsmr2.sci.gsfc.nasa.gov:80/opendap/MERRA/MAT1NXFLX.5.2.0', 'MERRA300.prod.assim.tavg1_2d_flx_Nx.', 0)
dataset = open_url(path)
self.native_lat = dataset['YDim'][:]
self.native_lon = dataset['XDim'][:]
self.lat_idx_native = np.where(np.min(np.abs(self.native_lat - lat)) == np.abs(self.native_lat - lat))[0][0]
self.lon_idx_native = np.where(np.min(np.abs(self.native_lon - lon)) == np.abs(self.native_lon - lon))[0][0]
self.lat_actual = self.native_lat[self.lat_idx_native]
self.lon_actual = self.native_lon[self.lon_idx_native]
return
def construct_path(self, dataroot, filename, delta_day):
date = self.datetime_date + datetime.timedelta(days=delta_day)
date = str(date.isoformat())
day = date[8:10]
month = date[5:7]
year = date[:4]
full_path = dataroot + '/' + str(year)+ '/'
full_path += str(month) + '/'
full_path += filename + year + month + day + '.hdf'
return full_path
def surface_fluxes(self):
#Get the sensible and latent heat fluxes
lhf = np.array([], dtype=np.double)
evap = np.array([], dtype=np.double)
shf = np.array([], dtype=np.double)
qlml = np.array([], dtype=np.double)
tlml = np.array([], dtype=np.double)
ulml = np.array([], dtype=np.double)
vlml = np.array([], dtype=np.double)
precip = np.array([], dtype=np.double)
time = np.array([], dtype=np.double)
for i in range(self.ndays):
path = self.construct_path('http://goldsmr2.sci.gsfc.nasa.gov:80/opendap/MERRA/MAT1NXFLX.5.2.0',
'MERRA300.prod.assim.tavg1_2d_flx_Nx.', i)
dataset = open_url(path)
#lhf = np.append(lhf, dataset['EFLUX'][:,self.lat_idx_native, self.lon_idx_native])
#shf = np.append(shf, dataset['HFLUX'][:,self.lat_idx_native, self.lon_idx_native])
#evap = np.append(evap, dataset['EVAP'][:,self.lat_idx_native, self.lon_idx_native])
#ulml = np.append(ulml, dataset['ULML'][:, self.lat_idx_native, self.lon_idx_native])
#vlml = np.append(vlml, dataset['VLML'][:, self.lat_idx_native, self.lon_idx_native])
#qlml = np.append(qlml, dataset['QLML'][:, self.lat_idx_native, self.lon_idx_native])
#tlml = np.append(tlml, dataset['TLML'][:, self.lat_idx_native, self.lon_idx_native])
#precip = np.append(precip, dataset['PRECTOT'][:, self.lat_idx_native, self.lon_idx_native])
#time = np.append(time, dataset['TIME'][:])
#import pylab as plt
#plt.plot(precip)
#plt.show()
return