Skip to content
Snippets Groups Projects
Commit 4d6e2f73 authored by Tom Rink's avatar Tom Rink
Browse files

snapshot

parent 4d6b9ea1
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ gfs_date_format = '%y%m%d' ...@@ -25,7 +25,7 @@ gfs_date_format = '%y%m%d'
h4_to_h5_path = home_dir + '/h4toh5convert' h4_to_h5_path = home_dir + '/h4toh5convert'
data_dir = '/data1/rink' data_dir = '/home/rink/data'
converted_file_dir = data_dir + '/gfs_h5' converted_file_dir = data_dir + '/gfs_h5'
CACHE_GFS = True CACHE_GFS = True
...@@ -549,6 +549,7 @@ def get_bounding_gfs_files(timestamp): ...@@ -549,6 +549,7 @@ def get_bounding_gfs_files(timestamp):
farr = np.array(filelist) farr = np.array(filelist)
farr = farr[sidxs] farr = farr[sidxs]
ftimes = tarr[sidxs] ftimes = tarr[sidxs]
idxs = np.arange(len(filelist))
above = ftimes >= timestamp above = ftimes >= timestamp
if not above.any(): if not above.any():
...@@ -559,16 +560,18 @@ def get_bounding_gfs_files(timestamp): ...@@ -559,16 +560,18 @@ def get_bounding_gfs_files(timestamp):
if not below.any(): if not below.any():
return None, None, None, None return None, None, None, None
tL = ftimes[below].max() tL = ftimes[below].max()
iL = idxs[below].max()
iL = np.searchsorted(ftimes, tL, 'left')
iR = iL + 1 iR = iL + 1
fList = farr.tolist() fList = farr.tolist()
if timestamp == ftimes[iL]:
return fList[iL], ftimes[iL], None, None
else:
return fList[iL], ftimes[iL], fList[iR], ftimes[iR] return fList[iL], ftimes[iL], fList[iR], ftimes[iR]
def get_profile(xr_dataset, fld_name, lons, lats, lon360=True): def get_profile(xr_dataset, fld_name, lons, lats, lon360=True, do_norm=False):
if lon360: if lon360:
lons = np.where(lons < 0, lons + 360, lons) # convert -180,180 to 0,360 lons = np.where(lons < 0, lons + 360, lons) # convert -180,180 to 0,360
...@@ -583,6 +586,9 @@ def get_profile(xr_dataset, fld_name, lons, lats, lon360=True): ...@@ -583,6 +586,9 @@ def get_profile(xr_dataset, fld_name, lons, lats, lon360=True):
dim1 = xr.DataArray(lats, dims='k') dim1 = xr.DataArray(lats, dims='k')
intrp_fld = fld.interp(fakeDim1=dim1, fakeDim2=dim2, fakeDim0=plevs, method='linear') intrp_fld = fld.interp(fakeDim1=dim1, fakeDim2=dim2, fakeDim0=plevs, method='linear')
intrp_fld = intrp_fld.values
if do_norm:
intrp_fld = normalize(intrp_fld, fld_name)
return intrp_fld return intrp_fld
......
...@@ -8,7 +8,7 @@ import xarray as xr ...@@ -8,7 +8,7 @@ import xarray as xr
import pickle import pickle
from deeplearning.amv_raob import get_bounding_gfs_files, convert_file, get_images, get_interpolated_profile, \ from deeplearning.amv_raob import get_bounding_gfs_files, convert_file, get_images, get_interpolated_profile, \
split_matchup, shuffle_dict, get_interpolated_scalar, get_num_samples split_matchup, shuffle_dict, get_interpolated_scalar, get_num_samples, get_time_tuple_utc, get_profile
LOG_DEVICE_PLACEMENT = False LOG_DEVICE_PLACEMENT = False
...@@ -273,22 +273,30 @@ class CloudHeightNN: ...@@ -273,22 +273,30 @@ class CloudHeightNN:
label.append(tup[2]) label.append(tup[2])
sfc.append(tup[3]) sfc.append(tup[3])
continue continue
print('not found in cache, processing key: ', key)
obs = self.matchup_dict.get(key) obs = self.matchup_dict.get(key)
if obs is None: if obs is None:
print('no entry for: ', key) print('no entry for: ', key)
timestamp = obs[0][0] timestamp = obs[0][0]
print('not found in cache, processing key: ', key, get_time_tuple_utc(timestamp)[0])
gfs_0, time_0, gfs_1, time_1 = get_bounding_gfs_files(timestamp) gfs_0, time_0, gfs_1, time_1 = get_bounding_gfs_files(timestamp)
if (gfs_0 is None) or (gfs_1 is None): if (gfs_0 is None) and (gfs_1 is None):
print('no GFS for: ', timestamp) print('no GFS for: ', get_time_tuple_utc(timestamp)[0])
continue continue
try:
gfs_0 = convert_file(gfs_0) gfs_0 = convert_file(gfs_0)
if gfs_1 is not None:
gfs_1 = convert_file(gfs_1) gfs_1 = convert_file(gfs_1)
except Exception as exc:
print(get_time_tuple_utc(timestamp)[0])
print(exc)
continue
ds_1 = None
try: try:
ds_0 = xr.open_dataset(gfs_0) ds_0 = xr.open_dataset(gfs_0)
if gfs_1 is not None:
ds_1 = xr.open_dataset(gfs_1) ds_1 = xr.open_dataset(gfs_1)
except Exception as exc: except Exception as exc:
print(exc) print(exc)
...@@ -334,20 +342,26 @@ class CloudHeightNN: ...@@ -334,20 +342,26 @@ class CloudHeightNN:
lons = lons[common_idxs] lons = lons[common_idxs]
lats = lats[common_idxs] lats = lats[common_idxs]
if ds_1 is not None:
ndb = get_interpolated_profile(ds_0, ds_1, time_0, time_1, 'temperature', timestamp, lons, lats, do_norm=True) ndb = get_interpolated_profile(ds_0, ds_1, time_0, time_1, 'temperature', timestamp, lons, lats, do_norm=True)
else:
ndb = get_profile(ds_0, 'temperature', lons, lats, do_norm=True)
if ndb is None: if ndb is None:
continue continue
if ds_1 is not None:
ndf = get_interpolated_profile(ds_0, ds_1, time_0, time_1, 'rh', timestamp, lons, lats, do_norm=False) ndf = get_interpolated_profile(ds_0, ds_1, time_0, time_1, 'rh', timestamp, lons, lats, do_norm=False)
else:
ndf = get_profile(ds_0, 'rh', lons, lats, do_norm=False)
if ndf is None: if ndf is None:
continue continue
ndf /= 100.0 ndf /= 100.0
ndb = np.stack((ndb, ndf), axis=2) ndb = np.stack((ndb, ndf), axis=2)
ndd = get_interpolated_scalar(ds_0, ds_1, time_0, time_1, 'MSL pressure', timestamp, lons, lats, do_norm=False) #ndd = get_interpolated_scalar(ds_0, ds_1, time_0, time_1, 'MSL pressure', timestamp, lons, lats, do_norm=False)
ndd /= 1000.0 #ndd /= 1000.0
nde = get_interpolated_scalar(ds_0, ds_1, time_0, time_1, 'surface temperature', timestamp, lons, lats, do_norm=True) #nde = get_interpolated_scalar(ds_0, ds_1, time_0, time_1, 'surface temperature', timestamp, lons, lats, do_norm=True)
# label/truth # label/truth
# Level of best fit (LBF) # Level of best fit (LBF)
...@@ -369,7 +383,8 @@ class CloudHeightNN: ...@@ -369,7 +383,8 @@ class CloudHeightNN:
images.append(nda) images.append(nda)
vprof.append(ndb) vprof.append(ndb)
label.append(ndc) label.append(ndc)
nds = np.stack([ndd, nde], axis=1) # nds = np.stack([ndd, nde], axis=1)
nds = np.zeros((len(lons), 2))
sfc.append(nds) sfc.append(nds)
if not CACHE_GFS: if not CACHE_GFS:
...@@ -379,6 +394,7 @@ class CloudHeightNN: ...@@ -379,6 +394,7 @@ class CloudHeightNN:
self.in_mem_data_cache[key] = (nda, ndb, ndc, nds) self.in_mem_data_cache[key] = (nda, ndb, ndc, nds)
ds_0.close() ds_0.close()
if ds_1 is not None:
ds_1.close() ds_1.close()
images = np.concatenate(images) images = np.concatenate(images)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment