Commit 915d5091 authored by Mike Bedington's avatar Mike Bedington

Update river make to cope with nemo rivers

parent fe0f1966
......@@ -17,14 +17,14 @@ wrf_nc_file_str = sys.argv[6]
# Load the river model
with open('river_model.pk1','rb') as f:
river_dict = pk.load(f)
river_dict = pk.load(f)
river_list = []
for this_obj in river_dict.values():
this_obj.mouth_lon = float(this_obj.mouth_lon)
this_obj.mouth_lat = float(this_obj.mouth_lat)
this_obj.salinity = 0
river_list.append(this_obj)
this_obj.mouth_lon = float(this_obj.mouth_lon)
this_obj.mouth_lat = float(this_obj.mouth_lat)
this_obj.salinity = 0
river_list.append(this_obj)
# Add the new WRF data
forecast_nc = nc.Dataset(wrf_nc_file_str, 'r')
......@@ -32,19 +32,26 @@ forecast_nc = nc.Dataset(wrf_nc_file_str, 'r')
wrf_vars = ['RAINNC', 'T2', 'Times']
forecast_data = {}
for this_var in wrf_vars:
forecast_data[this_var] = forecast_nc.variables[this_var][:]
forecast_data[this_var] = forecast_nc.variables[this_var][:]
date_str_raw = [b''.join(this_date_raw) for this_date_raw in forecast_data['Times']]
forecast_data['times'] = np.asarray([dt.datetime.strptime(this_date_str.decode('utf-8'), '%Y-%m-%d_%H:%M:%S') for this_date_str in date_str_raw])
for this_river in river_list:
this_rain = np.sum(np.sum(forecast_data['RAINNC']*this_river.wrf_catchment_factors, axis=2), axis=1)
this_river.addToSeries('catchment_precipitation', this_rain, forecast_data['times'])
if hasattr(this_river, 'wrf_catchment_factors'):
this_rain = np.sum(np.sum(forecast_data['RAINNC']*this_river.wrf_catchment_factors, axis=2), axis=1)
this_river.addToSeries('catchment_precipitation', this_rain, forecast_data['times'])
this_temp = np.zeros(len(forecast_data['times']))
for i in range(0, len(forecast_data['times'])):
this_temp[i] = np.average(forecast_data['T2'][i,:,:], weights=this_river.wrf_catchment_factors)
this_river.addToSeries('catchment_temp', this_temp, forecast_data['times'], override=True)
this_temp = np.zeros(len(forecast_data['times']))
for i in range(0, len(forecast_data['times'])):
this_temp[i] = np.average(forecast_data['T2'][i,:,:], weights=this_river.wrf_catchment_factors)
this_river.addToSeries('catchment_temp', this_temp, forecast_data['times'], override=True)
for this_river in river_list:
try:
this_river._expandDateSeries(start_date, end_date)
except:
pass
# Get and write out the forecast predictions
grid = common_dir + '/' + grid_name + '_grd.dat'
......
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