Commit 7220f33d authored by Carl Schreck's avatar Carl Schreck

Merge branch 'master' of k3.cicsnc.org:carl/nClimGrid

parents a4550cf8 15214fd7
......@@ -8,6 +8,7 @@ __license__ = "BSD-3.0"
import xarray as xr
import pandas as pd
import numpy as np
import pandas as pd
import os
import cjs # '~carl/lib/python'
import argparse
......@@ -17,7 +18,7 @@ cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top
parser = argparse.ArgumentParser()
parser.add_argument('--var_name', default='tmin')
parser.add_argument('--year', default=2019)
parser.add_argument('--year', default=2018)
parser.add_argument('--month', default=9)
args = parser.parse_args()
var_name = args.var_name
......@@ -37,39 +38,53 @@ var_name_to_units = {
'prcp': 'mm',
}
last_day = calendar.monthrange(year, month)[1]
# Create time array
for day in np.arange(1, last_day+1):
file_name = f'PRISM_{var_name}_{year}{month:02}{day:02}'
in_path = f'{os.environ["DATA_DIR"]}/prism/{file_name}.txt'
out_path = f'{os.environ["DATA_DIR"]}/prism/netcdf/{file_name}.nc'
in_data = pd.read_csv(in_path, sep=' ', header=None, skiprows=6,
na_values=-9999, skipinitialspace=True)
in_data = in_data[::-1]
xllcorner = -125.020833333333
yllcorner = 24.062499999979
cellsize = 0.041666666667
ncols = 1405
nrows = 621
xllcorner = -125.020833333333
yllcorner = 24.062499999979
cellsize = 0.041666666667
ncols = 1405
nrows = 621
lon = xr.DataArray((xllcorner + (np.arange(ncols) * cellsize)),
dims='lon', name='lon',
attrs={'long_name': 'Longitude',
'units': 'degrees_north'})
lon.assign_coords(lon=lon)
lon = xr.DataArray((xllcorner + (np.arange(ncols) * cellsize)),
dims='lon', name='lon',
attrs={'long_name': 'Longitude', 'units': 'degrees_north'})
lon.assign_coords({'lon': lon})
lat = xr.DataArray((yllcorner + (np.arange(nrows) * cellsize)),
dims='lat', name='lat',
attrs={'long_name': 'Latitude',
'units': 'degrees_east'})
lat.assign_coords(lat=lat)
lat = xr.DataArray((yllcorner + (np.arange(nrows) * cellsize)),
dims='lat', name='lat',
attrs={'long_name': 'Latitude', 'units': 'degrees_east'})
lat.assign_coords({'lat': lat})
last_day = calendar.monthrange(year, month)[1]
time = xr.DataArray(pd.date_range(f'{year}-{month:02}-01',
f'{year}-{month:02}-{last_day:02}'),
dims='time', name='time',
attrs={'long_name': 'time'})
time.assign_coords(time=time)
data = xr.DataArray(in_data, coords=[lat, lon], name=var_name,
out_data = xr.DataArray(np.full((len(time),len(lat), len(lon)), np.nan),
coords=[time, lat, lon],
name=var_name,
dims=['time', 'lat', 'lon'],
attrs={'long_name': var_name_to_long_name[var_name],
'units': var_name_to_units[var_name]})
data.to_netcdf(out_path)
out_path = f'{os.environ["DATA_DIR"]}/prism/netcdf/' \
f'{var_name}-{year}{month:02}.nc'
for curr_time in time.values:
ts = pd.to_datetime(str(curr_time))
file_name = f'PRISM_{var_name}_{ts.strftime("%Y%m%d")}'
cjs.tstamp(file_name)
in_path = f'{os.environ["DATA_DIR"]}/prism/jared/{file_name}.txt'
in_data = pd.read_csv(in_path, sep=' ', header=None, skiprows=6,
na_values=-9999, skipinitialspace=True)
in_data = in_data[::-1]
out_data.loc[dict(time=curr_time)] = in_data
cjs.tstamp('Writing')
out_data.to_netcdf(out_path)
cjs.tstamp('Thank you, come again.')
......
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