Commit ec005fec authored by Carl Schreck's avatar Carl Schreck

Working version of read_unscaled

parent 712f2886
......@@ -79,7 +79,18 @@ def draw_station_type(path, lat_column=1, lon_column=2, time_column=6,
return asc_data
def read_unscaled(path, lat_column=0, lon_column=1, data_column=4,):
def read_unscaled(path, var_name, lat_column=0, lon_column=1, data_column=4,):
var_name_to_long_name = {
'tmin': 'Minimum Temperature',
'tmax': 'Maximum Temperature',
'prcp': 'Precipitation',
}
var_name_to_units = {
'tmin': 'degree_Celsius',
'tmax': 'degree_Celsius',
'prcp': 'Millimeters',
}
with gzip.open(path, mode='rt') as f:
asc_data = pd.read_csv(path, sep=' ', header=None,
skipinitialspace=True)
......@@ -97,18 +108,22 @@ def read_unscaled(path, lat_column=0, lon_column=1, data_column=4,):
lon = lon.sortby(lon)
lon.assign_coords(lon=lon)
data2d = asc_data[data_column].values.reshape(len(lat), len(lon))
data = xr.DataArray(data2d,
retval = xr.DataArray(np.full((len(lat), len(lon)), np.nan),
coords=[lat, lon], name=var_name,
attrs={'long_name': var_name_to_long_name[var_name],
'units': var_name_to_units[var_name]})
return data
retval.loc[dict(lon=xr.DataArray(asc_data[lon_column]),
lat=xr.DataArray(asc_data[lat_column]))] = \
asc_data[data_column]
return retval
# path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/02temp-steps/' \
# f'TMAX19890203map.txt'
path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/02temp-steps/' \
f'TMAX_19890203_D6_A2.pnt.gz'
var_name = 'tmax'
bounds=np.arange(-30, 35, 5)
cmap = cm.get_cmap('bwr', lut=(len(bounds) + 1))
......@@ -117,4 +132,4 @@ norm = mpl.colors.BoundaryNorm(bounds, cmap.N, clip=False)
# station_plot = draw_station_type(path)
# plt.colorbar(station_plot)
# plt.show()
data = read_unscaled(path)
\ No newline at end of file
data = read_unscaled(path, var_name)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment