Aim: convert spatially-distributed WFDEI forcing data to averaged lumped timeseries of Temperature and Precipitation


In [41]:
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
%matplotlib inline

Nadym


In [42]:
#read basin shematization file
nadym_coord = pd.read_csv('../../Schemes/drt_05_nadym.csv', usecols=[0, 1])
nadym_coord.columns = ['lon','lat']
#calculate weights of each cell for further weighted averaging
nadym_coord['weights'] = (np.cos((nadym_coord['lat'] + 0.25)*np.pi/180) + np.cos((nadym_coord['lat'] - 0.25)*np.pi/180))
nadym_coord['weights'] = nadym_coord['weights']/np.sum(nadym_coord['weights'])

In [43]:
#read WFDEI forcing data
nadym_forc = pd.read_csv('../../Meteo_forcing_WFDEI/wfdei_for_nadym.csv', index_col=0, parse_dates=True)
#cut necessary variables (Rainf, Snowf, Tair)
nadym_rain = nadym_forc[['Rainf_'+str(point) for point in nadym_coord.index]]
nadym_snow = nadym_forc[['Snowf_'+str(point) for point in nadym_coord.index]]
nadym_temp = nadym_forc[['Tair_'+str(point) for point in nadym_coord.index]]

In [45]:
#convert precipitation (average rate mm/sec for 24 hours) to (sum of mm for whole day) 
#just multiply all values by 60sec*60min*24h
nadym_rain = nadym_rain*(60*60*24)
nadym_snow = nadym_snow*(60*60*24)
#convert temperature from Kelvins to Celsius
nadym_temp = nadym_temp-273.15
#summarize rain and snow to one precipitation parameter
nadym_prec = nadym_rain.add(nadym_snow.values)

In [46]:
#weighted averaging (sum of weight_i*value_i)
nadym_prec_avrg = nadym_prec.mul(nadym_coord['weights'].values, axis=1).sum(axis=1)
nadym_temp_avrg = nadym_temp.mul(nadym_coord['weights'].values, axis=1).sum(axis=1)

In [48]:
#wrap up results to .csv file
pd.DataFrame({'Temp': nadym_temp_avrg, 'Prec': nadym_prec_avrg}, index=nadym_temp_avrg.index).to_csv('nadym_avrg.csv')

In [49]:
%reset


Once deleted, variables cannot be recovered. Proceed (y/[n])? y

Pur


In [51]:
import numpy as np
import pandas as pd

#read basin shematization file
pur_coord = pd.read_csv('../../Schemes/drt_05_pur.csv', usecols=[0, 1])
pur_coord.columns = ['lon','lat']
#calculate weights of each cell for further weighted averaging
pur_coord['weights'] = (np.cos((pur_coord['lat'] + 0.25)*np.pi/180) + np.cos((pur_coord['lat'] - 0.25)*np.pi/180))
pur_coord['weights'] = pur_coord['weights']/np.sum(pur_coord['weights'])

#read WFDEI forcing data
pur_forc = pd.read_csv('../../Meteo_forcing_WFDEI/wfdei_for_pur.csv', index_col=0, parse_dates=True)
#cut necessary variables (Rainf, Snowf, Tair)
pur_rain = pur_forc[['Rainf_'+str(point) for point in pur_coord.index]]
pur_snow = pur_forc[['Snowf_'+str(point) for point in pur_coord.index]]
pur_temp = pur_forc[['Tair_'+str(point) for point in pur_coord.index]]

#convert precipitation (average rate mm/sec for 24 hours) to (sum of mm for whole day) 
#just multiply all values by 60sec*60min*24h
pur_rain = pur_rain*(60*60*24)
pur_snow = pur_snow*(60*60*24)
#convert temperature from Kelvins to Celsius
pur_temp = pur_temp-273.15
#summarize rain and snow to one precipitation parameter
pur_prec = pur_rain.add(pur_snow.values)

#weighted averaging (sum of weight_i*value_i)
pur_prec_avrg = pur_prec.mul(pur_coord['weights'].values, axis=1).sum(axis=1)
pur_temp_avrg = pur_temp.mul(pur_coord['weights'].values, axis=1).sum(axis=1)

#wrap up results to .csv file
pd.DataFrame({'Temp': pur_temp_avrg, 'Prec': pur_prec_avrg}, index=pur_temp_avrg.index).to_csv('pur_avrg.csv')

In [59]:
%reset


Once deleted, variables cannot be recovered. Proceed (y/[n])? y

Taz


In [60]:
import numpy as np
import pandas as pd

#read basin shematization file
taz_coord = pd.read_csv('../../Schemes/drt_05_taz.csv', usecols=[0, 1])
taz_coord.columns = ['lon','lat']
#calculate weights of each cell for further weighted averaging
taz_coord['weights'] = (np.cos((taz_coord['lat'] + 0.25)*np.pi/180) + np.cos((taz_coord['lat'] - 0.25)*np.pi/180))
taz_coord['weights'] = taz_coord['weights']/np.sum(taz_coord['weights'])

#read WFDEI forcing data
taz_forc = pd.read_csv('../../Meteo_forcing_WFDEI/wfdei_for_taz.csv', index_col=0, parse_dates=True)
#cut necessary variables (Rainf, Snowf, Tair)
taz_rain = taz_forc[['Rainf_'+str(point) for point in taz_coord.index]]
taz_snow = taz_forc[['Snowf_'+str(point) for point in taz_coord.index]]
taz_temp = taz_forc[['Tair_'+str(point) for point in taz_coord.index]]

#convert precipitation (average rate mm/sec for 24 hours) to (sum of mm for whole day) 
#just multiply all values by 60sec*60min*24h
taz_rain = taz_rain*(60*60*24)
taz_snow = taz_snow*(60*60*24)
#convert temperature from Kelvins to Celsius
taz_temp = taz_temp-273.15
#summarize rain and snow to one precipitation parameter
taz_prec = taz_rain.add(taz_snow.values)

#weighted averaging (sum of weight_i*value_i)
taz_prec_avrg = taz_prec.mul(taz_coord['weights'].values, axis=1).sum(axis=1)
taz_temp_avrg = taz_temp.mul(taz_coord['weights'].values, axis=1).sum(axis=1)

#wrap up results to .csv file
pd.DataFrame({'Temp': taz_temp_avrg, 'Prec': taz_prec_avrg}, index=taz_temp_avrg.index).to_csv('taz_avrg.csv')

In [ ]: