<jupyter_start><jupyter_text>Calculate Basin Total Water Storage Anomalies<jupyter_code>BASIN_SHP= BASIN['geo_data']['basin']# path to basin shapefile
basin_grace_folder= os.path.join(BASIN['Dir'],'grace')
if not os.path.exists(basin_grace_folder):
    os.makedirs(basin_grace_folder)
OUT_CSV= os.path.join(basin_grace_folder,'ts_GRACE.csv')# path to basin GRACE time-series csv file
MASCON_DATA_FOLDER = BASIN['global_data']['grace']# path to GRACE folder
end_month=BASIN['end_month']
                            
success=calc_dS_basin(BASIN_SHP,MASCON_DATA_FOLDER,OUT_CSV)
if success:
    BASIN['input_ts']['dS']=[OUT_CSV,'mm of Equivalent Water Height','Total Water Storage Anomalies']
    pickle_out(BASIN)
OUT_CSV<jupyter_output><empty_output><jupyter_text>Estimate yearly Total Water Storage Change<jupyter_code># Read GRACE basin pseudo-monthly estimates
grace_basin_csv=OUT_CSV
ts_grace=pd.read_csv(grace_basin_csv,sep=',',index_col=0)
ts_day=pd.DataFrame(index=pd.date_range(start='2003-01-06',end='2016-07-14',freq='D'))
# Interpolate GRACE estimates to daily time-step
ts_grace_daily=pd.merge(ts_day,ts_grace, left_index=True,right_index=True, how='outer')
ts_grace_interpolate_daily=ts_grace_daily.interpolate()
# Estimate monthly TWS change by Central difference
ts_grace_monthly_firstday=ts_grace_interpolate_daily.resample('MS').first()
ts_dS_monthly=ts_grace_monthly_firstday.diff(2).shift(-1)/2
# Estimate yearly TWS change
ts_dS_yearly=ts_dS_monthly.resample('A-{0}'.format(end_month)).sum()
ts_dS_yearly.columns=['TWS Change [mm/year]']

OUT_CSV=os.path.join(basin_grace_folder,'ts_GRACE_yearly.csv')
ts_dS_yearly.to_csv(OUT_CSV,sep=';')
BASIN['input_ts']['dS_yearly']=[OUT_CSV,'mm of Equivalent Water Height','Yearly Total Water Storage Change']
pickle_out(BASIN)
ts_grace.plot(style='.')
ts_grace_interpolate_daily.plot(style='.-')
ts_grace_monthly_firstday.plot(style='.-')
ts_dS_monthly.plot.bar()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13435897435897437, 'fraction_numerical': 0.010769230769230769, 'mean_word_length': 9.056701030927835, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '617336', 'license': 'Apache-2.0', 'n_tokens_mistral': 810, 'n_tokens_neox': 772, 'n_words': 102, 'path': 'WAPORWA/notebooks/2_GRACE_dS.ipynb', 'repo_name': 'Neo916/deafrica-sandbox-notebooks', 'size': '1950'}