def run(station, dt, rapid=True, prefixdir=""): """ PPP-processing with NRCan ppp. requires "gpsppp" binary """ print "------------------------------------" print "PPP-processing with NRCan ppp." original_dir = prefixdir dt_start = datetime.datetime.utcnow( ) # for timing how long processing takes year = dt.timetuple().tm_year doy = dt.timetuple().tm_yday rinex = station.get_rinex(dt) # this downloads RINEX over ftp, if needed # get GPS Products # nrcan ppp wants IGS products for two days. # if we process day N, we need products for N and N+1 clk_files = [] eph_files = [] erp_file = "" # we do not use the ERP files, for now. if not rapid: # Final products (clk1, eph1, erp1) = igs_ftp.get_CODE_final(dt, prefixdir) (clk2, eph2, erp2) = igs_ftp.get_CODE_final(dt + datetime.timedelta(days=1), prefixdir) clk_files = [clk1, clk2] eph_files = [eph1, eph2] erp_file = erp1 elif rapid: # Rapid products (clk1, eph1, erp1) = igs_ftp.get_CODE_rapid(dt, prefixdir) (clk2, eph2, erp2) = igs_ftp.get_CODE_rapid(dt + datetime.timedelta(days=1), prefixdir) clk_files = [clk1, clk2] eph_files = [eph1, eph2] erp_file = erp1 # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir(tempdir) ftp_tools.delete_files(tempdir) # empty the temp directory # us an existing cmd-file (doesn't change from run to run) cmdfile = prefixdir + "/gpsppp/1day.cmd" # write an INP file, corresponding to the keyboard-input required inp_file = nrcan_inp_file(tempdir + "run.inp", rinex, cmdfile, eph_files, clk_files, rapid) # write a DEF file nrcan_def_file(prefixdir, "gpsppp.def") # result will be stored in a POS file: (rinexdir, fn) = os.path.split(rinex) if fn[-3:] == ".gz": nrcan_pos_file = tempdir + fn[:-6] + "pos" else: nrcan_pos_file = tempdir + fn[:-5] + "pos" run_log = "" run_log += " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Program: %s\n" % gpsppp_version run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk_files # allow for multiple clk-files!? run_log += " EPH: %s\n" % eph_files run_log += " ERP: %s\n" % erp_file print run_log # move RINEX, CLK, EPH, ERP files to temp_dir files_to_move = [rinex, clk1, clk2, eph1, eph2, erp_file] moved_files = [] for f in files_to_move: shutil.copy2(f, tempdir) (tmp, fn) = os.path.split(f) moved_files.append(tempdir + fn) print moved_files # unzip zipped files. this may include the RINEX, CLK, EPH files. for f in moved_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd = '/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # rename the ERP file - becase the name is fixed to gpsppp.ERP in the DEF file. cmd = '/bin/mv' gpsppp_erp = prefixdir + "/temp/gpsppp.ERP" (tmp, fn) = os.path.split(erp_file) # [:-2] cmd = cmd + " " + tempdir + fn + " " + gpsppp_erp print "rename command: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name print "rinex= ", rinex (tmp, rinexfile) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == ".": # ends in a dot inputfile = inputfile[:-1] # strip off # if the RINEX file is hatanaka-compressed, uncompress it if inputfile[-1] == "d" or inputfile[-1] == "D": hata_file = moved_files[0] hata_file = hata_file[:-2] # strip off ".Z" if hata_file[-1] == ".": hata_file = hata_file[:-1] # stip off more cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # now gpsppp itself: os.chdir(tempdir) cmd = gpsppp_binary + " < " + inp_file p = subprocess.Popen(cmd, shell=True, cwd=tempdir) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end - dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds + delta.microseconds / 1.0e6) print run_log2 print "---------------------------------" # we may now do postprocessing and store the results. # the result is named RINEX.pos, for example "usn63440.pos" ppp_result = nrcan_parse_result(nrcan_pos_file, station, inputfile, bwd=True) result_file = ppp_common.write_result_file(ppp_result=ppp_result, preamble=run_log + run_log2, rapid=rapid, tag=gpsppp_tag, prefixdir=prefixdir) os.chdir(original_dir) # change back to original directory return result_file
def run(station, dt, rapid=True, prefixdir=""): """ PPP run using RTKLib rnx2rtkp """ original_dir = prefixdir dt_start = datetime.datetime.utcnow() doy = dt.timetuple().tm_yday rinex = station.get_rinex(dt) # doenload rinex file # GET NAV file navfile = igs_ftp.cddis_brdc_file(dt, prefixdir) # download IGS products (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir) # log input files, for writing to the result file run_log = " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % dt.year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk run_log += " EPH: %s\n" % eph run_log += " ERP: %s\n" % erp print run_log # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir(tempdir) ftp_tools.delete_files(tempdir) # empty the temp directory # copy files to tempdir files_to_copy = [rinex, clk, eph, eph, erp, navfile] copied_files = [] for f in files_to_copy: shutil.copy2(f, tempdir) (tmp, fn) = os.path.split(f) copied_files.append(tempdir + fn) # unzip zipped files, if needed for f in copied_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd = '/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # Hatanaka uncompress - if needed #rinexfile = copied_files[0] # the first file is the unzipped RINEX, in the temp dir if rinex[-3] == "d" or rinex[-3] == "D": hata_file = copied_files[0] hata_file = hata_file[:-2] # strip off ".Z" #print "hata ", hata_file cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name (tmp, rinexfile) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == "d" or rinex[-3] == "D": # if hatanaka compressed, we already uncompressed, so change to "O" inputfile = inputfile[:-1] + "O" # now ppp itself: os.chdir(tempdir) antfile = prefixdir + "/common/igs08.atx" outfile = tempdir + "out.txt" clk = copied_files[1] # RKLib wants eph files to be named sp3 # from CODE they end .CLK_R clk_new = clk[:-6] + ".clk" cmd = "cp " + clk + " " + clk_new #print cmd p = subprocess.Popen(cmd, shell=True) p.communicate() clk = clk_new print clk # RKLib wants eph files to be named sp3 # from CODE they end .CLK_R eph = copied_files[2] eph_new = eph[:-6] + ".sp3" cmd = "cp " + eph + " " + eph_new #print cmd p = subprocess.Popen(cmd, shell=True) p.communicate() eph = eph_new print eph navfile = copied_files[5] navfile = navfile[:-2] # strip off ".Z" inputfile = tempdir + inputfile print "input ", inputfile print "nav ", navfile print "clk ", clk print "eph ", eph cmd = rtklib_binary # must have this executable in path conf_file = prefixdir + "/common/rtklib_opts1.conf" options = [ " -k %s" % conf_file, #" -p 7", # mode 7:ppp-static #" -t", # lat/lon/height time output #" -u", # UTC time Don't use it, we get epochs of min:11 and min:41 instead of min:00 and min:00 #" -d %d" % 12, # number of decimals in time output " -o %s" % outfile, #" -m 10", # elevation mask #" -c", # combined forward/backward solutions #" -y 1", # state output #" -h", # fix and hold for integer ambiguity resolution [off] #" -f 2", # 2:L1+L2 #" -x 2", # debug level " %s" % eph, " %s" % clk, " %s" % inputfile, # RINEX file " %s" % navfile, # brdc NAV file #" %s" % (prefixdir + "/common/igs08.atx") ] for opt in options: cmd += opt p = subprocess.Popen(cmd, shell=True, cwd=tempdir) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end - dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds + delta.microseconds / 1.0e6) print run_log2 # here we may parse the output and store it to file somewhere ppp_result = parse_result(outfile, station) result_file = ppp_common.write_result_file(ppp_result=ppp_result, preamble=run_log + run_log2, rapid=rapid, tag=rtklib_tag, prefixdir=prefixdir) os.chdir(original_dir) # change back to original directory
def run(station, dt, rapid=True, prefixdir=""): """ PPP run using ESA gLAB """ print "ESA gLAB PPP-run" original_dir = prefixdir dt_start = datetime.datetime.utcnow() doy = dt.timetuple().tm_yday rinex = station.get_rinex(dt) # download rinex file print "getting IGS products:" # download IGS products (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir) print "IGS products done." print "-------------------" # log input files, for writing to the result file run_log = " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % dt.year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk run_log += " EPH: %s\n" % eph run_log += " ERP: %s\n" % erp print run_log print "-------------------" # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir(tempdir) ftp_tools.delete_files(tempdir) # empty the temp directory # copy files to tempdir files_to_copy = [rinex, clk, eph, eph, erp] copied_files = [] for f in files_to_copy: shutil.copy2(f, tempdir) (tmp, fn) = os.path.split(f) copied_files.append(tempdir + fn) # unzip zipped files, if needed for f in copied_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd = '/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # Hatanaka uncompress - if needed #rinexfile = copied_files[0] # the first file is the unzipped RINEX, in the temp dir if rinex[-3] == "d" or rinex[-3] == "D" or rinex[ -4] == "D": # can end .z, .Z, or .gz - so the "d" is in position -3 or -4 hata_file = copied_files[0] hata_file = hata_file[:-2] # strip off ".Z" if rinex[-4] == "D": hata_file = hata_file[:-1] # stip off more #print "hata ", hata_file cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name (tmp, rinexfile) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == ".": # ends in a dot inputfile = inputfile[:-1] # strip off if inputfile[-1] == "d" or inputfile[-1] == "D": # if hatanaka compressed, we already uncompressed, so change to "O" inputfile = inputfile[:-1] + "O" # now ppp itself: os.chdir(tempdir) antfile = prefixdir + "/common/igs08.atx" outfile = tempdir + "out.txt" eph = copied_files[2] clk = copied_files[1] inputfile = tempdir + inputfile print "inputfile for gLAB is: ", inputfile cmd = glab_binary # must have this executable in path # see doc/glab_options.txt options = [ " -input:obs %s" % inputfile, # RINEX observation file " -input:clk %s" % clk, " -input:orb %s" % eph, # SP3 Orbits " -input:ant %s" % antfile, # " -model:recphasecenter ANTEX", # " -model:recphasecenter no", " -model:trop", # correct for troposphere #" -model:iono FPPP", " -output:file %s" % outfile, " -pre:dec 30", # rinex data is at 30s intervals, don't decimate " -pre:elevation 10", # elevation mask " -pre:availf G12" # GPS frequencies L1 and L2 " -filter:trop", " -filter:backward", # runs filter both FWD and BWD " --print:input", # discard unnecessary output " --print:model", " --print:prefit", " --print:postfit", " --print:satellites" ] if station.antex: options.append(" -model:recphasecenter ANTEX") else: options.append( " -model:recphasecenter no" ) # USNO receiver antenna is not in igs08.atx (?should it be?) for opt in options: cmd += opt p = subprocess.Popen(cmd, shell=True, cwd=tempdir) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end - dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds + delta.microseconds / 1.0e6) print run_log2 print "-------------------" # here we may parse the output and store it to file somewhere ppp_result = glab_parse_result(outfile, station) ppp_common.write_result_file(ppp_result=ppp_result, preamble=run_log + run_log2, rapid=rapid, tag=glab_tag, prefixdir=prefixdir) os.chdir(original_dir)
def run(station, dt, rapid=True, prefixdir=""): """ PPP run using RTKLib rnx2rtkp """ print "------------------------------" print "PPP run using RTKLib rnx2rtkp" original_dir = prefixdir dt_start = datetime.datetime.utcnow() doy = dt.timetuple().tm_yday rinex = station.get_rinex( dt ) # doenload rinex file # GET NAV file navfile = igs_ftp.cddis_brdc_file(dt, prefixdir) # download IGS products (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir) # log input files, for writing to the result file run_log = " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % dt.year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk run_log += " EPH: %s\n" % eph run_log += " ERP: %s\n" % erp print run_log # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir( tempdir ) ftp_tools.delete_files(tempdir) # empty the temp directory # copy files to tempdir files_to_copy = [ rinex, clk, eph, eph, erp, navfile ] copied_files = [] for f in files_to_copy: shutil.copy2( f, tempdir ) (tmp,fn ) = os.path.split(f) copied_files.append( tempdir + fn ) # unzip zipped files, if needed for f in copied_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd ='/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # Hatanaka uncompress - if needed #rinexfile = copied_files[0] # the first file is the unzipped RINEX, in the temp dir if rinex[-3] == "d" or rinex[-3] == "D" or rinex[-4] == "D": hata_file = copied_files[0] hata_file = hata_file[:-2] # strip off ".Z" if hata_file[-1] == ".": hata_file = hata_file[:-1] # stip off more #print "hata ", hata_file cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name (tmp,rinexfile ) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == ".": # ends in a dot inputfile = inputfile[:-1] # strip off if inputfile[-1] == "d" or inputfile[-1] == "D": # if hatanaka compressed, we already uncompressed, so change to "O" inputfile = inputfile[:-1]+"O" # now ppp itself: os.chdir( tempdir ) antfile = prefixdir + "/common/igs08.atx" outfile = tempdir + "out.txt" clk = copied_files[1] # RKLib wants eph files to be named sp3 # from CODE they end .CLK_R clk_new = clk[:-6]+".clk" cmd = "cp "+clk + " " + clk_new #print cmd p = subprocess.Popen(cmd, shell=True) p.communicate() clk = clk_new print clk # RKLib wants eph files to be named sp3 # from CODE they end .CLK_R eph = copied_files[2] eph_new = eph[:-6]+".sp3" cmd = "cp "+eph + " " + eph_new #print cmd p = subprocess.Popen(cmd, shell=True) p.communicate() eph = eph_new print eph navfile = copied_files[5] navfile = navfile[:-2] # strip off ".Z" inputfile = tempdir+inputfile print "input ", inputfile print "nav ", navfile print "clk ", clk print "eph ", eph cmd = rtklib_binary # must have this executable in path conf_file = prefixdir + "/common/rtklib_opts1.conf" options = [ " -k %s"%conf_file, #" -p 7", # mode 7:ppp-static #" -t", # lat/lon/height time output #" -u", # UTC time Don't use it, we get epochs of min:11 and min:41 instead of min:00 and min:00 #" -d %d" % 12, # number of decimals in time output " -o %s" % outfile, #" -m 10", # elevation mask #" -c", # combined forward/backward solutions #" -y 1", # state output #" -h", # fix and hold for integer ambiguity resolution [off] #" -f 2", # 2:L1+L2 #" -x 2", # debug level " %s" % eph, " %s" % clk, " %s" % inputfile, # RINEX file " %s" % navfile, # brdc NAV file #" %s" % (prefixdir + "/common/igs08.atx") ] for opt in options: cmd += opt p = subprocess.Popen(cmd, shell=True, cwd = tempdir ) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end-dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds+delta.microseconds/1.0e6) print run_log2 # here we may parse the output and store it to file somewhere ppp_result = parse_result(outfile, station) result_file = ppp_common.write_result_file( ppp_result=ppp_result, preamble=run_log+run_log2, rapid=rapid, tag=rtklib_tag, prefixdir=prefixdir ) os.chdir(original_dir) # change back to original directory
def run(station, dt, rapid=True, prefixdir=""): """ PPP run using ESA gLAB """ print "ESA gLAB PPP-run" original_dir = prefixdir dt_start = datetime.datetime.utcnow() doy = dt.timetuple().tm_yday rinex = station.get_rinex( dt ) # download rinex file print "getting IGS products:" # download IGS products (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir) print "IGS products done." print "-------------------" # log input files, for writing to the result file run_log = " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % dt.year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk run_log += " EPH: %s\n" % eph run_log += " ERP: %s\n" % erp print run_log print "-------------------" # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir( tempdir ) ftp_tools.delete_files(tempdir) # empty the temp directory # copy files to tempdir files_to_copy = [ rinex, clk, eph, eph, erp ] copied_files = [] for f in files_to_copy: shutil.copy2( f, tempdir ) (tmp,fn ) = os.path.split(f) copied_files.append( tempdir + fn ) # unzip zipped files, if needed for f in copied_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd ='/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # Hatanaka uncompress - if needed #rinexfile = copied_files[0] # the first file is the unzipped RINEX, in the temp dir if rinex[-3] == "d" or rinex[-3] == "D" or rinex[-4] == "D": # can end .z, .Z, or .gz - so the "d" is in position -3 or -4 hata_file = copied_files[0] hata_file = hata_file[:-2] # strip off ".Z" if rinex[-4] == "D": hata_file = hata_file[:-1] # stip off more #print "hata ", hata_file cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name (tmp,rinexfile ) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == ".": # ends in a dot inputfile = inputfile[:-1] # strip off if inputfile[-1] == "d" or inputfile[-1] == "D": # if hatanaka compressed, we already uncompressed, so change to "O" inputfile = inputfile[:-1]+"O" # now ppp itself: os.chdir( tempdir ) antfile = prefixdir + "/common/igs08.atx" outfile = tempdir + "out.txt" eph = copied_files[2] clk = copied_files[1] inputfile = tempdir + inputfile print "inputfile for gLAB is: ",inputfile cmd = glab_binary # must have this executable in path # see doc/glab_options.txt options = [ " -input:obs %s" % inputfile, # RINEX observation file " -input:clk %s" % clk, " -input:orb %s" % eph, # SP3 Orbits " -input:ant %s" % antfile, # " -model:recphasecenter ANTEX", # " -model:recphasecenter no", " -model:trop", # correct for troposphere #" -model:iono FPPP", " -output:file %s" % outfile, " -pre:dec 30", # rinex data is at 30s intervals, don't decimate " -pre:elevation 10", # elevation mask " -pre:availf G12" # GPS frequencies L1 and L2 " -filter:trop", " -filter:backward", # runs filter both FWD and BWD " --print:input", # discard unnecessary output " --print:model", " --print:prefit", " --print:postfit", " --print:satellites" ] if station.antex: options.append(" -model:recphasecenter ANTEX") else: options.append(" -model:recphasecenter no") # USNO receiver antenna is not in igs08.atx (?should it be?) for opt in options: cmd += opt p = subprocess.Popen(cmd, shell=True, cwd = tempdir ) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end-dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds+delta.microseconds/1.0e6) print run_log2 print "-------------------" # here we may parse the output and store it to file somewhere ppp_result = glab_parse_result(outfile, station) ppp_common.write_result_file( ppp_result=ppp_result, preamble=run_log+run_log2, rapid=rapid, tag=glab_tag, prefixdir=prefixdir ) os.chdir(original_dir)
def run(station, dt, rapid=True, prefixdir=""): """ PPP-processing with NRCan ppp. requires "gpsppp" binary """ print "------------------------------------" print "PPP-processing with NRCan ppp." original_dir = prefixdir dt_start = datetime.datetime.utcnow() # for timing how long processing takes year = dt.timetuple().tm_year doy = dt.timetuple().tm_yday rinex = station.get_rinex( dt ) # this downloads RINEX over ftp, if needed # get GPS Products # nrcan ppp wants IGS products for two days. # if we process day N, we need products for N and N+1 clk_files =[] eph_files = [] erp_file = "" # we do not use the ERP files, for now. if not rapid: # Final products (clk1, eph1, erp1) = igs_ftp.get_CODE_final(dt, prefixdir) (clk2, eph2, erp2) = igs_ftp.get_CODE_final(dt+datetime.timedelta(days=1), prefixdir) clk_files = [ clk1, clk2 ] eph_files = [ eph1, eph2 ] erp_file = erp1 elif rapid: # Rapid products (clk1, eph1, erp1) = igs_ftp.get_CODE_rapid(dt, prefixdir) (clk2, eph2, erp2) = igs_ftp.get_CODE_rapid(dt+datetime.timedelta(days=1), prefixdir ) clk_files = [ clk1, clk2 ] eph_files = [ eph1, eph2 ] erp_file = erp1 # we do processing in a temp directory tempdir = prefixdir + "/temp/" ftp_tools.check_dir( tempdir ) ftp_tools.delete_files(tempdir) # empty the temp directory # us an existing cmd-file (doesn't change from run to run) cmdfile = prefixdir + "/gpsppp/1day.cmd" # write an INP file, corresponding to the keyboard-input required inp_file = nrcan_inp_file( tempdir + "run.inp", rinex, cmdfile, eph_files, clk_files, rapid ) # write a DEF file nrcan_def_file( prefixdir, "gpsppp.def") # result will be stored in a POS file: (rinexdir, fn ) = os.path.split(rinex) if fn[-3:] == ".gz": nrcan_pos_file = tempdir + fn[:-6] + "pos" else: nrcan_pos_file = tempdir + fn[:-5] + "pos" run_log = "" run_log += " run start: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_start.year, dt_start.month, dt_start.day, dt_start.hour, dt_start.minute, dt_start.second) run_log += " Program: %s\n" % gpsppp_version run_log += " Station: %s\n" % station.name run_log += " Year: %d\n" % year run_log += " DOY: %03d\n" % doy run_log += " date: %d-%02d-%02d\n" % (dt.year, dt.month, dt.day) run_log += " RINEX: %s\n" % rinex run_log += " CLK: %s\n" % clk_files # allow for multiple clk-files!? run_log += " EPH: %s\n" % eph_files run_log += " ERP: %s\n" % erp_file print run_log # move RINEX, CLK, EPH, ERP files to temp_dir files_to_move = [ rinex, clk1, clk2, eph1, eph2, erp_file ] moved_files = [] for f in files_to_move: shutil.copy2( f, tempdir ) (tmp,fn ) = os.path.split(f) moved_files.append( tempdir + fn ) print moved_files # unzip zipped files. this may include the RINEX, CLK, EPH files. for f in moved_files: if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file cmd ='/bin/gunzip' cmd = cmd + " -f " + f # -f overwrites existing file print "unzipping: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # rename the ERP file - becase the name is fixed to gpsppp.ERP in the DEF file. cmd ='/bin/mv' gpsppp_erp = prefixdir + "/temp/gpsppp.ERP" (tmp,fn ) = os.path.split(erp_file) # [:-2] cmd = cmd + " " + tempdir + fn + " " + gpsppp_erp print "rename command: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # figure out the rinex file name print "rinex= ", rinex (tmp,rinexfile ) = os.path.split(rinex) inputfile = rinexfile[:-2] # strip off ".Z" if inputfile[-1] == ".": # ends in a dot inputfile = inputfile[:-1] # strip off # if the RINEX file is hatanaka-compressed, uncompress it if inputfile[-1] == "d" or inputfile[-1] == "D": hata_file = moved_files[0] hata_file = hata_file[:-2] # strip off ".Z" if hata_file[-1] == ".": hata_file = hata_file[:-1] # stip off more cmd = "CRX2RNX " + hata_file print "Hatanaka uncompress: ", cmd p = subprocess.Popen(cmd, shell=True) p.communicate() # now gpsppp itself: os.chdir( tempdir ) cmd = gpsppp_binary + " < " + inp_file p = subprocess.Popen(cmd, shell=True, cwd = tempdir ) p.communicate() # wait for processing to finish dt_end = datetime.datetime.utcnow() delta = dt_end-dt_start run_log2 = " run end: %d-%02d-%02d %02d:%02d:%02d\n" % ( dt_end.year, dt_end.month, dt_end.day, dt_end.hour, dt_end.minute, dt_end.second) run_log2 += " elapsed: %.2f s\n" % (delta.seconds+delta.microseconds/1.0e6) print run_log2 print "---------------------------------" # we may now do postprocessing and store the results. # the result is named RINEX.pos, for example "usn63440.pos" ppp_result = nrcan_parse_result(nrcan_pos_file, station, inputfile, bwd=True) result_file = ppp_common.write_result_file( ppp_result=ppp_result, preamble=run_log+run_log2, rapid=rapid, tag=gpsppp_tag, prefixdir=prefixdir ) os.chdir(original_dir) # change back to original directory return result_file