示例#1
0
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
示例#2
0
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
示例#3
0
def glab_run(station, dt, rapid=True, prefixdir=""):
    dt_start = datetime.datetime.utcnow()

    doy = dt.timetuple().tm_yday
    rinex = station.get_rinex( dt )

    (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir)

    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 ]
    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()

    # TODO: if the RINEX file is hatanaka-compressed, uncompress it
    # this requires the CRX2RNX binary
    """
    if rinexfile[-3] == "d" or rinexfile[-3] == "D":
        hata_file = moved_files[0]
        cmd = "CRX2RNX " + hata_file[:-2]
        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"

    # now ppp itself:
    os.chdir( tempdir )

    antfile = prefixdir + "/common/igs08.atx"
    outfile = tempdir + "out.txt"
    
    cmd =  glab_binary # must have this executable in path
    # see doc/glab_options.txt
    options = [ " -input:obs %s" % inputfile,
                " -input:clk %s" % clk,
                " -input:orb %s" % eph,
                " -input:ant %s" % antfile,
                " -model:recphasecenter no", # USNO receiver antenna is not in igs08.atx (?should it be?)
                " -output:file %s" % outfile,
                " -pre:dec 30", # rinex data is at 30s intervals, don't decimate
                " -pre:elevation 10", # elevation mask
                " --print:input", # discard unnecessary output
                " --print:model",
                " --print:prefit",
                " --print:postfit",
                " --print:satellites" ]

    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 = 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 )
示例#4
0
def run_ppp(rinexobs, rinexnav, rapid=True, prefixdir=os.getcwd(), coordtype=None, output=None):

    # Verilen Rinex observation dosyasindan day of year
    # bilgisini al ve doy degiskenine ata

    doy = int(os.path.splitext(os.path.basename(rinexobs))[0][4:-1])
    year = int(os.path.splitext(os.path.basename(rinexobs))[1][1:-1])+2000
    station = os.path.splitext(os.path.basename(rinexobs))[0][:4]

    # Rinex adindan elde edilen doy ve yil degerini datetime objesine donustur

    dt = datetime.datetime(year, 1, 1) +  datetime.timedelta(doy-1)

    # Bern universitesi aiub ftp adresinden,
    # EPH efemeris
    # ERP yer donme parametreleri
    # CLK Uydu saat bilgilerini al 

    (clk, eph, erp) = igs_ftp.get_CODE_rapid(dt, prefixdir)
    
    # ppp cozum program icin baslatma zamani
    dt_start = datetime.datetime.utcnow()
    # Cozum icin gerekli dosya bilgilerini goster

    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" % os.path.splitext(os.path.basename(rinexobs))[0][:4].upper()
    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" % rinexobs
    run_log += "       CLK: %s\n" % clk
    run_log += "       EPH: %s\n" % eph
    run_log += "       ERP: %s\n" % erp
    print(run_log)

    # RTKLIB icin DLL dosyalarini yukle
    print("Downloading Necessary DLL files\n\n")
    if os.path.isfile("libguide40.dll"):
        print("libguide40.dll already exists. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/libguide40.dll", "libguide40.dll")
    if os.path.isfile("libiconv-2.dll"):
        print("libiconv-2.dll already exists. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/libiconv-2.dll", "libiconv-2.dll")
    if os.path.isfile("libintl-2.dll"):
        print("libintl-2.dll already exists. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/libintl-2.dll", "libintl-2.dll")
    if os.path.isfile("mkl_def.dll"):
        print("mkl_def.dll already exits. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/mkl_def.dll", "mkl_def.dll")
    if os.path.isfile("mkl_lapack.dll"):
        print("mkl_lapack.dll already exits. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/mkl_lapack.dll", "mkl_lapack.dll")
    if os.path.isfile("mkl_p4p.dll"):
        print("mkl_p4p.dll already exits. skipping download.")
    else:
        urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/mkl_p4p.dll", "mkl_p4p.dll")

    # RTKLIB post-processing ppp icin gerekli CLI program yukle (RNX2RTKP)
    urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/rnx2rtkp.exe", prefixdir + "\\products\\CODE_rapid\\" + "rnx2rtkp.exe")

    # .Z compressed efemeris (EPH), clock (CLK) ve yer donme parametre (ERP) dosyalarini acmak ici
    # gzip yukle

    urllib.request.urlretrieve("https://github.com/tomojitakasu/RTKLIB_bin/raw/master/bin/gzip.exe", prefixdir + "\\products\\CODE_rapid\\" + "gzip.exe")


    # indirilen EPH, CLK ve ERP dosyalarini ac.
    # ve
    # rinex dosyalarini kopyala
    code_rapid_path = prefixdir + "\products\CODE_rapid"

    for f in os.listdir(prefixdir):
        if f.endswith(os.path.splitext(os.path.basename(rinexobs))[1]):
            shutil.copy2(f, code_rapid_path)
        elif f.endswith(os.path.splitext(os.path.basename(rinexnav))[1]):
            shutil.copy2(f, code_rapid_path)


    os.chdir(code_rapid_path)
    for f in os.listdir():
        if f.endswith(".Z"):
            subprocess.call("gzip.exe" +' -d '+ f)
        else:
            pass

    # IGS Alici anten bilgileri dosyasinin yolu
    atx_path = prefixdir + "/common/igs08.atx"
    # ppp
    for f in os.listdir(code_rapid_path):
        if f.endswith(".CLK"):
            clockfile = f
        elif f.endswith(".ERP"):
            erpfile = f
        elif f.endswith(".EPH"):
            ephfile = f
        else:
            pass
    if coordtype == 1:
        # Cikti koordinatlari enlem/boylam/elipsoidal yukseklik
        coordopt = " -a "
    elif coordtype == 2:
        # Cikti koordinatlari ECEF xyz
        coordopt = " -e "
    else:
        # Default olarak enlem/boylam
        coordopt = "  "

    if not output:
        subprocess.call("rnx2rtkp.exe" +' -p 7 ' + coordopt + " " + rinexobs + " " + rinexnav + " " + \
            ephfile + " " + clockfile + " " + erpfile + " " + atx_path )
    elif output:
        output = prefixdir + "\\" + output
        subprocess.call("rnx2rtkp.exe" +' -p 7 ' + coordopt + " " + rinexobs + " " + rinexnav + " " + \
            ephfile + " " + clockfile + " " + erpfile + " " + atx_path + " -o " + output)

    with open(output) as pppout:
        lines = pppout.readlines()
        if coordtype == 2:
            print("X-Coordinate (m):", lines[-1].split()[2])
            print("Y-Coordinate (m):", lines[-1].split()[3])
            print("Z-Coordinate (m):", lines[-1].split()[4])
        else:
            print("Latitude: ", lines[-1].split()[2])
            print("Longitue: ", lines[-1].split()[3])
            print("Ellipsoidal height: ", lines[-1].split()[4])
示例#5
0
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)
示例#6
0
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
示例#7
0
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)
示例#8
0
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