def test_interface_network_init(): """ test limitation of interface to certain networks """ path_header_values = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'multinetwork', 'header_values') hv_interface = interface.ISMN_Interface(path_header_values, network=['SCAN']) assert hv_interface.list_networks().size == 1 assert hv_interface.list_networks()[0] == 'SCAN' hv_interface = interface.ISMN_Interface(path_header_values, network=['SCAN', 'MAQU']) assert hv_interface.list_networks().size == 2
def test_interface_plotting(): """ test plotting of networks """ path_header_values = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'multinetwork', 'header_values') hv_interface = interface.ISMN_Interface(path_header_values, network=['SCAN']) fig, axes = hv_interface.plot_station_locations() return fig
def test_find_nearest_station(): """ Test nearest neighbor search """ path_header_values = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'multinetwork', 'header_values') hv_interface = interface.ISMN_Interface(path_header_values, network=['SCAN']) station, distance = hv_interface.find_nearest_station(-90, 35, True) assert station.station == "AAMU-jtg" assert station.network == "SCAN" nptest.assert_almost_equal(distance, 316228.53147802927)
def test_min_max_obstime_getting(): """ test of the getting minimum and maxiumum observation time of a station """ path_header_values = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'format_header_values', 'SMOSMANIA') hv_interface = interface.ISMN_Interface(path_header_values) station = hv_interface.get_station('Narbonne') startd, endd = station.get_min_max_obs_timestamp() assert startd == datetime.datetime(2007, 1, 1, 1) assert endd == datetime.datetime(2007, 1, 31, 23) path_ceop_sep = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'format_ceop_sep', 'SMOSMANIA') ceop_sep_interface = interface.ISMN_Interface(path_ceop_sep) station = ceop_sep_interface.get_station('Narbonne') startd, endd = station.get_min_max_obs_timestamp() assert startd == datetime.datetime(2007, 1, 1, 1) assert endd == datetime.datetime(2007, 1, 31, 23)
def test_min_max_obstime_networks(): """ test of the getting minimum and maxiumum observation time of several networks """ path_header_values = os.path.join(os.path.dirname(__file__), '..', 'test-data', 'ismn', 'multinetwork', 'header_values') hv_interface = interface.ISMN_Interface(path_header_values) data = hv_interface.get_min_max_obs_timestamps(min_depth=0, max_depth=0.1) assert data.loc['MAQU']['end date'][0] == datetime.datetime( 2010, 7, 31, 23) assert data.loc['MAQU']['end date'][1] == datetime.datetime( 2010, 7, 31, 23) assert data.loc['MAQU']['start date'][1] == datetime.datetime( 2008, 7, 1, 0) assert data.loc['SCAN']['start date'][1] == datetime.datetime( 2007, 1, 1, 0) assert data.loc['SOILSCAPE']['start date'][1] == datetime.datetime( 2012, 12, 14, 19)
import pytesmo.io.ismn.interface as ismn_interface import pickle import matplotlib.pyplot as plt import numpy as np import pandas as pd from sgrt_devels.extr_TS import extr_SIG0_LIA_ts_GEE as extrts import ascat import h5py import datetime as dt # outpath outpath = '/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/ISMN/s1_ascat_smap_comp/' # initialise available ISMN data ismn = ismn_interface.ISMN_Interface( '/mnt/SAT/Workspaces/GrF/01_Data/InSitu/ISMN/') # get list of available stations available_stations = ismn.list_stations() # initialise S1 SM retrieval #mlmodel = pickle.load(open('/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/all_alps_plus_se_gee/pwise/mlmodel.p', 'rb')) # initialse text report txtrep = open(outpath + 'report.txt', 'w') txtrep.write('Name, R, RMSE\n') xyplot = pd.DataFrame() cntr = 1 # iterate through all available ISMN stations
#path to advisory flags from FTP Server path_to_adv_flags = os.path.join('path', 'to', 'advisory_flags', 'from', 'FTP Server') ascat_SSM_reader = ascat.Ascat_SSM(path_to_ascat_ssm_data, path_to_grid_definition, advisory_flags_path=path_to_adv_flags) path_to_ismn_data = os.path.join('/media', 'sf_D', 'small_projects', 'cpa_2013_07_ISMN_userformat_reader', 'ceop_sep_parser_test') #initialize interface, this can take up to a few minutes the first #time, since all metadata has to be collected ISMN_reader = ismn.ISMN_Interface(path_to_ismn_data) i = 0 label_ascat = 'SSM' label_insitu = 'insitu_sm' #this loops through all stations that measure soil moisture for station in ISMN_reader.stations_that_measure('soil moisture'): #this loops through all time series of this station that measure soil moisture #between 0 and 0.1 meters for ISMN_time_series in station.data_for_variable('soil moisture', min_depth=0, max_depth=0.1):
static_layers_folder = os.path.join(testdata_folder, 'sat/h_saf/static_layer') # init the ASCAT SSM reader with the paths ascat_SSM_reader = ascat.AscatSsmCdr(ascat_data_folder, ascat_grid_folder, grid_filename='TUW_WARP5_grid_info_2_1.nc', static_layer_path=static_layers_folder) ascat_SSM_reader.read_bulk = True # set path to ISMN data ismn_data_folder = os.path.join(testdata_folder, 'ismn/multinetwork/header_values') # Initialize reader ISMN_reader = ismn.ISMN_Interface(ismn_data_folder) i = 0 label_ascat = 'sm' label_insitu = 'insitu_sm' # this loops through all stations that measure soil moisture for station in ISMN_reader.stations_that_measure('soil moisture'): # this loops through all time series of this station that measure soil moisture # between 0 and 0.1 meters for ISMN_time_series in station.data_for_variable('soil moisture', min_depth=0, max_depth=0.1): ascat_time_series = ascat_SSM_reader.read(ISMN_time_series.longitude,
def __init__(self, timeframe, breaktime, max_depth=0.1): # Create a list of gpis nearest to the stations of the dataset # If a gpi is nearest for multiple stations, # create a list of stations for these gpis that have to be merged # when importing data for the gpi path_ismn_usa = os.path.join( 'U:\\', 'datasets', 'ISMN', 'insituUSA', 'Data_seperate_files_19500101_20170321_2365493_xzeO_20170321') self.breaktime = breaktime self.timeframe = timeframe self.max_depth = max_depth self.path_ismn = path_ismn_usa self.ISMN_reader = ismn.ISMN_Interface(self.path_ismn) networks = self.ISMN_reader.list_networks() defaultfile = r'H:\HomogeneityTesting_data\ismn_files\USA_gpinetsta_%s_%s_%s.pkl' % ( timeframe[0].strftime('%Y-%m-%d'), breaktime.strftime('%Y-%m-%d'), timeframe[1].strftime('%Y-%m-%d')) land_grid = load_grid( r"R:\Datapool_processed\GLDAS\GLDAS_NOAH025SUBP_3H\ancillary\GLDAS_025_grid.nc" ) if os.path.isfile(defaultfile): with open(defaultfile, 'rb') as f: self.gpis_with_netsta = pickle.load(f) else: print('File for stations near GPI not found. Creating...') self.gpis_with_netsta = {} # IDS of measurements of valid variable and depth for i, network in enumerate(networks): print(network, '%i of %i' % (i, len(networks) - 1)) stations = self.ISMN_reader.list_stations(network=network) for station in stations: station_obj = self.ISMN_reader.get_station( stationname=station, network=network) gpi, dist = land_grid.find_nearest_gpi( station_obj.longitude, station_obj.latitude) variables = station_obj.get_variables() if 'soil moisture' in variables: depths_from, depths_to = station_obj.get_depths( 'soil moisture') depths_from = np.unique(depths_from) depths_to = np.unique(depths_to) # Check if any sensor measured in the correct depth if any( np.around(depths_to, decimals=2) <= self.max_depth): station_timeframe = station_obj.get_min_max_obs_timestamp( ) # Check if station measured during the timeframe if (station_timeframe[0] < self.timeframe[1]) and \ (station_timeframe[1] > self.timeframe[0]): if gpi in self.gpis_with_netsta.keys(): self.gpis_with_netsta[gpi].append( (network, station)) else: self.gpis_with_netsta.update( {gpi: [(network, station)]}) with open(defaultfile, 'wb') as f: pickle.dump(self.gpis_with_netsta, f, pickle.HIGHEST_PROTOCOL)
import pytesmo.io.ismn.interface as ismn_interface from sgrt_devels.extr_TS import extr_SIG0_LIA_ts_GEE import matplotlib.pyplot as plt import numpy as np import pandas as pd import os import pickle # outpath outpath = '/mnt/SAT/Workspaces/GrF/02_Documents/1_THESIS/pub3/plots/valid_stations/' # use descending orbits desc = False # initialise available ISMN data ismn = ismn_interface.ISMN_Interface('/mnt/SAT4/DATA/S1_EODC/ISMN/') # get the stations the qualified for training #used_stations = np.load('/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/ISMN/gee_global_ASC_DESC/ValidStaions.npy') invalid_col = pickle.load(open('/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/ISMN/tmp/invalid_col.p', 'rb')) # iterate through all stations #for vstation in used_stations: for i in range(len(invalid_col['label'])): #ntwk, st_name = [x.strip() for x in vstation.split(',')] ntwk = invalid_col['ntwkname'][i] st_name = invalid_col['stname'][i] if os.path.exists(outpath + st_name + '.png'): continue
def ismn_validation_run(bsize=500, name='500m', fvect1=None, fvect2=None, fvect1desc=None, fvect2desc=None): s1path = 117 #bsize=250 basepath = '//projectdata.eurac.edu/projects/ESA_TIGER/S1_SMC_DEV/Processing/S1ALPS/ISMN/S1AB_' + name + '_reprocess_lt_05/' # outpath outpath = basepath + 'w_GLDAS_asc_desc/' # Calculate prediction standar deviations calcstd = False # use descending orbits desc = False # calculate anomalies? calc_anomalies = False # initialise available ISMN data ismn = ismn_interface.ISMN_Interface( 'T:/ECOPOTENTIAL/reference_data/ISMN/') # get list of networks networks = ismn.list_networks() # initialise S1 SM retrieval # mlmodel = pickle.load(open('/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/ASCAT/gee/mlmodel0.p', 'rb')) mlmodel_avg = "//projectdata.eurac.edu/projects/ESA_TIGER/S1_SMC_DEV/Processing/S1ALPS/ISMN/S1AB_1km_reprocess_lt_05/no_GLDAS_RFmlmodelNoneSVR_2step.p" mlmodel = basepath + "w_GLDAS_RFmlmodelNoneSVR_2step.p" mlmodel_desc = "//projectdata.eurac.edu/projects/ESA_TIGER/S1_SMC_DEV/Processing/S1ALPS/ISMN/S1AB_50m_reprocess_lt_05_descending/w_GLDAS_RFmlmodelNoneSVR_2step.p" # initialse text report txtrep = open(outpath + '2_report.txt', 'w') txtrep.write( 'Accuracy report for Soil Moisture validation based on ISMN stations\n\n' ) txtrep.write('Model used: ' + mlmodel + '\n') txtrep.write( '------------------------------------------------------------------------\n\n' ) txtrep.write('Name, R, RMSE\n') xyplot = pd.DataFrame() cntr = 1 #used_stations = np.load('X:/Workspaces/GrF/Processing/S1ALPS/ISMN/gee_global_all_no_deep/ValidStaions.npy') used_stations = pickle.load(open(basepath + "testset_meta.p", 'rb')) #invalid_col = pickle.load(open('/mnt/SAT/Workspaces/GrF/Processing/S1ALPS/ISMN/gee_global005_highdbtollerance/invalid_col.p', 'rb')) #used_stations = [invalid_col['ntwkname'][i] + ', ' + invalid_col['stname'][i] for i in range(len(invalid_col['ntwkname']))] #for ntwk in networks: #for vstation in used_stations: s1_ts_list = list() station_ts_list = list() station_name_list = list() gldas_ts_list = list() s1_failed_list = list() s1_ub_list = list() for st_i in range(len(used_stations[0])): #for st_i in [0]: #ntwk, st_name = [x.strip() for x in vstation.split(',')] ntwk = used_stations[1][st_i] st_name = used_stations[0][st_i] # if st_name != 'ROSASCYN':# and st_name != 'Salem-10-W': # continue # get list of available stations available_stations = ismn.list_stations(ntwk) # iterate through all available ISMN stations #for st_name in available_stations: try: station = ismn.get_station(st_name, ntwk) station_vars = station.get_variables() # if st_name != '2.10': # continue # if (st_name != 'Boulder-14-W'): # continue #if st_name not in ['ANTIMONYFL', 'CALIVALLEY', 'Bethlehem']: # if st_name not in ['CALIVALLEY']: # continue if 'soil moisture' not in station_vars: continue station_depths = station.get_depths('soil moisture') # if 0.0 in station_depths[0]: # sm_sensors = station.get_sensors('soil moisture', depth_from=0, depth_to=0.24) # station_ts = station.read_variable('soil moisture', depth_from=0, depth_to=0.24, sensor=sm_sensors[0]) # else: # continue if 0.0 in station_depths[0]: did = np.where(station_depths[0] == 0.0) dto = station_depths[1][did] sm_sensors = station.get_sensors('soil moisture', depth_from=0, depth_to=dto[0]) print(sm_sensors[0]) station_ts = station.read_variable('soil moisture', depth_from=0, depth_to=dto[0], sensor=sm_sensors[0]) elif 0.05 in station_depths[0]: sm_sensors = station.get_sensors('soil moisture', depth_from=0.05, depth_to=0.05) station_ts = station.read_variable('soil moisture', depth_from=0.05, depth_to=0.05, sensor=sm_sensors[0]) else: continue print(st_name) plotpath = outpath + st_name + '.png' # if os.path.exists(plotpath): # continue # get station ts station_ts = station_ts.data['soil moisture'] # get S1 time series s1_ts, s1_ts_std, outliers, s1_failed = extract_time_series_gee( mlmodel, mlmodel_avg, '/mnt/SAT4/DATA/S1_EODC/', outpath, station.latitude, station.longitude, name=st_name, footprint=bsize, calcstd=calcstd, desc=desc, target=station_ts, feature_vect1=fvect1, feature_vect2=fvect2) #, #s1path=s1path) s1_ts2, s1_ts_std2, outliers2, s1_failed2 = extract_time_series_gee( mlmodel_desc, mlmodel_avg, '/mnt/SAT4/DATA/S1_EODC/', outpath, station.latitude, station.longitude, name=st_name, footprint=bsize, calcstd=calcstd, desc=True, target=station_ts, feature_vect1=fvect1desc, feature_vect2=fvect2desc) # , if (s1_ts is not None) and (s1_ts2 is not None): # correct the mean offset between time-series from ascending and descending orbits meandiff = s1_ts.mean() - s1_ts2.mean() s1_ts2 = s1_ts2 + meandiff meandiff_failed = s1_failed.median() - s1_failed2.median() s1_failed2 = s1_failed2 + meandiff_failed s1_ts = pd.concat([s1_ts, s1_ts2]) s1_failed = pd.concat([s1_failed, s1_failed2]) elif (s1_ts is None) and (s1_ts2 is not None): s1_ts = s1_ts2 s1_failed = s1_failed2 s1_ts.sort_index(inplace=True) s1_failed.sort_index(inplace=True) if s1_ts is None: continue if len(s1_ts) < 5: continue #evi_ts = extr_MODIS_MOD13Q1_ts_GEE(station.longitude, station.latitude, bufferSize=150) #evi_ts = pd.Series(evi_ts[1]['EVI'], index=evi_ts[0]) gldas_ts = extr_GLDAS_ts_GEE( station.longitude, station.latitude, bufferSize=150, yearlist=[2014, 2015, 2016, 2017, 2018, 2019]) gldas_ts = gldas_ts / 100. start = np.array([s1_ts.index[0], station_ts.index[0]]).max() end = np.array([s1_ts.index[-1], station_ts.index[-1]]).min() if start > end: continue station_ts = station_ts[start:end] s1_ts = s1_ts[start:end] s1_failed = s1_failed[start:end] #outliers = outliers[start:end] #evi_ts = evi_ts[start:end] gldas_ts = gldas_ts[start:end] if calcstd == True: s1_ts_std = s1_ts_std[start:end] if len(s1_ts) < 1: continue #station_ts = station_ts.iloc[np.where(station_ts > 0.1)] #s1_ts = s1_ts[np.where(error_ts == error_ts.min())[0]] s1_ts_res = s1_ts.resample('D').mean().rename('s1') station_ts_res = station_ts.resample('D').mean().rename('ismn') gldas_ts_res = gldas_ts.resample('D').mean().rename('gldas') if calc_anomalies == True: from pytesmo.time_series import anomaly as pyan s1_clim = pyan.calc_climatology(s1_ts_res.interpolate()) station_clim = pyan.calc_climatology( station_ts_res.interpolate()) s1_ts = pyan.calc_anomaly(s1_ts, climatology=s1_clim) s1_ts_res = pyan.calc_anomaly(s1_ts_res, climatology=s1_clim) station_ts = pyan.calc_anomaly(station_ts, climatology=station_clim) station_ts_res = pyan.calc_anomaly(station_ts_res, climatology=station_clim) # calculate error metrics ts_bias = s1_ts_res.subtract(station_ts_res).mean() # cdf matching tobemerged = [ s1_ts_res.dropna(), gldas_ts_res.dropna(), station_ts_res.dropna() ] s1_and_station = pd.concat(tobemerged, axis=1, join='inner') statmask = (s1_and_station['ismn'] > 0) & ( s1_and_station['ismn'] < 1) & (s1_and_station['s1'] > 0) & (s1_and_station['s1'] < 1) p2 = s1_and_station['ismn'][statmask].std( ) / s1_and_station['s1'][statmask].std() p1 = s1_and_station['ismn'][statmask].mean() - ( p2 * s1_and_station['s1'][statmask].mean()) s1_ts_ub = p1 + (p2 * s1_ts) s1_and_station['s1ub'] = p1 + (p2 * s1_and_station['s1']) ts_bias = s1_and_station['s1ub'].subtract( s1_and_station['ismn']).median() s1_failed = p1 + (p2 * s1_failed) xytmp = pd.concat( { 'y': s1_and_station['s1ub'], 'x': s1_and_station['ismn'] }, join='inner', axis=1) if cntr == 1: xyplot = xytmp else: xyplot = pd.concat([xyplot, xytmp], axis=0) cntr = cntr + 1 ts_cor = s1_and_station['s1ub'].corr(s1_and_station['ismn']) ts_rmse = np.sqrt( np.nanmean( np.square(s1_and_station['s1ub'].subtract( s1_and_station['ismn'])))) #ts_ubrmse = np.sqrt(np.sum(np.square(s1_ts_res.subtract(s1_ts_res.mean()).subtract(station_ts_res.subtract(station_ts_res.mean()))))) ts_ubrmse = np.sqrt( np.sum( np.square((s1_and_station['s1ub'] - s1_and_station['s1ub'].mean()) - (s1_and_station['ismn'] - s1_and_station['ismn'].mean()))) / len(s1_and_station['s1ub'])) print('R: ' + str(ts_cor)) print('RMSE: ' + str(ts_rmse)) print('Bias: ' + str(ts_bias)) txtrep.write(st_name + ', ' + str(ts_cor) + ', ' + str(ts_rmse) + '\n') s1_ts_list.append(s1_ts) station_ts_list.append(station_ts) station_name_list.append(st_name) gldas_ts_list.append(gldas_ts) s1_failed_list.append(s1_failed) s1_ub_list.append(s1_ts_ub) # plot # plt.figure(figsize=(18, 6)) fig, ax1 = plt.subplots(figsize=(7.16, 1.4), dpi=300) line1, = ax1.plot(s1_ts_ub.index, s1_ts_ub, color='b', linestyle='', marker='+', label='Sentinel-1', linewidth=0.2) line8, = ax1.plot(s1_failed.index, s1_failed, color='r', linestyle='', marker='+', label='fail', linewidth=0.2) line2, = ax1.plot(station_ts.index, station_ts, label='In-Situ', linewidth=0.4) if np.any(outliers) and outliers is not None: line6, = ax1.plot(s1_ts.index[outliers], s1_ts.iloc[outliers], color='r', linestyle='', marker='o') #line3, = ax1.plot(outliers.index, outliers, color='r', linestyle='', marker='*', label='Outliers') if calcstd == True: line4, = ax1.plot(s1_ts.index, s1_ts - np.sqrt(s1_ts_std), color='k', linestyle='--', linewidth=0.2) line5, = ax1.plot(s1_ts.index, s1_ts + np.sqrt(s1_ts_std), color='k', linestyle='--', linewidth=0.2) #ax3 = ax1.twinx() line6, = ax1.plot(gldas_ts.index, gldas_ts, color='g', linestyle='--', label='GLDAS', linewidth=0.2) #line3, = ax3.plot(evi_ts.index, evi_ts, linewidth=0.4, color='r', linestyle='--', label='MOD13Q1:EVI') # ax3.axes.tick_params(axis='y', direction='in', labelcolor='r', right='off', labelright='off') ax1.set_ylabel('Soil Moisture [m3m-3]', size=8) smc_max = np.max([s1_ts.max(), station_ts.max()]) if smc_max <= 0.5: smc_max = 0.5 ax1.set_ylim((0, smc_max)) ax1.text( 0.85, 0.4, 'R=' + '{:03.2f}'.format(ts_cor) + #'\nRMSE=' + '{:03.2f}'.format(ts_rmse) + '\nBias=' + '{:03.2f}'.format(ts_bias) + '\nRMSE=' + '{:03.2f}'.format(ts_rmse), transform=ax1.transAxes, fontsize=8) # ax2.set_ylabel('In-Situ [m3/m3]') #ax3.set_ylabel('EVI') #fig.tight_layout() #plt.legend(handles=[line1, line2], loc='upper left', fontsize=8)#, line3, line6]) plt.title(st_name, fontsize=8) #plt.show() plt.tight_layout() plt.savefig(plotpath, dpi=300) plt.close() except: print('No data for: ' + st_name) pickle.dump( (s1_ts_list, s1_ub_list, s1_failed, station_ts_list, gldas_ts_list, station_name_list), open( 'C:/Users/FGreifeneder/OneDrive - Scientific Network South Tyrol/1_THESIS/pub3/images_submission2/w_GLDAS_validation_tss_' + name + '.p', 'wb')) scatter_valid = np.where(((xyplot['x'] > 0) & (xyplot['x'] < 1)) & ((xyplot['y'] > 0) & (xyplot['y'] < 1))) xyplot = xyplot.iloc[scatter_valid] urmse_scatter = np.sqrt( np.sum( np.square((xyplot['y'] - xyplot['y'].mean()) - (xyplot['x'] - xyplot['x'].mean()))) / len(xyplot['y'])) rmse_scatter = np.sqrt( np.nanmean(np.square(xyplot['x'].subtract(xyplot['y'])))) r_scatter = xyplot['x'].corr(xyplot['y']) #plt.figure(figsize=(3.5, 3), dpi=600) xyplot.plot.scatter(x='x', y='y', color='k', xlim=(0, 1), ylim=(0, 1), figsize=(3.5, 3), s=1, marker='*') plt.xlim(0, 1) plt.ylim(0, 1) plt.xlabel("$SMC_{Tot}$ [m$^3$m$^{-3}$]", size=8) plt.ylabel("$SMC^*_{Tot}$ [m$^3$m$^{-3}$]", size=8) plt.plot([0, 1], [0, 1], 'k--', linewidth=0.8) plt.text(0.1, 0.5, 'R=' + '{:03.2f}'.format(r_scatter) + '\nRMSE=' + '{:03.2f}'.format(rmse_scatter), fontsize=8) # + #'\nRMSE=' + '{:03.2f}'.format(rmse_scatter), fontsize=8) plt.tick_params(labelsize=8) plt.title('True vs. estimated SMC', size=8) plt.axes().set_aspect('equal', 'box') plt.tight_layout() plt.savefig(outpath + '1_scatterplot.png', dpi=600) plt.close() txtrep.write( '------------------------------------------------------------------------\n\n' ) txtrep.write('Overall performance:\n') txtrep.write('R = ' + str(xyplot['x'].corr(xyplot['y'])) + '\n') txtrep.write( 'RMSE = ' + str(np.sqrt(np.nanmean(np.square(xyplot['x'].subtract(xyplot['y'])))))) txtrep.write('ubRMSE = ' + str( np.sqrt( np.sum( np.square((xyplot['y'] - xyplot['y'].mean()) - (xyplot['x'] - xyplot['x'].mean()))) / len(xyplot['y'])))) txtrep.close()
def plot_ismn_map(): stations = pickle.load(open( '/mnt/CEPH_PROJECTS/ESA_TIGER/S1_SMC_DEV/Processing/S1ALPS/ISMN/newrun_ft_descending/stations.tmp', 'rb'), encoding='latin-1') ismn = ismn_interface.ISMN_Interface( '/mnt/CEPH_PROJECTS/ECOPOTENTIAL/reference_data/ISMN/') fig = plt.figure(figsize=(5, 4)) ax = plt.subplot(111) #plt.figure(figsize=(3.5, 3)) m = Basemap(projection='mill', ax=ax) m.drawcoastlines(linewidth=0.5) #m.fillcontinents() # plot stations from the different networks with different markers markerlist = [ 'o', 'v', '*', 'h', 'p', '^', '+', 'x', 'd', '8', 's', '*', 'v', 'o', 'p', 'h', '^', 'x', '+', '8', 'd', 's', 's', '8', 'd', 'x', '+', 'p', '^', 'p', 'h', '*', 'o' ] colours = [ 'g', 'b', 'r', 'k', 'y', 'c', 'm', 'g', 'k', 'b', 'c', 'c', 'b', 'k', 'g', 'm', 'c', 'y', 'k', 'b', 'r', 'g', 'g', 'b', 'r', 'k', 'y', 'c', 'm', 'g', 'k', 'b', 'c' ] # create a networklist allntwks = list() for i_ntwk, _ in stations: allntwks.append(i_ntwk) allntwks = np.unique(allntwks) for i_ntwk, i_sttn in stations: style_ind = np.where(allntwks == i_ntwk)[0][0] lon = ismn.get_station(i_sttn, i_ntwk).longitude lat = ismn.get_station(i_sttn, i_ntwk).latitude x, y = m(lon, lat) m.plot(x, y, marker='.', color='C' + str(style_ind), linestyle='', markersize=1.5, label=str(i_ntwk)) m.drawmeridians([-180, -90, 0, 90, 180], labels=[1, 1, 0, 1], fontsize="x-small") m.drawparallels([-60, 0, 60], labels=[1, 1, 0, 1], fontsize="x-small") box = ax.get_position() ax.set_position( [box.x0, box.y0 + box.height * 0.2, box.width, box.height * 0.9]) #create legend without dublicates handles, labels = plt.gca().get_legend_handles_labels() by_label = dict(zip(labels, handles)) plt.legend(by_label.values(), by_label.keys()) # Put a legend below current axis ax.legend(by_label.values(), by_label.keys(), loc='upper center', bbox_to_anchor=(0.5, -0.1), fancybox=True, shadow=False, ncol=4, fontsize='x-small', markerscale=5) #plt.tight_layout() plt.savefig( "/home/[email protected]/Documents/sm_paper/sub3mdpi/used_ismn_stations.png", dpi=600) plt.close()