From 3857eb19035de0e418d1b8bff605b972953d538e Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Mon, 23 Dec 2024 12:42:33 +0100 Subject: [PATCH 1/2] cleaned up example scripts --- ...roming.py => WSdwarsstroming_predictie.py} | 6 +- .../analysis_prediction_comparesettings.py | 55 ------------- tests/examples/analysis_xfac.py | 69 ---------------- tests/examples/astrog_example.py | 21 +++-- .../compare_foremanschureman_freqs.py | 1 - .../compare_foremanschureman_prediction.py | 14 ++-- tests/examples/longtimeseries_analysis.py | 79 ------------------- ...MDDPTS.py => nodal_alltimes_prediction.py} | 0 tests/examples/numbering_FEWS_PG.py | 10 --- tests/examples/numbering_extremes.py | 25 +----- tests/examples/predictie_2019_19Ycomp4Ydia.py | 4 - tests/examples/spatialsummary.py | 6 +- 12 files changed, 19 insertions(+), 271 deletions(-) rename tests/examples/{predictie_2019_frommergedcomp_WSdwarsstroming.py => WSdwarsstroming_predictie.py} (88%) delete mode 100644 tests/examples/analysis_prediction_comparesettings.py delete mode 100644 tests/examples/analysis_xfac.py delete mode 100644 tests/examples/longtimeseries_analysis.py rename tests/examples/{predictie_2019_frommergedcomp_AWGPFMDDPTS.py => nodal_alltimes_prediction.py} (100%) diff --git a/tests/examples/predictie_2019_frommergedcomp_WSdwarsstroming.py b/tests/examples/WSdwarsstroming_predictie.py similarity index 88% rename from tests/examples/predictie_2019_frommergedcomp_WSdwarsstroming.py rename to tests/examples/WSdwarsstroming_predictie.py index e977d66a..7d47ca50 100644 --- a/tests/examples/predictie_2019_frommergedcomp_WSdwarsstroming.py +++ b/tests/examples/WSdwarsstroming_predictie.py @@ -35,7 +35,7 @@ ts_prediction_HANSWT = hatyan.prediction(comp=COMP_merged_HANSWT, times=times_pred) ts_prediction_TERNZN = hatyan.prediction(comp=COMP_merged_TERNZN, times=times_pred) - ts_prediction_diff = ts_prediction_TERNZN-ts_prediction_HANSWT # TODO: metadata is dropped + ts_prediction_diff = ts_prediction_TERNZN-ts_prediction_HANSWT # TODO: metadata is retained from TERNZN ts_prediction_diff['values'] = ts_prediction_diff['values'].round(2) #round to cm ts_prediction_diff_HWLW = hatyan.calc_HWLW(ts=ts_prediction_diff) @@ -46,19 +46,15 @@ list_matig.append(ts_prediction_diff_matig) list_sterk.append(ts_prediction_diff_sterk) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_diff) ax.plot(ts_prediction_diff.index, ts_prediction_diff['values'],'-',linewidth=0.7,markersize=1, label='verval') ax.plot(ts_prediction_diff_matig.index, ts_prediction_diff_matig['values'],'oy',markersize=5, label='matig (>%.2fm)'%(value_matig)) ax.plot(ts_prediction_diff_sterk.index, ts_prediction_diff_sterk['values'],'or',markersize=5, label='sterk (>%.2fm)'%(value_sterk)) ax.plot([ts_prediction_diff.index[0],ts_prediction_diff.index[-1]],[value_matig,value_matig],'-y') ax.plot([ts_prediction_diff.index[0],ts_prediction_diff.index[-1]],[value_sterk,value_sterk],'-r') - #ax1.set_ylim(-1.2,1.7) ax.legend(loc=1) ax.grid() ax.set_xlabel('Tijd') ax.set_ylabel('astro verval %d [m] (TERNZN-HANSWT)'%yr) - #hatyan.write_dia(ts=ts_ext_prediction_main, station=current_station, vertref='NAP', filename='prediction_HWLW_%s_%s_main.dia'%(times_step_pred, current_station)) - #hatyan.write_dia(ts=ts_ext_prediction_clean, station=current_station, vertref='NAP', filename='prediction_HWLW_%s_%s_agger345.dia'%(times_step_pred, current_station)) fig.tight_layout() fig.savefig('prediction_WSdwarsstroming') diff --git a/tests/examples/analysis_prediction_comparesettings.py b/tests/examples/analysis_prediction_comparesettings.py deleted file mode 100644 index 6a4be644..00000000 --- a/tests/examples/analysis_prediction_comparesettings.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Feb 5 09:53:03 2021 - -@author: veenstra - -analyse three years and predict for forth year, compare analysis/prediction settings and schureman/foreman -""" - -import os -import pandas as pd -import numpy as np -import hatyan - -#dir_testdata = 'P:\\1209447-kpp-hydraulicaprogrammatuur\\hatyan\\hatyan_data_acceptancetests' -dir_testdata = 'C:\\DATA\\hatyan_data_acceptancetests' - -selected_stations = ['HOEKVHLD']#,'VLISSGN','CUXHVN'] - -#file_slotgemiddelden = os.path.join(dir_testdata,'predictie2019','_slotgemiddelden_predictie2019.txt') -#stations_slotgem = pd.read_csv(file_slotgemiddelden, names=['slotgemiddelde'], comment='#', sep="\\s+") - -stats_list = [] - -for current_station in selected_stations: - const_list = hatyan.get_const_list_hatyan('year') - file_data_comp0_lastyear = os.path.join(dir_testdata,'predictie2019','%s_obs4.txt'%(current_station)) - file_data_comp0_raw = [os.path.join(dir_testdata,'predictie2019','%s_obs%i.txt'%(current_station, file_id)) for file_id in [1,2,3]] - file_data_comp0 = [x for x in file_data_comp0_raw if os.path.exists(x)] #slim filename list down to available files/years - - ts_measurements_group0_lastyear = hatyan.read_dia(filename=file_data_comp0_lastyear, station=current_station) - ts_measurements_group0 = hatyan.read_dia(filename=file_data_comp0, station=current_station) - #ts_measurements_group0 = hatyan.crop_timeseries(ts_measurements_group0, times_ext=[dt.datetime(2012,1,1),dt.datetime(2013,1,1)]) - - stats_row = pd.DataFrame(index=[current_station]) - - #prediction and comparison to measurements - for fu_alltimes in [True,False]: - for xfac in [True, False]: - for source in ['schureman','foreman']: - COMP_merged = hatyan.analysis(ts=ts_measurements_group0, const_list=const_list, analysis_perperiod='Y', fu_alltimes=fu_alltimes, xfac=xfac, source=source) - #print(COMP_merged) - ts_prediction = hatyan.prediction(comp=COMP_merged, times=ts_measurements_group0_lastyear.index) - overlapdiff = ts_prediction['values']-ts_measurements_group0_lastyear['values'] - rmse = np.sqrt(np.nanmean(overlapdiff ** 2)) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction, ts_validation=ts_measurements_group0) - #ax2.set_ylim(-0.3,0.3) - stats_row['fu_alltimes=%s_xfac=%s_%s'%(fu_alltimes,xfac,source)] = [rmse] - #print(stats_row) - stats_list.append(stats_row) - -stats = pd.concat(stats_list,axis=0) -statsT = stats.T -print('RMSE values [cm] for several settings and stations:') -print((statsT*100).round(3)) diff --git a/tests/examples/analysis_xfac.py b/tests/examples/analysis_xfac.py deleted file mode 100644 index c62c02e0..00000000 --- a/tests/examples/analysis_xfac.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Feb 5 09:53:03 2021 - -@author: veenstra -""" - -import os -import datetime as dt -import hatyan - -#dir_testdata = 'P:\\1209447-kpp-hydraulicaprogrammatuur\\hatyan\\hatyan_data_acceptancetests' -dir_testdata = 'C:\\DATA\\hatyan_data_acceptancetests' - -current_station = 'VLISSGN' - -#file_slotgemiddelden = os.path.join(dir_testdata,'predictie2019','_slotgemiddelden_predictie2019.txt') -#stations_slotgem = pd.read_csv(file_slotgemiddelden, names=['slotgemiddelde'], comment='#', sep="\\s+") - -for fu_alltimes in [True,False]: - const_list = hatyan.get_const_list_hatyan('springneap') - #file_data_comp0 = os.path.join(dir_testdata,'predictie2019','%s_pre.txt'%(current_station)) - file_data_comp0 = os.path.join(dir_testdata,'predictie2019','%s_obs4.txt'%(current_station)) - - file_data_compvali = os.path.join(dir_testdata,'predictie2019','%s_ana.txt'%(current_station)) - - times_pred = slice(dt.datetime(2019,1,1),dt.datetime(2020,1,1), "10min") - - file_data_predvali = os.path.join(dir_testdata,'predictie2019','%s_pre.txt'%(current_station)) - #file_data_predvaliHWLW = os.path.join(dir_testdata,'predictie2019','%s_ext.txt'%(current_station)) - - ts_measurements_group0 = hatyan.read_dia(filename=file_data_comp0, station=current_station) - ts_measurements_group0['values'] -=.1 - #ts_measurements_group0 = hatyan.crop_timeseries(ts_measurements_group0, times_ext=[dt.datetime(2012,1,1),dt.datetime(2012,2,1)]) - - COMP_merged_xfac0 = hatyan.analysis(ts=ts_measurements_group0, const_list=const_list, fu_alltimes=fu_alltimes, xfac=False) - COMP_merged_xfac1 = hatyan.analysis(ts=ts_measurements_group0, const_list=const_list, fu_alltimes=fu_alltimes, xfac=True) - print(COMP_merged_xfac0) - print(COMP_merged_xfac1) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_predCOMPyear, ts_validation=ts_measurements_group0) - - #print(COMP_merged['A'].max()) - #COMP_validation = hatyan.read_components(filename=file_data_compvali) - #fig, (ax1,ax2) = hatyan.plot_components(COMP_merged, comp_validation=COMP_validation) - - #prediction and validation - ts_prediction_xfac0_xfac0 = hatyan.prediction(comp=COMP_merged_xfac0, times=times_pred) - ts_prediction_xfac1_xfac1 = hatyan.prediction(comp=COMP_merged_xfac1, times=times_pred) - # deliberately set xfac to wrong settings to allow predictions to succeed - COMP_merged_xfac0.attrs["xfac"] = True - COMP_merged_xfac1.attrs["xfac"] = False - ts_prediction_xfac0_xfac1 = hatyan.prediction(comp=COMP_merged_xfac0, times=times_pred) - ts_prediction_xfac1_xfac0 = hatyan.prediction(comp=COMP_merged_xfac1, times=times_pred) - - #ts_validation = hatyan.read_dia(filename=file_data_predvali, station=current_station) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac0_xfac0, ts_validation=ts_prediction_xfac1_xfac1) - fig.savefig('fualltimes%d_anaxfac0_predxfac1.png'%(fu_alltimes)) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac1_xfac1, ts_validation=ts_prediction_xfac0_xfac0) - fig.savefig('fualltimes%d_anaxfac1_predxfac0.png'%(fu_alltimes)) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac0_xfac0, ts_validation=ts_prediction_xfac0_xfac1) - fig.savefig('fualltimes%d_anaxfac0_predxfacdiff.png'%(fu_alltimes)) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac1_xfac0, ts_validation=ts_prediction_xfac1_xfac1) - fig.savefig('fualltimes%d_anaxfac1_predxfacdiff.png'%(fu_alltimes)) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac0_xfac0, ts_validation=ts_prediction_xfac1_xfac0) - fig.savefig('fualltimes%d_anaxfacdiff_predxfac0.png'%(fu_alltimes)) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_xfac0_xfac1, ts_validation=ts_prediction_xfac1_xfac1) - fig.savefig('fualltimes%d_anaxfacdiff_predxfac1.png'%(fu_alltimes)) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction, ts_validation=ts_measurements_group0) - diff --git a/tests/examples/astrog_example.py b/tests/examples/astrog_example.py index 5239c9f4..b97845c8 100644 --- a/tests/examples/astrog_example.py +++ b/tests/examples/astrog_example.py @@ -14,7 +14,6 @@ """ import os -import numpy as np import datetime as dt import pandas as pd import matplotlib.pyplot as plt @@ -24,7 +23,6 @@ #dir_testdata = 'P:\\1209447-kpp-hydraulicaprogrammatuur\\hatyan\\hatyan_data_acceptancetests' dir_testdata = 'C:\\DATA\\hatyan_data_acceptancetests' -# script settings compare2fortran = True #requires validation data start_date_utc = pd.Timestamp(2000, 1, 1, tz="UTC") @@ -38,39 +36,38 @@ dT_fortran = True #True is best comparison to fortran, False is more precise -pdtocsv_kwargs = dict(index=False, sep=',', date_format='%Y-%m-%d %H:%M:%S %Z', float_format='%9.5f', na_rep='--:-- ') +pdtocsv_kwargs = dict(index=False, sep=',', date_format='%Y-%m-%d %H:%M:%S %Z', float_format='%9.5f', na_rep='--:--') -#%% calculate astrog arrays -# lunar culmination times, parallax, declination +# calculate astrog lunar culmination times, parallax, declination culminations_python = hatyan.astrog_culminations(tFirst=start_date_utc, tLast=end_date_utc, dT_fortran=dT_fortran) culminations_python.to_csv('moon_culminations.csv',**pdtocsv_kwargs) -# lunar phases +# calculate astrog lunar phases phases_python = hatyan.astrog_phases(tFirst=start_date_met, tLast=end_date_met, dT_fortran=dT_fortran) phases_python.to_csv('moon_phases.csv',**pdtocsv_kwargs) -# moonrise and -set +# calculate astrog moonrise and -set moonriseset_python = hatyan.astrog_moonriseset(tFirst=start_date_met, tLast=end_date_met, dT_fortran=dT_fortran) moonriseset_python.to_csv('moon_riseset.csv',**pdtocsv_kwargs) moonriseset_python_perday = hatyan.convert2perday(moonriseset_python) moonriseset_python_perday.to_csv('moon_riseset_perday.csv',**pdtocsv_kwargs) -# sunrise and -set +# calculate astrog sunrise and -set sunriseset_python = hatyan.astrog_sunriseset(tFirst=start_date_met, tLast=end_date_met, dT_fortran=dT_fortran) sunriseset_python.to_csv('sun_riseset.csv',**pdtocsv_kwargs) sunriseset_python_perday = hatyan.convert2perday(sunriseset_python) sunriseset_python_perday.to_csv('sun_riseset_perday.csv',**pdtocsv_kwargs) -# lunar anomalies +# calculate astrog lunar anomalies anomalies_python = hatyan.astrog_anomalies(tFirst=start_date_met, tLast=end_date_met, dT_fortran=dT_fortran) anomalies_python.to_csv('anomalies.csv',**pdtocsv_kwargs) -# astronomical seasons +# calculate astrog astronomical seasons seasons_python = hatyan.astrog_seasons(tFirst=start_date_met, tLast=end_date_met, dT_fortran=dT_fortran) seasons_python.to_csv('seasons.csv',**pdtocsv_kwargs) if compare2fortran: - #%% load fortran results + # load fortran results pkl_culm = os.path.join(dir_testdata,'other','astrog20_2000_2011.pkl') pkl_phas = os.path.join(dir_testdata,'other','astrog30_phases_2000_2011.pkl') txt_phas = os.path.join(dir_testdata,'other','maanfasen.txt') @@ -108,7 +105,7 @@ seasons_fortran = pd.read_pickle(pkl_seas).set_index('datetime') seasons_fortran = seasons_fortran.loc[start_date_naive:end_date_naive] - #%% plot results (differences) + # plot results (differences) fig, (ax1,ax2,ax3) = hatyan.plot_astrog_diff(culminations_python, culminations_fortran, typeLab=['lower','upper'], timeBand=[-.18,.18]) fig.savefig('culmination_differences.png') diff --git a/tests/examples/compare_foremanschureman_freqs.py b/tests/examples/compare_foremanschureman_freqs.py index 36467f01..9151c02d 100644 --- a/tests/examples/compare_foremanschureman_freqs.py +++ b/tests/examples/compare_foremanschureman_freqs.py @@ -23,7 +23,6 @@ freqs_pd['const'] = freqs_pd.index freqs_pd['freq_absdiff'] = np.abs(freqs_pd.iloc[:,0]-freqs_pd.iloc[:,1]) freqs_pd['freq_bigdiff'] = freqs_pd['freq_absdiff']>10e-9 -#freqs_pd['freq_nan'] = (np.isnan(freqs_pd.iloc[:,0]-freqs_pd.iloc[:,1])) v0_pd = pd.concat([v0_pd_schu[0],v0_pd_for[0]],axis=1) v0_pd['v0_absdiff'] = (np.abs(v0_pd.iloc[:,0]-v0_pd.iloc[:,1])+0.5*np.pi)%np.pi-0.5*np.pi diff --git a/tests/examples/compare_foremanschureman_prediction.py b/tests/examples/compare_foremanschureman_prediction.py index 1ea55f8b..f108045a 100644 --- a/tests/examples/compare_foremanschureman_prediction.py +++ b/tests/examples/compare_foremanschureman_prediction.py @@ -18,20 +18,18 @@ for current_station in selected_stations: const_list = hatyan.get_const_list_hatyan('year') - file_data_comp0_lastyear = os.path.join(dir_testdata,'predictie2019','%s_obs1.txt'%(current_station)) + file_data_comp0 = os.path.join(dir_testdata,'predictie2019','%s_obs1.txt'%(current_station)) - ts_measurements_group0_lastyear = hatyan.read_dia(filename=file_data_comp0_lastyear, station=current_station) - #ts_measurements_group0 = hatyan.read_dia(filename=file_data_comp0, station=current_station) - #ts_measurements_group0 = hatyan.crop_timeseries(ts_measurements_group0, times_ext=[dt.datetime(2012,1,1),dt.datetime(2013,1,1)]) + ts_measurements_group0 = hatyan.read_dia(filename=file_data_comp0, station=current_station) stats_row = pd.DataFrame(index=[current_station]) for fu_alltimes in [True,False]: xfac = False #prediction and comparison to measurements - COMP_schu = hatyan.analysis(ts=ts_measurements_group0_lastyear, const_list=const_list, source='schureman', fu_alltimes=fu_alltimes, xfac=xfac) - ts_prediction_schu = hatyan.prediction(comp=COMP_schu, times=ts_measurements_group0_lastyear.index) - COMP_for = hatyan.analysis(ts=ts_measurements_group0_lastyear, const_list=const_list, source='foreman', fu_alltimes=fu_alltimes, xfac=xfac) - ts_prediction_for = hatyan.prediction(comp=COMP_for, times=ts_measurements_group0_lastyear.index) + COMP_schu = hatyan.analysis(ts=ts_measurements_group0, const_list=const_list, source='schureman', fu_alltimes=fu_alltimes, xfac=xfac) + ts_prediction_schu = hatyan.prediction(comp=COMP_schu, times=ts_measurements_group0.index) + COMP_for = hatyan.analysis(ts=ts_measurements_group0, const_list=const_list, source='foreman', fu_alltimes=fu_alltimes, xfac=xfac) + ts_prediction_for = hatyan.prediction(comp=COMP_for, times=ts_measurements_group0.index) fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_schu, ts_validation=ts_prediction_for) ax1.set_title(f'{current_station} fualltimes={fu_alltimes}') diff --git a/tests/examples/longtimeseries_analysis.py b/tests/examples/longtimeseries_analysis.py deleted file mode 100644 index e423f298..00000000 --- a/tests/examples/longtimeseries_analysis.py +++ /dev/null @@ -1,79 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Feb 19 14:33:50 2021 - -@author: veenstra -""" - - -import os -import datetime as dt -import pandas as pd -import numpy as np -import matplotlib.pyplot as plt -plt.close('all') -from netCDF4 import Dataset, num2date #TODO: move to xarray -import hatyan - -dir_data = r'p:\archivedprojects\11205259-004-dcsm-fm\waterlevel_data\all\ncFiles' -selected_stations = ['A2','A12','AUKFPFM','AWGPFM','D15','EURPFM','F3PFM','F16','K13APFM','K14PFM','L9PFM'] #all platforms I can find -selected_stations = ['A2','AUKFPFM','EURPFM','F3PFM','K13APFM'] #more than 17 years of data -selected_stations = ['EURPFM'] - -do_analysis = True #set to false to check only timeseries length and tstart/tstop -#dir_output = os.path.join(dir_base,case2,'cotidal_FESGTSM_divfM2') -#if not os.path.exists(dir_output): -# os.mkdir(dir_output) - -for current_station in selected_stations: - print('') - print(current_station) - file_nc = os.path.join(dir_data,f'{current_station}.nc') - - data_nc = Dataset(file_nc) - - data_nc_timevar = data_nc.variables['time'] - - # get time ids for start and stop time ([0,-1] would also work, but ok) - time_length = data_nc_timevar.shape[0] - retrieve_ids_time = [0,-1] #start and stoptime - retrieve_ids_time = list(np.unique(np.array(range(time_length))[retrieve_ids_time])) - - #get start/stop time and convert to pandas Series of datetime - data_nc_times = data_nc_timevar[retrieve_ids_time] - data_nc_datetimes = num2date(data_nc_times, units=data_nc_timevar.units, only_use_cftime_datetimes=False, only_use_python_datetimes=True) - data_nc_datetimes_pd = pd.Series(data_nc_datetimes,index=retrieve_ids_time).dt.round(freq='S') - time_length_yr = (data_nc_datetimes_pd.iloc[-1]-data_nc_datetimes_pd.iloc[0]).total_seconds()/3600/24/365.25 - print('ts length is %.2f years'%(time_length_yr)) - print(data_nc_datetimes_pd) - - var_wl = data_nc.variables['waterlevel'] - - if do_analysis: - #constituent list - #const_list = hatyan.get_const_list_hatyan('year') #this is not a good year when you analyse 35 year of data with 60 or 10 minute interval, but is useful after subsampling - const_list = hatyan.get_const_list_hatyan('day') # choose from: dict_keys(['all', 'year', 'halfyear', 'month', 'month_deepwater', 'springneap', 'day', 'tidalcycle']) - #const_list = ['M2','S2'] - - print('reading data from netcdf') - meas_times_raw = data_nc_timevar[:] - meas_times = num2date(meas_times_raw, units=data_nc_timevar.units, only_use_cftime_datetimes=False, only_use_python_datetimes=True) - meas_vals = var_wl[:] - print('finished reading netcdf') - ts_measurements = pd.DataFrame({'values': meas_vals},index=meas_times) - - #analysis - comp_frommeasurements = hatyan.analysis(ts=ts_measurements, const_list=const_list, nodalfactors=True, xfac=False, fu_alltimes=True) - print(comp_frommeasurements) - - fig,(ax1,ax2) = hatyan.plot_components(comp_frommeasurements) - #fig.savefig('components_%s_4Y.png'%(current_station)) - - #prediction and validation - times_pred = slice(dt.datetime(2008,1,1),dt.datetime(2010,1,1), "10min") - ts_prediction = hatyan.prediction(comp=comp_frommeasurements, times=times_pred) - fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction, ts_validation=ts_measurements) - ax1.set_ylim(-2.5,2.5) - ax2.set_ylim(-0.5,0.5) - #fig.savefig('prediction_%im_%s_measurements'%(times_step_pred, current_station)) - diff --git a/tests/examples/predictie_2019_frommergedcomp_AWGPFMDDPTS.py b/tests/examples/nodal_alltimes_prediction.py similarity index 100% rename from tests/examples/predictie_2019_frommergedcomp_AWGPFMDDPTS.py rename to tests/examples/nodal_alltimes_prediction.py diff --git a/tests/examples/numbering_FEWS_PG.py b/tests/examples/numbering_FEWS_PG.py index 81ced812..e3ccb66d 100644 --- a/tests/examples/numbering_FEWS_PG.py +++ b/tests/examples/numbering_FEWS_PG.py @@ -17,7 +17,6 @@ analyse_ts_bool = False -#station_name = data_pred.var_stations.loc[0,'node_id'] station_name = 'HOEKVHLD' file_meas = os.path.join(dir_testdata,'other','FEWS_202010221200_testdata_S_2.nc') @@ -68,15 +67,6 @@ ax2.set_ylim(-1,2) fig.savefig(file_ncout.replace('.nc','_nrs.png')) -""" -hatyan.write_netcdf(ts=ts_prediction, station=station_name, vertref='NAP', filename=file_ncout, ts_ext=ts_ext_prediction_nos, tzone_hr=0, nosidx=False) -#from dfm_tools.get_nc_helpers import get_ncvardimlist -#vars_pd, dims_pd = get_ncvardimlist(file_nc=file_ncout) -#data_nc_checkLWval = get_ncmodeldata(file_nc=file_ncout,varname='time_LW',timestep='all',station=0) -data_ncout = Dataset(file_ncout) -data_ncout.variables['waterlevel_astro_LW_numbers'] -data_ncout.variables['waterlevel_astro_HW_numbers'] -""" hatyan.write_netcdf(ts=ts_prediction, filename=file_ncout_nosidx, ts_ext=ts_ext_prediction_nos, nosidx=True) # add fake extra station to show how this works ts_prediction.attrs["station"] = station_name+"_COPY" diff --git a/tests/examples/numbering_extremes.py b/tests/examples/numbering_extremes.py index 387a3c1e..1251b972 100644 --- a/tests/examples/numbering_extremes.py +++ b/tests/examples/numbering_extremes.py @@ -93,12 +93,8 @@ file_data_comp0 = os.path.join(dir_testdata,'predictie2019','%s_ana.txt'%(current_station)) - - #file_data_compvali = os.path.join(dir_testdata,'predictie2019','%s_ana.txt'%(current_station)) times_pred = slice(dt.datetime(yr-1,12,31),dt.datetime(yr,1,2,12), "1min") - file_data_predvali = os.path.join(dir_testdata,'predictie2019','%s_pre.txt'%(current_station)) - #file_data_predvaliHWLW = os.path.join(dir_testdata,'predictie2019','%s_ext.txt'%(current_station)) #component groups COMP_merged = hatyan.read_components(filename=file_data_comp0) @@ -106,9 +102,6 @@ #prediction and validation ts_prediction = hatyan.prediction(comp=COMP_merged, times=times_pred) - #ts_validation = hatyan.read_dia(filename=file_data_predvali, station=current_station) - #ts_ext_validation = hatyan.read_dia(filename=file_data_predvaliHWLW, station=current_station) - #hatyan.write_dia(ts=ts_prediction, filename='prediction_%im_%s.dia'%(times_step_pred,current_station)) ts_ext_prediction = hatyan.calc_HWLW(ts=ts_prediction) if i_stat == 0: @@ -152,13 +145,7 @@ pdrow['RDx'] = RDx pdrow['RDy'] = RDy stats = pd.concat([stats,pdrow]) - - #hatyan.write_dia(ts=ts_ext_prediction, filename='prediction_HWLW_%im_%s.dia'%(times_step_pred, current_station)) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction, ts_ext=ts_ext_prediction, ts_ext_validation=ts_ext_validation) - #fig.savefig('prediction_%im_%s_HWLW'%(times_step_pred, current_station)) - #fig, (ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction, ts_ext=ts_ext_prediction) - #fig.savefig('prediction_%im_%s_validation'%(times_step_pred, current_station)) - + ax1.plot(ts_prediction.index, ts_prediction['values'], label=current_station, color=colors[i_stat]) ax1.plot([ts_firstlocalHW.name,ts_firstlocalHW.name], [ts_firstlocalHW['values'], 2.5], '--', linewidth=1.5, color=colors[i_stat]) ax1.plot(ts_firstlocalHW.name,ts_firstlocalHW['values'],'x', color=colors[i_stat]) @@ -166,11 +153,8 @@ if 1: #validation case #calculate tidal wave number times_pred_HWLWno = slice(dt.datetime(yr_HWLWno-1,12,31),dt.datetime(yr_HWLWno,1,2,12), "1min") - #COMP_merged_temp.loc['M2','A']=0.05 ts_prediction_HWLWno = hatyan.prediction(comp=COMP_merged, times=times_pred_HWLWno) ts_ext_prediction_HWLWno_pre = hatyan.calc_HWLW(ts=ts_prediction_HWLWno) - #fig,(ax1,ax2) = hatyan.plot_timeseries(ts=ts_prediction_HWLWno, ts_ext=ts_ext_prediction_HWLWno_pre) - #breakit print(current_station) ts_ext_prediction_HWLWno = hatyan.calc_HWLWnumbering(ts_ext=ts_ext_prediction_HWLWno_pre, station=current_station) @@ -191,8 +175,7 @@ stats['M2phasediff_hr'] = stats['M2phasediff']/360*12.420601 stats_M2phasediff_out = stats.sort_values('M2phasediff_hr')['M2phasediff'] - #stats_M2phasediff_out.to_csv(r'c:\DATA\hatyan_github\hatyan\data_M2phasediff_perstation_new.txt', sep=' ', header=False, float_format='%.2f') - + print(stats) print('') print(hatyan.schureman.get_schureman_freqs(['M2'])) @@ -223,9 +206,5 @@ for irow, pdrow in stats.iterrows(): fig2_ax1.text(pdrow['RDx'], pdrow['RDy'], '%.1f'%(pdrow['M2phasediff'])) - #fig2_ax1.text(pdrow['RDx'], pdrow['RDy'], '%.1f (%s)'%(pdrow['M2phasediff'],pdrow.name)) fig2.tight_layout() - if 0: - import contextily as ctx - ctx.add_basemap(fig2_ax1, source=ctx.providers.Esri.WorldImagery, crs=crs, attribution=False) fig2.savefig('tide_numbering_phasediff.png', dpi=250) diff --git a/tests/examples/predictie_2019_19Ycomp4Ydia.py b/tests/examples/predictie_2019_19Ycomp4Ydia.py index f85db054..84603c78 100644 --- a/tests/examples/predictie_2019_19Ycomp4Ydia.py +++ b/tests/examples/predictie_2019_19Ycomp4Ydia.py @@ -96,10 +96,6 @@ analysis_perperiod=analysis_perperiod, return_allperiods=True, cs_comps=cs_comps) - #fig,(ax1,ax2) = hatyan.plot_components(comp_fromts_avg, comp_allperiods=comp_fromts_all) - #fig.savefig('components_%s_4Y.png'%(current_station)) - #hatyan.write_components(comp_fromts_avg, filename='components_%s_4Y.txt'%(current_station)) - comp_fromfile = hatyan.read_components(filename=file_comp1) assert comp_fromfile.attrs["xfac"] == xfac diff --git a/tests/examples/spatialsummary.py b/tests/examples/spatialsummary.py index 13784277..e3bf4538 100644 --- a/tests/examples/spatialsummary.py +++ b/tests/examples/spatialsummary.py @@ -24,7 +24,6 @@ stats_all = ['ABDN','AMLAHVN','BAALHK','BATH','BERGSDSWT','BORSSLE','BOURNMH','BRESKS','BROUWHVSGT02','BROUWHVSGT08','CADZD','CROMR','CUXHVN','DELFZL','DENHDR','DENOVBTN','DEVPT','DORDT','DOVR','EEMHVN','EEMSHVN','EURPFM','EURPHVN','FELSWE','FISHGD','GEULHVN','GOIDSOD','GOUDBG','HAGSBNDN','HANSWT','HARLGN','HARMSBG','HARTBG','HARTHVN','HARVT10','HEESBN','HELLVSS','HOEKVHLD','HOLWD','HUIBGT','IJMDBTHVN','IJMDSMPL','IMMHM','KATSBTN','KEIZVR','KINLBVE','KORNWDZBTN','KRAMMSZWT','KRIMPADIJSL','KRIMPADLK','K13APFM','LAUWOG','LEITH','LICHTELGRE','LITHDP','LLANDNO','LOWST','MAASMSMPL','MAASSS','MAESLKRZZDE','MARLGT','MOERDK','NES','NEWHVN','NEWLN','NIEUWSTZL','NORTHSS','OOSTSDE04','OOSTSDE11','OOSTSDE14','OUDSD','OVLVHWT','PARKSS','PETTZD','PORTSMH','RAKND','ROOMPBNN','ROOMPBTN','ROTTDM','ROZBSSNZDE','ROZBSSZZDE','SCHAARVDND','SCHEVNGN','SCHIERMNOG','SCHOONHVN','SHEERNS','SINTANLHVSGR','SPIJKNSE','STAVNSE','STELLDBTN','STORNWY','SUURHBNZDE','TENNSHVN','TERNZN','TERSLNZE','TEXNZE','VLAARDGN','VLAKTVDRN','VLIELHVN','VLISSGN','VURN','WALSODN','WERKDBTN','WESTKPLE','WESTTSLG','WEYMH','WHITBY','WICK','WIERMGDN','YERSKE','A12','AUKFPFM','AWGPFM','D15','F16','F3PFM','J6','K14PFM','L9PFM','NORTHCMRT','Q1'] - case_list = ['A0','M2','S2']#,'P1','K1','K2','M4','P1_K1','NU2_N2','LABDA2_2MN2','K2_S2','T2_S2'] #get coordinates @@ -38,9 +37,7 @@ #get data and plot for case in case_list: - print('-'*50) - print('%-45s = %s'%('case',case)) - print('-'*5) + print(case) if '_' in case: const_list = case.split('_') else: @@ -60,7 +57,6 @@ else: A_list.append(COMP_sel.loc[const_list_sel[0],'A']/COMP_sel.loc[const_list_sel[1],'A']) phi_list.append(COMP_sel.loc[const_list_sel[0],'phi_deg']-COMP_sel.loc[const_list_sel[1],'phi_deg']) - if len(COMP_sel) == 1: if case=='A0': From 65cc080f8e1e2d606b873df005234392c27a9f0d Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Mon, 23 Dec 2024 12:50:39 +0100 Subject: [PATCH 2/2] updated testcase to avoid failure on 2022 duplicate extremes in DDL --- tests/test_ddlpy_helpers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_ddlpy_helpers.py b/tests/test_ddlpy_helpers.py index 7ec2b104..140ae5ec 100644 --- a/tests/test_ddlpy_helpers.py +++ b/tests/test_ddlpy_helpers.py @@ -61,8 +61,8 @@ def test_ddlpy_to_hatyan(locations, grootheid): @pytest.mark.unittest def test_convert_hwlwstr2num(locations): - tstart_dt = "2022-12-19" - tstop_dt = "2022-12-31" + tstart_dt = "2020-12-19" + tstop_dt = "2020-12-31" bool_grootheid_meas = locations['Grootheid.Code'].isin(['WATHTE']) bool_hoedanigheid = locations['Hoedanigheid.Code'].isin(['NAP']) @@ -79,10 +79,9 @@ def test_convert_hwlwstr2num(locations): # hatyan timeseries ts_measwlHWLW = hatyan.ddlpy_to_hatyan(meas_wathte_ext, meas_wathte_exttypes) - hwlwcode_expected = np.array([2, 1, 2, 1, 2, 1, 3, 4, 5, 1, 2, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, - 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, - 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, - 5, 1, 2, 1, 3, 4, 5, 1, 2, 1, 2, 1]) + hwlwcode_expected = np.array([2, 1, 3, 4, 5, 1, 2, 1, 3, 4, 5, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 4, + 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 3, 4, 5, 1, 2]) assert "HWLWcode" in ts_measwlHWLW.columns assert np.array_equal(ts_measwlHWLW["HWLWcode"].values, hwlwcode_expected)