def main(): """ command line interface for download_rinex """ parser = argparse.ArgumentParser() parser.add_argument("inputfile", help="inputfile name", type=str) parser.add_argument("outputfile", help="outputfile name", type=str) # optional arguments args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() inputfile = args.inputfile outputfile = args.outputfile n.nmea_snr(inputfile, outputfile)
def gnssir_guts(station, year, doy, snr_type, extension, lsp): """ my attempt to separate the inputs to the code and the guts of the code inputs are station name, year, day of year (integers) snr_type is an integer (99, 66, etc). lsp is a json """ # make sure environment variables exist. set to current directory if not g.check_environ_variables() e1 = lsp['e1'] e2 = lsp['e2'] minH = lsp['minH'] maxH = lsp['maxH'] ediff = lsp['ediff'] NReg = lsp['NReg'] PkNoise = lsp['PkNoise'] azval = lsp['azval'] naz = int(len(azval) / 2) freqs = lsp['freqs'] reqAmp = lsp['reqAmp'] plot_screen = lsp['plt_screen'] onesat = lsp['onesat'] screenstats = lsp['screenstats'] azval = lsp['azval'] d = g.doy2ymd(year, doy) month = d.month day = d.day dmjd, fracS = g.mjd(year, month, day, 0, 0, 0) xdir = os.environ['REFL_CODE'] ann = g.make_nav_dirs(year) # make sure directories are there for orbits g.result_directories(station, year, extension) # make directories for the LSP results # this defines the minimum number of points in an arc. This depends entirely on the sampling # rate for the receiver, so you should not assume this value is relevant to your case. minNumPts = 20 p, T, irefr = set_refraction_params(station, dmjd, lsp) # only doing one day at a time for now - but have started defining the needed inputs for using it twoDays = False obsfile2 = '' # dummy value for name of file for the day before, when we get to that fname, resultExist = g.LSPresult_name(station, year, doy, extension) if (resultExist): print('Results already exist on disk') if (lsp['overwriteResults'] == False) & (resultExist == True): allGood = 0 print( '>>>>> The result file exists for this day and you have selected the do not overwrite option' ) sys.exit() print('go ahead and access SNR data - first define SNR filename') obsfile, obsfileCmp, snre = g.define_and_xz_snr(station, year, doy, snr_type) print(obsfile, 'snrexistence', snre, ' and ', snr_type) if (not snre) and (not lsp['seekRinex']): print( 'SNR file does not exist and you have set the seekRinex variable to False' ) print('Use rinex2snr.py to make SNR files') sys.exit() if (not snre) and lsp['seekRinex']: print('SNR file does not exist. I will try to make a GPS only file.') rate = 'low' dec_rate = 0 orbtype = 'nav' g.quick_rinex_snrC(year, doy, station, snr_type, orbtype, rate, dec_rate) allGood, sat, ele, azi, t, edot, s1, s2, s5, s6, s7, s8, snrE = snr.read_snr_multiday( obsfile, obsfile2, twoDays) snr.compress_snr_files(lsp['wantCompression'], obsfile, obsfile2, twoDays) # SNR exists - go ahead if (allGood == 1): ele = apply_refraction_corr(lsp, ele, p, T) fout, frej = g.open_outputfile(station, year, doy, extension) # main loop a given list of frequencies total_arcs = 0 ct = 0 for f in freqs: if plot_screen: fig, (ax1, ax2) = plt.subplots(2, 1) rj = 0 gj = 0 print('**** looking at frequency ', f, ' ReqAmp', reqAmp[ct], ' doy ', doy, 'YYYY/MM/DD', year, month, day) # get the list of satellites for this frequency if onesat == None: satlist = g.find_satlist(f, snrE) else: satlist = onesat if (int(satlist[0]) < 100) and (f > 100): print('wrong satellite name for this frequency') for satNu in satlist: #if screenstats: print('Satellite', satNu) for a in range(naz): az1 = azval[(a * 2)] az2 = azval[(a * 2 + 1)] x, y, Nv, cf, UTCtime, avgAzim, avgEdot, Edot2, delT = g.window_data( s1, s2, s5, s6, s7, s8, sat, ele, azi, t, edot, f, az1, az2, e1, e2, satNu, lsp['polyV'], lsp['pele'], screenstats) MJD = g.getMJD(year, month, day, UTCtime) if Nv > minNumPts: maxF, maxAmp, eminObs, emaxObs, riseSet, px, pz = g.strip_compute( x, y, cf, maxH, lsp['desiredP'], lsp['polyV'], minH) nij = pz[(px > NReg[0]) & (px < NReg[1])] Noise = 0 if (len(nij) > 0): Noise = np.mean(nij) iAzim = int(avgAzim) okPk = True if abs(maxF - minH) < 0.10: # peak too close to min value okPk = False print( 'found a peak too close to the edge of the restricted RH region' ) if okPk & (delT < lsp['delTmax']) & ( eminObs < (e1 + ediff)) & (emaxObs > (e2 - ediff)) & ( maxAmp > reqAmp[ct]) & (maxAmp / Noise > PkNoise): fout.write( " {0:4.0f} {1:3.0f} {2:6.3f} {3:3.0f} {4:6.3f} {5:6.2f} {6:6.2f} {7:6.2f} {8:6.2f} {9:4.0f} {10:3.0f} {11:2.0f} {12:8.5f} {13:6.2f} {14:7.2f} {15:12.6f} {16:1.0f} \n" .format(year, doy, maxF, satNu, UTCtime, avgAzim, maxAmp, eminObs, emaxObs, Nv, f, riseSet, Edot2, maxAmp / Noise, delT, MJD, irefr)) gj += 1 if screenstats: T = g.nicerTime(UTCtime) print( 'SUCCESS Azimuth {0:3.0f} Sat {1:3.0f} RH {2:7.3f} m PkNoise {3:4.1f} Amp {4:4.1f} Fr{5:3.0f} UTC {6:5s} DT {7:3.0f} ' .format(iAzim, satNu, maxF, maxAmp / Noise, maxAmp, f, T, round(delT))) if plot_screen: local_update_plot(x, y, px, pz, ax1, ax2) else: rj += 1 if screenstats: print( 'FAILED QC for Azimuth {0:.1f} Satellite {1:2.0f} UTC {2:5.2f}' .format(iAzim, satNu, UTCtime)) g.write_QC_fails(delT, lsp['delTmax'], eminObs, emaxObs, e1, e2, ediff, maxAmp, Noise, PkNoise, reqAmp[ct]) print( '=================================================================================' ) print(' Frequency ', f, ' good arcs:', gj, ' rejected arcs:', rj) print( '=================================================================================' ) total_arcs = gj + total_arcs # close the output files ct += 1 #'Yes' if fruit == 'Apple' else 'No' if plot_screen: plot2screen(station, f, ax1, ax2, lsp['pltname']) fout.close()
def main(): # make surer environment variables are set g.check_environ_variables() xdir = os.environ['REFL_CODE'] # must input start and end year parser = argparse.ArgumentParser() parser.add_argument("station", help="station name", type=str) # optional inputs: filename to output daily RH results parser.add_argument("-year", default='None', type=str, help="restrict to years beginning with") parser.add_argument("-txtfile", default='None', type=str, help="output (plain text)") parser.add_argument("-csvfile", default='None', type=str, help="output (csv)") parser.add_argument("-jsonfile", default='None', type=str, help="output (json)") parser.add_argument("-plt", default='None', type=str, help="set to False to suppress plots") args = parser.parse_args() # these are required station = args.station # these are optional txtfile = args.txtfile csvfile = args.csvfile jsonfile = args.jsonfile writetxt = True if txtfile == 'None': writetxt = False writecsv = True if csvfile == 'None': writecsv = False writejson = True if jsonfile == 'None': writejson = False if args.year == 'None': year = 2020 else: year=int(args.year) if args.plt == 'False': plt= False else: plt = True # where the summary files will be written to txtdir = xdir + '/Files' if not os.path.exists(txtdir): os.makedirs(txtdir) direc = xdir + '/' + str(year) + '/results/' + station + '/' tv = np.empty(shape=[0, 17]) if os.path.isdir(direc): all_files = os.listdir(direc) #print('Number of files in ', year1, len(all_files)) for f in all_files: fname = direc + f a = np.loadtxt(fname,comments='%') tv = np.append(tv, a,axis=0) #print(tv.shape) t=tv[:,0] + (tv[:,1] + tv[:,4]/24)/365.25 rh = tv[:,2] # sort the data ii = np.argsort(t) t = t[ii] ; rh = rh[ii] # store it all in a new variable ntv = tv[ii,:] # Plt.figure() Plt.plot(t, rh,'.') Plt.ylabel('Reflector Height (m)') Plt.title('GNSS station: ' + station) Plt.gca().invert_yaxis() Plt.grid() # default is to show the plot #if plt: #Plt.show() # always make a png file plotname = txtdir + '/' + station + '_subdaily_RH.png' Plt.savefig(plotname) print('png file saved as: ', plotname) splines_for_dummies(t,rh,plt) # apply time tags to a new variable N,M = np.shape(ntv) if writejson: outfile = txtdir + '/' + jsonfile if writecsv: outfile = txtdir + '/' + csvfile if writetxt: outfile = txtdir + '/' + txtfile if (writecsv) and (writetxt) : print('You cannot simultaneously write out a csvfile and a txtfile') print('Default to writing only a txtfile') writecsv = False if (writejson): print('you picked the json output') o = {} N= len(ntv) column_names = ['timestamp','rh','sat','freq','ampl','azim','edotf','mjd'] # this worked - but didn't have names, so not useful #o['station'] = station #o['data'] = ntv[:,[0,1,2,4,15,3]].tolist() # give my numpy variables names # to make a string # x=datetime.datetime(2018,9,15) # print(x.strftime("%b %d %Y %H:%M:%S")) year = ntv[:,0].tolist() year =[str(int(year[i])) for i in range(N)]; doy = ntv[:,1].tolist() doy=[str(int(doy[i])) for i in range(N)]; UTChour = ntv[:,4].tolist() UTChour = [str(UTChour[i]) for i in range(N)]; timestamp = [quickTr(ntv[i,0], ntv[i,1], ntv[i,4]) for i in range(N)] rh = ntv[:,2].tolist() rh=[str(rh[i]) for i in range(N)]; sat = ntv[:,3].tolist() sat =[int(sat[i]) for i in range(N)]; freq = ntv[:,10].tolist() freq =[int(freq[i]) for i in range(N)]; ampl = ntv[:,6].tolist() ampl =[str(ampl[i]) for i in range(N)]; azim = ntv[:,5].tolist() azim =[str(azim[i]) for i in range(N)]; edotf = ntv[:,12].tolist() edotf =[str(edotf[i]) for i in range(N)]; mjd = ntv[:,15].tolist() mjd=[str(mjd[i]) for i in range(N)]; # now attempt to zip them l = zip(timestamp,rh,sat,freq,ampl,azim,edotf,mjd) dzip = [dict(zip(column_names, next(l))) for i in range(N)] # make a dictionary with metadata and data o={} lat = "0"; lon = "0"; firstline = {'name': station, 'latitude': lat, 'longitude': lon} o['metadata'] = firstline o['data'] = dzip outf = outfile print(outfile) with open(outf,'w+') as outf: json.dump(o,outf,indent=4) #close(outf) if (writecsv) or (writetxt): print('Results are being written to : ', outfile) fout = open(outfile, 'w+') write_out_header(fout,station) for i in np.arange(0,N,1): year = int(ntv[i,0]); doy = int(ntv[i,1]) year, month, day, cyyyy,cdoy, YMD = g.ydoy2useful(year,doy) rh = ntv[i,2]; UTCtime = ntv[i,4]; mjd = ntv[i,15] ctime = g.nicerTime(UTCtime); ctime2 = ctime[0:2] + ' ' + ctime[3:5] if writecsv: fout.write(" {0:4.0f},{1:3.0f},{2:7.3f},{3:3.0f},{4:7.3f},{5:8.2f},{6:7.2f},{7:5.2f}, {8:3.0f},{9:8.5f}, {10:2.0f}, {11:2.0f},{12:2s},{13:2s},{14:15.6f} \n".format(year, doy, rh,ntv[i,3],UTCtime,ntv[i,5],ntv[i,6],ntv[i,13],ntv[i,10],ntv[i,12],month,day,ctime[0:2],ctime[3:5] ,mjd )) else: fout.write(" {0:4.0f} {1:3.0f} {2:7.3f} {3:3.0f} {4:7.3f} {5:8.2f} {6:7.2f} {7:5.2f} {8:3.0f} {9:8.5f} {10:2.0f} {11:2.0f} {12:5s} {13:15.6f} \n".format(year, doy, rh,ntv[i,3],UTCtime,ntv[i,5],ntv[i,6],ntv[i,13],ntv[i,10],ntv[i,12],month,day,ctime2,mjd )) fout.close()
def main(): # make surer environment variables are set g.check_environ_variables() xdir = os.environ['REFL_CODE'] # must input start and end year parser = argparse.ArgumentParser() parser.add_argument("station", help="station name", type=str) # optional inputs: filename to output daily RH results parser.add_argument("-year", default='None', type=str, help="restrict to years beginning with") parser.add_argument("-txtfile", default='None', type=str, help="output (plain text)") parser.add_argument("-csvfile", default='None', type=str, help="output (csv)") parser.add_argument("-plt", default='None', type=str, help="set to False to suppress plots") args = parser.parse_args() # these are required station = args.station # these are optional txtfile = args.txtfile csvfile = args.csvfile if args.plt == 'False': plt = False else: plt = True writetxt = True writecsv = True if txtfile == 'None': writetxt = False if csvfile == 'None': writecsv = False if args.year == 'None': year = 2020 else: year = int(args.year) # where the summary files will be written to txtdir = xdir + '/Files' if not os.path.exists(txtdir): os.makedirs(txtdir) direc = xdir + '/' + str(year) + '/results/' + station + '/' tv = np.empty(shape=[0, 17]) if os.path.isdir(direc): all_files = os.listdir(direc) #print('Number of files in ', year1, len(all_files)) for f in all_files: fname = direc + f a = np.loadtxt(fname, comments='%') tv = np.append(tv, a, axis=0) #print(tv.shape) Plt.figure() t = tv[:, 0] + (tv[:, 1] + tv[:, 4] / 24) / 365.25 rh = tv[:, 2] Plt.plot(t, rh, '.') Plt.ylabel('Reflector Height (m)') Plt.title('GNSS station: ' + station) Plt.gca().invert_yaxis() Plt.grid() # default is to show the plot if plt: Plt.show() # always make a png file plotname = txtdir + '/' + station + '_subdaily_RH.png' Plt.savefig(plotname) print('png file saved as: ', plotname) ii = np.argsort(t) # apply time tags to a new variable ntv = tv[ii, :] N, M = np.shape(ntv) #txtfile = station + '_subdaily_rh.txt' #csvfile = station + '_subdaily_rh.csv' if writecsv: outfile = txtdir + '/' + csvfile if writetxt: outfile = txtdir + '/' + txtfile if (writecsv) and (writetxt): print('You cannot simultaneously write out a csvfile and a txtfile') print('Default to writing only a txtfile') writecsv = False if (writecsv) or (writetxt): print('Results are being written to : ', outfile) fout = open(outfile, 'w+') write_out_header(fout, station) for i in np.arange(0, N, 1): year = int(ntv[i, 0]) doy = int(ntv[i, 1]) year, month, day, cyyyy, cdoy, YMD = g.ydoy2useful(year, doy) rh = ntv[i, 2] UTCtime = ntv[i, 4] mjd = ntv[i, 15] ctime = g.nicerTime(UTCtime) ctime2 = ctime[0:2] + ' ' + ctime[3:5] if writecsv: fout.write( " {0:4.0f},{1:3.0f},{2:7.3f},{3:3.0f},{4:7.3f},{5:8.2f},{6:7.2f},{7:5.2f}, {8:3.0f},{9:8.5f}, {10:2.0f}, {11:2.0f},{12:2s},{13:2s},{14:15.6f} \n" .format(year, doy, rh, ntv[i, 3], UTCtime, ntv[i, 5], ntv[i, 6], ntv[i, 13], ntv[i, 10], ntv[i, 12], month, day, ctime[0:2], ctime[3:5], mjd)) else: fout.write( " {0:4.0f} {1:3.0f} {2:7.3f} {3:3.0f} {4:7.3f} {5:8.2f} {6:7.2f} {7:5.2f} {8:3.0f} {9:8.5f} {10:2.0f} {11:2.0f} {12:5s} {13:15.6f} \n" .format(year, doy, rh, ntv[i, 3], UTCtime, ntv[i, 5], ntv[i, 6], ntv[i, 13], ntv[i, 10], ntv[i, 12], month, day, ctime2, mjd)) fout.close()
def main(): # user inputs the observation file information parser = argparse.ArgumentParser() # required arguments parser.add_argument("station", help="station", type=str) parser.add_argument("year", help="year", type=int) parser.add_argument("doy", help="day of year", type=int) # these are the optional inputs parser.add_argument("-snr", type=int, default=66, help="snr ending - default is 66") parser.add_argument( "-fr", default=None, type=int, help="try -fr 1 for GPS L1 only, or -fr 101 for Glonass L1") parser.add_argument("-ampl", default=None, type=float, help="minimum spectral amplitude allowed") parser.add_argument("-e1", default=None, type=int, help="lower limit elevation angle (deg)") parser.add_argument("-e2", default=None, type=int, help="upper limit elevation angle (deg)") parser.add_argument("-h1", default=None, type=float, help="lower limit reflector height (m)") parser.add_argument("-h2", default=None, type=float, help="upper limit reflector height (m)") parser.add_argument("-sat", default=None, type=int, help="satellite") parser.add_argument("-peak2noise", default=None, type=float, help="Quality Control ratio") parser.add_argument("-fortran", default='True', type=str, help="Default is True: use Fortran translators") args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() # # rename the user inputs as variables # station = args.station year = args.year doy = args.doy if len(str(year)) != 4: print('Year must have four characters: ', year) sys.exit() # default value is 66 for now snr = args.snr exitS = g.check_inputs(station, year, doy, snr) if exitS: sys.exit() if args.fortran == 'True': fortran = True else: fortran = False # set some reasonable default values for LSP (Reflector Height calculation). # most of these can be overriden at the command line freqs = [1] # default is to do L1 pele = [5, 30] # polynomial fit limits h1 = 0.5 h2 = 6 # RH limits in meters - this is typical for a snow setup e1 = 5 e2 = 25 # elevation angle limits for estimating LSP # look at the four geographic quadrants to get started - these are azimuth angles azval = [0, 90, 90, 180, 180, 270, 270, 360] reqAmp = [7] # this is arbitrary - but often true for L1 obs twoDays = False # peak to noise value is one way of defining that significance (not the only way). # For snow and ice, 3.5 or greater, tides can be tricky if the water is rough (and thus # you might go below 3 a bit, say 2.5-2.7 PkNoise = 3.0 # if user inputs these, then it overrides the default if (args.e1 != None): e1 = args.e1 if (args.e2 != None): e2 = args.e2 if e1 < 5: print( 'have to change the polynomial limits because you went below 5 degrees' ) print('this restriction is for quickLook only ') pele[0] = e1 if (args.peak2noise != None): PkNoise = args.peak2noise if (args.h1 != None): h1 = args.h1 if (args.h2 != None): h2 = args.h2 if (args.sat != None): sat = args.sat else: sat = None # this is for when you want to run the code with just a single frequency, i.e. input at the console # rather than using the input restrictions if args.fr != None: freqs = [args.fr] if args.ampl != None: reqAmp[0] = args.ampl f = freqs[0] NReg = [h1, h2] # noise region - again, this is for typical snow setup quick.quickLook_function(station, year, doy, snr, f, e1, e2, h1, h2, reqAmp, pele, sat, PkNoise, fortran)
def quickLook_function(station, year, doy, snr_type,f,e1,e2,minH,maxH,reqAmp,pele,satsel,PkNoise,fortran): """ inputs: station name (4 char), year, day of year snr_type is the file extension (i.e. 99, 66 etc) f is frequency (1, 2, 5), etc e1 and e2 are the elevation angle limits in degrees for the LSP minH and maxH are the allowed LSP limits in meters reqAmp is LSP amplitude significance criterion pele is the elevation angle limits for the polynomial removal. units: degrees KL 20may10 pk2noise value is now sent from main function, which can be set online KL 20aug07 added fortran boolean """ # make sure environment variables exist g.check_environ_variables() if not os.path.isdir('logs'): subprocess.call(['mkdir', 'logs']) webapp = False # orbit directories ann = g.make_nav_dirs(year) # titles in 4 quadrants - for webApp titles = ['Northwest', 'Southwest','Northeast', 'Southeast'] # define where the axes are located bx = [0,1,0,1]; by = [0,0,1,1]; bz = [1,3,2,4] # various defaults - ones the user doesn't change in this quick Look code delTmax = 70 polyV = 4 # polynomial order for the direct signal desiredP = 0.01 # 1 cm precision ediff = 2 # this is a QC value, eliminates small arcs #four_in_one = True # put the plots together minNumPts = 20 #noise region for LSP QC. these are meters NReg = [minH, maxH] #print('Refl. Ht. Noise Region used: ', NReg) # for quickLook, we use the four geographic quadrants - these are azimuth angles in degrees azval = [270, 360, 180, 270, 0, 90, 90, 180] naz = int(len(azval)/2) # number of azimuth pairs pltname = 'temp.png' # default plot requireAmp = reqAmp[0] screenstats = True # to avoid having to do all the indenting over again # this allows snr file to live in main directory # not sure that that is all that useful as I never let that happen obsfile = g.define_quick_filename(station,year,doy,snr_type) if os.path.isfile(obsfile): print('>>>> The snr file exists ',obsfile) else: if True: #print('looking for the SNR file on disk') obsfile, obsfileCmp, snre = g.define_and_xz_snr(station,year,doy,snr_type) if snre: dkfjaklj = True #print('file exists on disk') else: print('>>>> The SNR the file does not exist ',obsfile) print('This code used to try and make one for you, but I have removed this option.') print('Please us rinex2snr and make a SNR file') sys.exit() #print('I will try to pick up a RINEX file ') #print('and translate it for you. This will be GPS only.') #print('For now I will check all the official archives for you.') #rate = 'low'; dec_rate = 0; archive = 'all'; #rinex.conv2snr(year, doy, station, int(snr_type), 'nav',rate,dec_rate,archive,fortran) #if os.path.isfile(obsfile): # print('the SNR file now exists') #else: # print('the RINEX file did not exist, had no SNR data, or failed to convert, so exiting.') allGood,sat,ele,azi,t,edot,s1,s2,s5,s6,s7,s8,snrE = read_snr_simple(obsfile) if allGood == 1: # make output file for the quickLook RRH values, just so you can give them a quick look see rhout = open('logs/rh.txt','w+') amax = 0 minEdataset = np.min(ele) print('minimum elevation angle (degrees) for this dataset: ', minEdataset) if minEdataset > (e1+0.5): print('It looks like the receiver had an elevation mask') e1 = minEdataset if webapp: fig = Figure(figsize=(10,6), dpi=120) axes = fig.subplots(2, 2) else: #plt.figure() # trying to help Kelly plt.figure(figsize=(10,6)) for a in range(naz): if not webapp: plt.subplot(2,2,bz[a]) plt.title(titles[a]) az1 = azval[(a*2)] ; az2 = azval[(a*2 + 1)] # this means no satellite list was given, so get them all if satsel == None: satlist = g.find_satlist(f,snrE) else: satlist = [satsel] for satNu in satlist: x,y,Nv,cf,UTCtime,avgAzim,avgEdot,Edot2,delT= g.window_data(s1,s2,s5,s6,s7,s8,sat,ele,azi,t,edot,f,az1,az2,e1,e2,satNu,polyV,pele,screenstats) if Nv > minNumPts: maxF, maxAmp, eminObs, emaxObs,riseSet,px,pz= g.strip_compute(x,y,cf,maxH,desiredP,polyV,minH) nij = pz[(px > NReg[0]) & (px < NReg[1])] Noise = 0 iAzim = int(avgAzim) if (len(nij) > 0): Noise = np.mean(nij) else: Noise = 1; iAzim = 0 # made up numbers if (delT < delTmax) & (eminObs < (e1 + ediff)) & (emaxObs > (e2 - ediff)) & (maxAmp > requireAmp) & (maxAmp/Noise > PkNoise): T = g.nicerTime(UTCtime) rhout.write('SUCCESS Azimuth {0:3.0f} RH {1:6.3f} m, Sat {2:3.0f} Freq {3:3.0f} Amp {4:4.1f} PkNoise {5:3.1f} UTC {6:5s} \n '.format( avgAzim,maxF,satNu,f,maxAmp,maxAmp/Noise,T)) if not webapp: plt.plot(px,pz,linewidth=1.5) else: axes[bx[a],by[a]].plot(px,pz,linewidth=2) axes[bx[a],by[a]].set_title(titles[a]) else: if not webapp: plt.plot(px,pz,'gray',linewidth=0.5) # i do not know how to add a grid using these version of matplotlib tt = 'GNSS-IR results: ' + station.upper() + ' Freq:' + str(f) + ' ' + str(year) + '/' + str(doy) aaa, bbb = plt.ylim() amax = max(amax, bbb) # do not know how to implement this ... if (a == 3) or (a==1): plt.xlabel('reflector height (m)') plt.suptitle(tt, fontsize=12) rhout.close() print('Reflector Height results are stored in a file called logs/rh.txt') if webapp: fig.savefig('temp.png', format="png") else: plt.show() else: print('some kind of problem with SNR file, so I am exiting the code politely.')
def main(): # make surer environment variables are set g.check_environ_variables() xdir = os.environ['REFL_CODE'] # must input start and end year parser = argparse.ArgumentParser() parser.add_argument("station", help="station name", type=str) parser.add_argument( "medfilter", help="Median filter for daily RH (m). Start with 0.25 ", type=float) parser.add_argument("ReqTracks", help="required number of tracks", type=int) # optional inputs: filename to output daily RH results parser.add_argument("-txtfile", default='None', type=str, help="output filename") parser.add_argument("-plt", default='None', type=str, help="plt to screen: True or False") parser.add_argument("-extension", default='None', type=str, help="extension for solution names") parser.add_argument("-year1", default='None', type=str, help="restrict to years starting with") parser.add_argument("-year2", default='None', type=str, help="restrict to years ending with") parser.add_argument("-fr", default=0, type=int, help="frequency, default is 1") args = parser.parse_args() # these are required station = args.station medfilter = args.medfilter ReqTracks = args.ReqTracks fr = args.fr # these are optional txtfile = args.txtfile # default is to show the plot if (args.plt == 'None') or (args.plt == 'True'): plt2screen = True else: plt2screen = False if args.extension == 'None': extension = '' else: extension = args.extension if args.year1 == 'None': year1 = 2005 else: year1 = int(args.year1) if args.year2 == 'None': year2 = 2021 else: year2 = int(args.year2) # where the summary files will be written to txtdir = xdir + '/Files' if not os.path.exists(txtdir): print('make an output directory', txtdir) os.makedirs(txtdir) # outliers limit, defined in meters howBig = medfilter k = 0 # added standard deviation 2020 feb 14, changed n=6 n = 7 # now require it as an input # you can change this - trying out 80 for now #ReqTracks = 80 # putting the results in a np.array, year, doy, RH, Nvalues, month, day tv = np.empty(shape=[0, n]) obstimes = [] medRH = [] meanRH = [] plt.figure() year_list = np.arange(year1, year2 + 1, 1) #print('Years to examine: ',year_list) print(fr) for yr in year_list: direc = xdir + '/' + str( yr) + '/results/' + station + '/' + extension + '/' if os.path.isdir(direc): all_files = os.listdir(direc) print('Number of files in ', yr, len(all_files)) for f in all_files: fname = direc + f L = len(f) # file names have 7 characters in them ... if (L == 7): # check that it is a file and not a directory and that it has something/anything in it try: a = np.loadtxt(fname, skiprows=3, comments='%').T numlines = len(a) if (len(a) > 0): y = a[0] + a[1] / 365.25 rh = a[2] doy = int(np.mean(a[1])) frequency = a[10] # change from doy to month and day in datetime d = datetime.date(yr, 1, 1) + datetime.timedelta(doy - 1) medv = np.median(rh) if fr == 0: cc = (rh < (medv + howBig)) & (rh > (medv - howBig)) else: cc = (rh < (medv + howBig)) & ( rh > (medv - howBig)) & (frequency == fr) good = rh[cc] goodT = y[cc] # only save if there are some minimal number of values if (len(good) > ReqTracks): rh = good obstimes.append( datetime.datetime(year=yr, month=d.month, day=d.day, hour=12, minute=0, second=0)) medRH = np.append(medRH, medv) plt.plot(goodT, good, '.') # store the meanRH after the outliers are removed using simple median filter meanRHtoday = np.mean(good) stdRHtoday = np.std(good) meanRH = np.append(meanRH, meanRHtoday) # add month and day just cause some people like that instead of doy # added standard deviation feb14, 2020 newl = [ yr, doy, meanRHtoday, len(rh), d.month, d.day, stdRHtoday ] tv = np.append(tv, [newl], axis=0) k += 1 else: print('not enough retrievals on ', yr, d.month, d.day, len(good)) except: print('problem reading ', fname, ' so skipping it') else: abc = 0 # dummy line #print('that directory does not exist - so skipping') plt.ylabel('Reflector Height (m)') plt.title('GNSS station: ' + station) plt.gca().invert_yaxis() plt.grid() if plt2screen: plt.show() fig, ax = plt.subplots() ax.plot(obstimes, meanRH, '.') fig.autofmt_xdate() plt.ylabel('Reflector Height (m)') today = str(date.today()) plt.title(station.upper() + ': Daily Mean Reflector Height, Computed ' + today) plt.grid() plt.gca().invert_yaxis() pltname = txtdir + '/' + station + '_RH.png' plt.savefig(pltname) #print('png file saved: ', pltname) # default is to show the plot if plt2screen: plt.show() if txtfile == 'None': print( 'no txt output file name has been provided, so no results are written' ) else: # sort the time tags ii = np.argsort(obstimes) # apply time tags to a new variable ntv = tv[ii, :] N, M = np.shape(ntv) outfile = txtdir + '/' + txtfile xxx = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) print('output file: ', outfile) fout = open(outfile, 'w+') # change comment value from # to % fout.write("{0:28s} \n".format('% calculated on ' + xxx)) fout.write("% year doy RH numval month day RH-sigma\n") fout.write("% year doy (m) (m)\n") fout.write("% (1) (2) (3) (4) (5) (6) (7)\n") for i in np.arange(0, N, 1): fout.write( " {0:4.0f} {1:3.0f} {2:7.3f} {3:3.0f} {4:4.0f} {5:4.0f} {6:7.3f} \n" .format(ntv[i, 0], ntv[i, 1], ntv[i, 2], ntv[i, 3], ntv[i, 4], ntv[i, 5], ntv[i, 6])) fout.close()
def main(): """ command line interface for download_rinex """ parser = argparse.ArgumentParser() parser.add_argument( "orbit", help="orbit center (gps,gnss,gps+glo, or specific centers) ", type=str) parser.add_argument("year", help="year", type=int) parser.add_argument("month", help="month (or day of year)", type=int) parser.add_argument("day", help="day (zero if you use day of year earlier)", type=int) args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() orbit_list = [ 'igs', 'igs', 'jax', 'grg', 'wum', 'gbm', 'nav', 'gps', 'gps+glo', 'gnss' ] # assign to normal variables pCtr = args.orbit year = args.year month = args.month day = args.day if len(str(year)) != 4: print('Year must have four characters: ', year) sys.exit() if (day == 0): # then you are using day of year as input doy = month year, month, day = g.ydoy2ymd(year, doy) else: doy, cdoy, cyyyy, cyy = g.ymd2doy(year, month, day) if pCtr not in orbit_list: print('You picked an orbit type - ', pCtr, ' - that I do not recognize') print(orbit_list) sys.exit() # if generic names used, we direct people to these orbit types if pCtr == 'gps': pCtr = 'nav' if pCtr == 'gnss': pCtr = 'gbm' if pCtr == 'gps+glo': pCtr = 'jax' if pCtr == 'nav': navname, navdir, foundit = g.getnavfile(year, month, day) if foundit: print('SUCCESS:', navname) else: filename, fdir, foundit = g.getsp3file_mgex(year, month, day, pCtr) if foundit: print('SUCCESS:', filename, fdir) else: print(filename, ' not found')
def main(): """ command line interface for download_rinex """ parser = argparse.ArgumentParser() parser.add_argument("station", help="station name", type=str) parser.add_argument("year", help="year", type=int) parser.add_argument("month", help="month (or day of year)", type=int) parser.add_argument("day", help="day (zero if you use day of year earlier)", type=int) # optional arguments parser.add_argument("-rate", default='low', metavar='low',type=str, help="sample rate: low or high") parser.add_argument("-archive", default=None, metavar='cddis',help="archive (unavco,sopac,cddis,sonel,nz,ga,ngs,bkg,nrcan)", type=str) parser.add_argument("-version", default=None, metavar=2,type=int, help="rinex version (2 or 3)") parser.add_argument("-doy_end", default=None, type=int, help="last day of year to be downloaded") args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() # assign to normal variables station = args.station year = args.year month = args.month day = args.day if len(str(year)) != 4: print('Year must have four characters: ', year) sys.exit() if (day == 0): # then you are using day of year as input doy = month year,month,day=g.ydoy2ymd(year, doy) else: doy,cdoy,cyyyy,cyy = g.ymd2doy(year,month,day) # default is low rate = args.rate # set archive variable archive = args.archive archive_list = ['sopac', 'unavco','sonel','cddis','nz','ga','bkg','jeff','ngs','nrcan'] archive_list_high = ['unavco','nrcan','ga'] if args.version == None: version = 2 else: version = args.version if args.doy_end == None: doy_end = doy else: doy_end = args.doy_end NS = len(station) if NS == 9: version = 3 # even if you don't choose version 3 .... # this is for version 2 if (version == 2) and (rate == 'low'): if (NS != 4): print('exiting: RINEX 2.11 station names must have 4 characters, lowercase please') sys.exit() if args.archive == None: archive = 'all' else: archive = args.archive.lower() if archive not in archive_list: print('You picked an archive that does not exist') print('I am going to check the main ones (unavco,sopac,sonel,cddis)') print('For future reference: I allow these archives:') print(archive_list) archive = 'all' #print('archive selected: ' , archive) # default archive wil be CDDIS for version 3 if (version == 3): if (args.archive == None): archive = 'cddis' #print('no archive was specified, so looking for it at CDDIS') else: archive = args.archive # print('data rate', rate) if (rate == 'high') and (version == 2): if args.archive == None: archive = 'unavco' else: archive = args.archive if archive not in archive_list_high: print('You picked an archive that is not supported by my code. Exiting') sys.exit() for d in range(doy, doy_end+1): #print('working on year, day of year:', year, d) if version == 3: version3(station,year,d,NS,archive) else: # RINEX VERSION 2 g.go_get_rinex_flex(station,year,d,0,rate,archive) rinexfile,rinexfiled = g.rinex_name(station, year, month, day) if os.path.isfile(rinexfile): print('SUCCESS: ', rinexfile)
def quickLook_function(station, year, doy, snr_type, f, e1, e2, minH, maxH, reqAmp, pele, satsel, PkNoise, fortran, pltscreen): """ inputs: station name (4 char), year, day of year snr_type is the file extension (i.e. 99, 66 etc) f is frequency (1, 2, 5), etc e1 and e2 are the elevation angle limits in degrees for the LSP minH and maxH are the allowed LSP limits in meters reqAmp is LSP amplitude significance criterion pele is the elevation angle limits for the polynomial removal. units: degrees KL 20may10 pk2noise value is now sent from main function, which can be set online KL 20aug07 added fortran boolean KL 21feb06 return data from the plots so that Jupyter notebooks can use them. also added pltscreen variable so that the default plots are not always displayed """ # return data to Jupyter Notebook people, good results nw = {} sw = {} ne = {} se = {} # failed periodograms failnw = {} failsw = {} failne = {} failse = {} list1 = {} # list of satellites in each quadrant list1['NW'] = [] list1['NE'] = [] list1['SW'] = [] list1['SE'] = [] list1['failNW'] = [] list1['failNE'] = [] list1['failSW'] = [] list1['failSE'] = [] # try the kelly way data = { 'NW': {}, 'SW': {}, 'NE': {}, 'SE': {}, 'fNW': {}, 'fSW': {}, 'fNE': {}, 'fSE': {} } # make sure environment variables exist g.check_environ_variables() if not os.path.isdir('logs'): subprocess.call(['mkdir', 'logs']) webapp = False # orbit directories ann = g.make_nav_dirs(year) # titles in 4 quadrants - for webApp titles = ['Northwest', 'Southwest', 'Northeast', 'Southeast'] stitles = ['NW', 'SW', 'NE', 'SE'] # define where the axes are located bx = [0, 1, 0, 1] by = [0, 0, 1, 1] bz = [1, 3, 2, 4] # various defaults - ones the user doesn't change in this quick Look code delTmax = 70 polyV = 4 # polynomial order for the direct signal desiredP = 0.01 # 1 cm precision ediff = 2 # this is a QC value, eliminates small arcs #four_in_one = True # put the plots together minNumPts = 20 #noise region for LSP QC. these are meters NReg = [minH, maxH] #print('Refl. Ht. Noise Region used: ', NReg) # for quickLook, we use the four geographic quadrants - these are azimuth angles in degrees azval = [270, 360, 180, 270, 0, 90, 90, 180] naz = int(len(azval) / 2) # number of azimuth pairs pltname = 'temp.png' # default plot requireAmp = reqAmp[0] screenstats = True # to avoid having to do all the indenting over again # this allows snr file to live in main directory # not sure that that is all that useful as I never let that happen obsfile = g.define_quick_filename(station, year, doy, snr_type) if os.path.isfile(obsfile): print('>>>> The snr file exists ', obsfile) else: if True: #print('looking for the SNR file on disk') obsfile, obsfileCmp, snre = g.define_and_xz_snr( station, year, doy, snr_type) if snre: dkfjaklj = True #print('file exists on disk') else: print('>>>> The SNR the file does not exist ', obsfile) print( 'This code used to try and make one for you, but I have removed this option.' ) print('Please us rinex2snr and make a SNR file') sys.exit() allGood, sat, ele, azi, t, edot, s1, s2, s5, s6, s7, s8, snrE = read_snr_simple( obsfile) if allGood == 1: # make output file for the quickLook RRH values, just so you can give them a quick look see rhout = open('logs/rh.txt', 'w+') amax = 0 minEdataset = np.min(ele) print('minimum elevation angle (degrees) for this dataset: ', minEdataset) if minEdataset > (e1 + 0.5): print('It looks like the receiver had an elevation mask') e1 = minEdataset if pltscreen: plt.figure(figsize=(10, 6)) for a in range(naz): if pltscreen: plt.subplot(2, 2, bz[a]) plt.title(titles[a]) az1 = azval[(a * 2)] az2 = azval[(a * 2 + 1)] # this means no satellite list was given, so get them all if satsel == None: satlist = g.find_satlist(f, snrE) else: satlist = [satsel] for satNu in satlist: x, y, Nv, cf, UTCtime, avgAzim, avgEdot, Edot2, delT = g.window_data( s1, s2, s5, s6, s7, s8, sat, ele, azi, t, edot, f, az1, az2, e1, e2, satNu, polyV, pele, screenstats) if Nv > minNumPts: maxF, maxAmp, eminObs, emaxObs, riseSet, px, pz = g.strip_compute( x, y, cf, maxH, desiredP, polyV, minH) nij = pz[(px > NReg[0]) & (px < NReg[1])] Noise = 0 iAzim = int(avgAzim) if (len(nij) > 0): Noise = np.mean(nij) else: Noise = 1 iAzim = 0 # made up numbers if (delT < delTmax) & (eminObs < (e1 + ediff)) & ( emaxObs > (e2 - ediff)) & (maxAmp > requireAmp) & (maxAmp / Noise > PkNoise): T = g.nicerTime(UTCtime) rhout.write( 'SUCCESS Azimuth {0:3.0f} RH {1:6.3f} m, Sat {2:3.0f} Freq {3:3.0f} Amp {4:4.1f} PkNoise {5:3.1f} UTC {6:5s} \n ' .format(avgAzim, maxF, satNu, f, maxAmp, maxAmp / Noise, T)) if pltscreen: plt.plot(px, pz, linewidth=1.5) if a == 0: nw[satNu] = [px, pz] list1['NW'].append(satNu) elif a == 1: sw[satNu] = [px, pz] list1['SW'].append(satNu) elif a == 2: ne[satNu] = [px, pz] list1['NE'].append(satNu) elif a == 3: se[satNu] = [px, pz] list1['SE'].append(satNu) idc = stitles[a] data[idc][satNu] = [px, pz] else: # these are failed tracks if pltscreen: plt.plot(px, pz, 'gray', linewidth=0.5) if a == 0: failnw[satNu] = [px, pz] list1['failNW'].append(satNu) elif a == 1: failsw[satNu] = [px, pz] list1['failSW'].append(satNu) elif a == 2: failne[satNu] = [px, pz] list1['failNE'].append(satNu) elif a == 3: failse[satNu] = [px, pz] list1['failSE'].append(satNu) idc = 'f' + stitles[a] data[idc][satNu] = [px, pz] # i do not know how to add a grid using these version of matplotlib tt = 'GNSS-IR results: ' + station.upper() + ' Freq:' + g.ftitle( f) + ' Year/DOY:' + str(year) + ',' + str(doy) if pltscreen: aaa, bbb = plt.ylim() amax = max(amax, bbb) # do not know how to implement this ... if (a == 3) or (a == 1): plt.xlabel('reflector height (m)') if (a == 1) or (a == 0): plt.ylabel('volts/volts') rhout.close() print( 'preliminary reflector height results are stored in a file called logs/rh.txt' ) # do not plot if sending data to Jupyter Notebooks if pltscreen: plt.suptitle(tt, fontsize=12) plt.show() else: print( 'some kind of problem with SNR file, so I am exiting the code politely.' ) return data
def main(): # # parser = argparse.ArgumentParser() parser.add_argument("station", help="station name", type=str) parser.add_argument("year", help="year", type=int) parser.add_argument("doy", help="start day of year", type=int) # optional arguments parser.add_argument("-snr", default=66, help="snr file ending", type=str) parser.add_argument( "-orb", default='nav', type=str, help= "orbit type, gps, gps+glo, gnss or you can specify nav,igs,igr,jax,gbm,grg,wum" ) parser.add_argument("-rate", default='low', metavar='low', type=str, help="sample rate: low or high, only unavco") parser.add_argument("-dec", default=0, type=int, help="decimate (seconds)") parser.add_argument( "-nolook", default='False', metavar='False', type=str, help="True means only use RINEX files on local machine") parser.add_argument("-fortran", default='True', metavar='True', type=str, help="True means use Fortran RINEX translators ") parser.add_argument( "-archive", default=None, metavar='all', help="archive (unavco,sopac,cddis,sonel,nz,ga,ngs,bkg,nrcan)", type=str) parser.add_argument("-doy_end", default=None, help="end day of year", type=int) parser.add_argument("-year_end", default=None, help="end year", type=int) parser.add_argument("-overwrite", default=None, help="boolean", type=str) args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() # # rename the user inputs as variables # station = args.station NS = len(station) if (NS == 4) or (NS == 9): #print('You have submitted a nominally valid station name') okok = 1 else: print( 'Illegal input - Station name must have 4 or 9 characters. Exiting.' ) sys.exit() year = args.year if len(str(year)) != 4: print('Year must be four characters long. Exiting.', year) sys.exit() if args.fortran == 'True': fortran = True else: fortran = False doy = args.doy isnr = args.snr # defined as an integer #snrt = args.snrEnd # #isnr = int(snrt) orb = args.orb # currently allowed orbit types - shanghai removed 2020sep08 orbit_list = [ 'gps', 'gps+glo', 'gnss', 'nav', 'igs', 'igr', 'jax', 'gbm', 'grg', 'wum' ] if orb not in orbit_list: print( 'You picked an orbit type I do not recognize. Here are the ones I allow' ) print(orbit_list) print('Exiting') sys.exit() # if you choose GPS, you get the nav message if orb == 'gps': orb = 'nav' # if you choose GNSS, you get the GFZ sp3 file if orb == 'gnss': orb = 'gbm' # if you choose GPS+GLO, you get the JAXA sp3 file if orb == 'gps+glo': orb = 'jax' # check that the fortran exe exist if fortran: if (orb == 'nav'): snrexe = g.gpsSNR_version() if not os.path.isfile(snrexe): print('You have selected the fortran and GPS only options.') print( 'However, the fortran translator gpsSNR.e has not been properly installed.' ) print('We are changing to the non-fortran option.') fortran = False else: snrexe = g.gnssSNR_version() if not os.path.isfile(snrexe): print('You have selected the fortran and GNSS options.') print( 'However, the fortran translator gnssSNR.e has not been properly installed.' ) print('We are changing to the non-fortran option.') fortran = False # if true ony use local RINEX files, which speeds up analysis of local datasets nolook = args.nolook if nolook == 'True': nol = True else: nol = False # default is set to low. pick high for 1sec files from unavco rate = args.rate if args.doy_end == None: doy2 = doy else: doy2 = args.doy_end # currently allowed archives archive_list = [ 'sopac', 'unavco', 'sonel', 'cddis', 'nz', 'ga', 'bkg', 'jeff', 'ngs', 'nrcan' ] if args.archive == None: archive = 'all' else: archive = args.archive.lower() if archive not in archive_list: print('You picked an archive that does not exist') print('For future reference: I allow these archives:') print(archive_list) print('Exiting') sys.exit() year1 = year if args.year_end == None: year2 = year else: year2 = args.year_end # decimation rate dec_rate = args.dec doy_list = list(range(doy, doy2 + 1)) year_list = list(range(year1, year2 + 1)) overwrite = False if (args.overwrite == 'True'): overwrite = True print('Feedback is written to files in the subdirectory logs/') rnx.run_rinex2snr(station, year_list, doy_list, isnr, orb, rate, dec_rate, archive, fortran, nol, overwrite)
def main(): # pick up the environment variable for where you are keeping your LSP data # print('=================================================================================') # print('===========================RUNNING GNSS IR ======================================') # print('=================================================================================') # # user inputs the observation file information parser = argparse.ArgumentParser() parser.add_argument("station", help="station", type=str) parser.add_argument("year", help="year", type=int) parser.add_argument("doy", help="doy", type=int) # optional inputs parser.add_argument("-snr", default=66,help="snr file ending, default is 66", type=int) parser.add_argument("-plt", default=None, help="plt to screen (True or False)", type=str) parser.add_argument("-fr", default=None, type=int, help="try -fr 1 for GPS L1 only, or -fr 101 for Glonass L1") parser.add_argument("-ampl", default=None, type=float, help="try -ampl 5-6 for minimum spectral amplitude") parser.add_argument("-sat", default=None, type=int, help="allow individual satellite") parser.add_argument("-doy_end", default=None, type=int, help="doy end") parser.add_argument("-year_end", default=None, type=int, help="year end") parser.add_argument("-azim1", default=None, type=int, help="lower limit azimuth") parser.add_argument("-azim2", default=None, type=int, help="upper limit azimuth") parser.add_argument("-nooverwrite", default=None, type=int, help="use any integer to not overwrite") parser.add_argument("-extension", default=None, type=str, help="extension for result file, useful for testing strategies") parser.add_argument("-compress", default=None, type=str, help="xz compress SNR files after use") parser.add_argument("-screenstats", default=None, type=str, help="some stats printed to screen(default is True)") parser.add_argument("-delTmax", default=None, type=int, help="Req satellite arc length (minutes)") parser.add_argument("-e1", default=None, type=str, help="override min elev angle") parser.add_argument("-e2", default=None, type=str, help="override max elev angle") parser.add_argument("-mmdd", default=None, type=str, help="boolean, add columns for month,day,hour,minute") args = parser.parse_args() # make sure environment variables exist. set to current directory if not g.check_environ_variables() # # rename the user inputs as variables # station = args.station year = int(args.year) doy= int(args.doy) # this is now optional snr_type = args.snr #snr_type = args.snrEnd if len(str(year)) != 4: print('Year must have four characters: ', year) sys.exit() if (doy > 366): print('doy cannot be larger than 366: ', year) sys.exit() # allow people to have an extension to the output file name so they can run different analysis strategies # this is undocumented and only for Kristine at the moment if args.extension == None: extension = '' else: extension = args.extension lsp = guts.read_json_file(station, extension) #print(lsp) # now check the overrides to the json instructions #print('plt argument', args.plt) if args.plt == 'True': lsp['plt_screen'] = True elif args.plt == 'False': lsp['plt_screen'] = False if (args.delTmax != None): lsp['delTmax'] = args.delTmax #print('Using user defined maximum satellite arc time (minutes) ', lsp['delTmax']) # though I would think not many people would do this ... if (args.compress != None): if args.compress == 'True': lsp['wantCompression'] = True else: lsp['wantCompression'] = False #print(lsp['screenstats'], 'screenstats from json') # do you override them? if args.screenstats == 'False': #print('No statistics will come to the screen') lsp['screenstats'] = False if args.screenstats == 'True': #print('Statistics will come to the screen') lsp['screenstats'] = True # in case you want to analyze multiple days of data if args.doy_end == None: doy_end = doy else: doy_end = int(args.doy_end) add_mmddhhss = False if args.mmdd == 'True': add_mmddhhss = True # in case you want to analyze multiple years of data if args.year_end == None: year_end = year else: year_end = int(args.year_end) # default will be to overwrite if args.nooverwrite == None: lsp['overwriteResults'] = True #print('LSP results will be overwritten') else: lsp['overwriteResults'] = False #print('LSP results will not be overwritten') if (args.e1 != None): #print('Overriding minimum elevation angle: ',args.e1) lsp['e1'] = float(args.e1) if (args.e2 != None): #print('Overriding maximum elevation angle: ',args.e2) lsp['e2'] = float(args.e2) # number of azimuth regions naz = int(len(lsp['azval'])/2) # in case you want to look at a restricted azimuth range from the command line setA = 0 if args.azim1 == None: azim1 = 0 else: setA = 1; azim1 = args.azim1 if args.azim2 == None: azim2 = 360 else: azim2 = args.azim2; setA = setA + 1 if (setA == 2): naz = 1; lsp['azval'] = [azim1, azim2] # this is for when you want to run the code with just a single frequency, i.e. input at the console # rather than using the input restrictions if args.fr != None: lsp['freqs'] = [args.fr] #print('Overriding frequency choices') if args.ampl != None: #print('Overriding amplitude choices') lsp['reqAmp'] = [args.ampl] if args.sat != None: #print('Overriding - only looking at a single satellite') lsp['onesat'] = [args.sat] lsp['mmdd'] = add_mmddhhss year_list = list(range(year, year_end+1)) doy_list = list(range(doy, doy_end+1)) for year in year_list: for doy in doy_list: # to make kelly happy :-) #print('--------------------------------------------------') #print('RESULTS gnssir for: ', station, year, doy) #print('--------------------------------------------------') guts.gnssir_guts(station,year,doy, snr_type, extension,lsp)
def main(): # user inputs the observation file information parser = argparse.ArgumentParser() # required arguments parser.add_argument("station", help="station (lowercase)", type=str) parser.add_argument("lat", help="latitude (degrees)", type=float) parser.add_argument("long", help="longitude (degrees)", type=float) parser.add_argument("height", help="ellipsoidal height (meters)", type=float) # these are the optional inputs parser.add_argument("-e1", default=None, type=int, help="lower limit elevation angle") parser.add_argument("-e2", default=None, type=int, help="upper limit elevation angle") parser.add_argument("-h1", default=None, type=float, help="lower limit reflector height (m)") parser.add_argument("-h2", default=None, type=float, help="upper limit reflector height (m)") parser.add_argument("-nr1", default=None, type=float, help="lower limit noise region for QC(m)") parser.add_argument("-nr2", default=None, type=float, help="upper limit noise region for QC(m)") parser.add_argument("-peak2noise", default=None, type=float, help="peak to noise ratio used for QC") parser.add_argument("-allfreq", default=None, type=str, help="set to True to include all GNSS") args = parser.parse_args() # # make sure environment variables exist g.check_environ_variables() # rename the user inputs into variables # station = args.station # location of the site - does not have to be very good. within 100 meters is fine Lat = args.lat Long = args.long Height = args.height # start the lsp dictionary lsp = {} lsp['station'] = station lsp['lat'] = Lat lsp['lon'] = Long lsp['ht'] = Height # reflector height (meters) if (args.h1 != None): h1 = args.h1 else: h1 = 0.5 if (args.h2 != None): h2 = args.h2 else: h2 = 6.0 # lsp['minH'] = h1 lsp['maxH'] = h2 # elevation angles (degrees) if (args.e1 != None): e1 = args.e1 else: e1 = 5 if (args.e2 != None): e2 = args.e2 else: e2 = 25 lsp['e1'] = e1 lsp['e2'] = e2 # the default noise region will the same as the RH exclusion area for now nr1 = h1 nr2 = h2 if (args.nr1 != None): nr1 = args.nr1 if (args.nr2 != None): nr2 = args.nr2 # lsp['NReg'] = [nr1, nr2] if (args.peak2noise == None): lsp['PkNoise'] = 2.7 # just a starting point for water - should be 3 or 3.5 for snow ... else: lsp['PkNoise'] = args.peak2noise # where the instructions will be written xdir = os.environ['REFL_CODE'] outputdir = xdir + '/input' if not os.path.isdir(outputdir): subprocess.call(['mkdir', outputdir]) outputfile = outputdir + '/' + station + '.json' lsp['polyV'] = 4 # polynomial order for DC removal lsp['pele'] = [5, 30] # elevation angles used for DC removal lsp['ediff'] = 2 # degrees lsp['desiredP'] = 0.005 # precision of RH in meters # azimuth regions in degrees (in pairs) # you can of course have more subdivisions here lsp['azval'] = [0, 90, 90, 180, 180, 270, 270, 360] # # frequencies to use - and their required amplitudes. The amplitudes are not set in stone # # added L5 as default october 13, 2020 if args.allfreq == None: # choose GPS as the default lsp['freqs'] = [1, 20, 5] lsp['reqAmp'] = [6, 6, 6] else: # 307 was making it crash. did not check as to why lsp['freqs'] = [1, 20, 5, 101, 102, 201, 205, 206, 207, 208, 302, 306] lsp['reqAmp'] = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] # use refraction correction lsp['refraction'] = True # write new RH results each time you run the code lsp['overwriteResults'] = True # if snr file does not exist, try to make one lsp['seekRinex'] = False # compress snr files after analysis - saves disk space lsp['wantCompression'] = False # periodogram plots come to the screen lsp['plt_screen'] = False # command line req to only do a single satellite - default is do all satellites lsp['onesat'] = None # send some information on periodogram RH retrievals to the screen lsp['screenstats'] = True # save the output plots lsp['pltname'] = station + '_lsp.png' # how long can the arc be, in minutes lsp['delTmax'] = 75 # - this is appropriate for 5-30 degrees print('writing out to:', outputfile) with open(outputfile, 'w+') as outfile: json.dump(lsp, outfile, indent=4)