Пример #1
0
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",
                        "--e1",
                        default=None,
                        type=int,
                        help="lower limit elevation angle")
    parser.add_argument("-e2",
                        "--e2",
                        default=None,
                        type=int,
                        help="upper limit elevation angle")
    parser.add_argument("-h1",
                        "--h1",
                        default=None,
                        type=float,
                        help="lower limit reflector height (m)")
    parser.add_argument("-h2",
                        "--h2",
                        default=None,
                        type=float,
                        help="upper limit reflector height (m)")
    parser.add_argument("-nr1",
                        "--nr1",
                        default=None,
                        type=float,
                        help="lower limit noise region for QC(m)")
    parser.add_argument("-nr2",
                        "--nr2",
                        default=None,
                        type=float,
                        help="upper limit noise region for QC(m)")
    parser.add_argument("-peak2noise",
                        "--peak2noise",
                        default=None,
                        type=float,
                        help="peak 2 noise ratio used for QC")
    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
    #
    lsp['freqs'] = [1, 20]
    lsp['reqAmp'] = [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)
Пример #2
0
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("doy1", help="start day of year", type=int)
    parser.add_argument("snrEnd", help="snr ending", type=str)
    parser.add_argument(
        "orbType",
        help="orbit type, nav or sp3 (igs,igr,gbm,jax,sha,wum,grg)",
        type=str)
    # optional arguments
    parser.add_argument("-rate",
                        default=None,
                        metavar='low',
                        type=str,
                        help="sample rate: low or high")
    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)",
                        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)

    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('nominally valid station name')
    else:
        print('Illegal input - Station must have 4 or 9 characters')
        sys.exit()
    year = args.year
    doy1 = args.doy1
    snrt = args.snrEnd  # string
    isnr = int(snrt)
    orbtype = args.orbType
    # currently allowed orbit types - sha removed 2020sep08
    orbit_list = ['nav', 'igs', 'igr', 'gbm', 'jax', 'grg', 'wum']
    if orbtype not in orbit_list:
        print(
            'You picked an orbit type I do not recognize. Here are the ones I allow'
        )
        print(orbit_list)
        sys.exit()

    if args.fortran == 'True':
        fortran = True
    else:
        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

    if args.rate == None:
        rate = 'low'
    else:
        rate = 'high'

    if args.doy_end == None:
        doy2 = doy1
    else:
        doy2 = args.doy_end

# currently allowed archives
    archive_list = [
        'sopac', 'unavco', 'sonel', 'cddis', 'nz', 'ga', 'bkg', 'jeff', 'ngs'
    ]
    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)

    year1 = year
    if args.year_end == None:
        year2 = year
    else:
        year2 = args.year_end


# decimation rate
    dec_rate = args.dec

    doy_list = list(range(doy1, doy2 + 1))
    year_list = list(range(year1, year2 + 1))

    # this sets up the loops
    rnx.run_rinex2snr(station, year_list, doy_list, isnr, orbtype, rate,
                      dec_rate, archive, fortran, nol)
Пример #3
0
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()

    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('noise region', 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('look for the SNR file elsewhere')
            obsfile, obsfileCmp, snre = g.define_and_xz_snr(
                station, year, doy, snr_type)
            if snre:
                print('file exists on disk')
            else:
                print('>>>> The SNR the file does not exist ', obsfile)
                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:
        amax = 0
        minEdataset = np.min(ele)
        print('min elevation angle 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()
        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)
                        print(
                            '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} '
                            .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)
        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.'
        )
Пример #4
0
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)
    parser.add_argument("snrEnd", help="snrEnding, try 99", type=int)
# these are the optional inputs
    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="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
    snr_type = args.snrEnd

    exitS = g.check_inputs(station,year,doy,snr_type)
    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 
    minH = 0.5; maxH = 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):
        minH  = args.h1
    if (args.h2 != None):
        maxH = 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 = [minH, maxH] # noise region - again, this is for typical snow setup
    quick.quickLook_function(station, year, doy, snr_type,f,e1,e2,minH,maxH,reqAmp,pele,sat,PkNoise,fortran)
Пример #5
0
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("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=None,
                        metavar='low',
                        type=str,
                        help="sample rate: low or high")
    parser.add_argument("-archive",
                        default=None,
                        metavar='all',
                        help="archive (unavco,sopac,cddis,sonel,nz,ga,ngs)",
                        type=str)
    parser.add_argument("-version",
                        default=None,
                        metavar=2,
                        type=int,
                        help="rinex version (2 or 3)")

    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 (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 args.rate == None:
        rate = 'low'
    else:
        rate = 'high'

    archive_list = [
        'sopac', 'unavco', 'sonel', 'cddis', 'nz', 'ga', 'bkg', 'jeff', 'ngs'
    ]

    if args.version == None:
        version = 2
    else:
        version = args.version

    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'

    NS = len(station)
    # RINEX version 3
    if version == 3:
        if NS == 9:
            srate = 30  # rate supported by CDDIS
            fexist = g.cddis3(station, year, doy, srate)
            if not fexist:
                # try again - unavco has 15 sec I believe
                srate = 15
                fexist = g.unavco3(station, year, doy, srate)
            if fexist:
                print('RINEX DOWNLOAD SUCCESSFUL')
        else:
            print('exiting: station names must have 9 characters')
    else:  # RINEX VERSION 2
        if NS == 4:
            g.go_get_rinex_flex(station, year, month, day, rate, archive)
        else:
            print(
                'exiting: station names must have 4 characters, lowercase please'
            )
Пример #6
0
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)
    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
            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}'
                                    .format(iAzim, satNu, maxF, maxAmp / Noise,
                                            maxAmp, f, T))
                            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()
Пример #7
0
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)
    parser.add_argument("snrEnd", help="snr file ending", type=int)

    # optional inputs
    parser.add_argument("-plt",
                        "--plt",
                        default=None,
                        help="ploting is boolean now. Default is True",
                        type=str)
    parser.add_argument(
        "-fr",
        "--fr",
        default=None,
        type=int,
        help="try -fr 1 for GPS L1 only, or -fr 101 for Glonass L1")
    parser.add_argument("-ampl",
                        "--ampl",
                        default=None,
                        type=float,
                        help="try -ampl 5-6 for minimum spectral amplitude")
    parser.add_argument("-sat",
                        "--sat",
                        default=None,
                        type=int,
                        help="allow individual satellite")
    parser.add_argument("-doy_end",
                        "--doy_end",
                        default=None,
                        type=int,
                        help="doy end")
    parser.add_argument("-year_end",
                        "--year_end",
                        default=None,
                        type=int,
                        help="year end")
    parser.add_argument("-azim1",
                        "--azim1",
                        default=None,
                        type=int,
                        help="lower limit azimuth")
    parser.add_argument("-azim2",
                        "--azim2",
                        default=None,
                        type=int,
                        help="upper limit azimuth")
    parser.add_argument("-nooverwrite",
                        "--nooverwrite",
                        default=None,
                        type=int,
                        help="use any integer to not overwrite")
    parser.add_argument(
        "-extension",
        "--extension",
        default=None,
        type=str,
        help="extension for result file, useful for testing strategies")
    parser.add_argument("-compress",
                        "--compress",
                        default=None,
                        type=str,
                        help="xz compress SNR files after use")
    parser.add_argument("-screenstats",
                        "--screenstats",
                        default=None,
                        type=str,
                        help="some stats printed to screen(default is True)")
    parser.add_argument("-delTmax",
                        "--delTmax",
                        default=None,
                        type=int,
                        help="Req satellite arc length (minutes)")
    parser.add_argument("-e1",
                        "--e1",
                        default=None,
                        type=str,
                        help="override min elev angle")
    parser.add_argument("-e2",
                        "--e2",
                        default=None,
                        type=str,
                        help="override max elev angle")

    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
    snr_type = args.snrEnd

    # get instructions first - this should be a standalone function
    instructions = str(os.environ['REFL_CODE']) + '/input/' + station + '.json'

    if os.path.isfile(instructions):
        with open(instructions) as f:
            lsp = json.load(f)
    else:
        print('Instruction file does not exist: ', instructions)
        print('Please make with make_json_input and run this code again.')
        sys.exit()

    # now check the overrides
    if (args.plt != None):
        if args.plt == 'True':
            lsp['plt_screen'] = True
        if args.plt == 'False':
            lsp['plt_screen'] = False
    else:
        lsp['plt_screen'] = True

    if lsp['plt_screen']:
        print('LSP plots will come to the screen')

    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

    if args.screenstats == 'False':
        print('no statistics will come to the screen')
        lsp['screenstats'] = False
    else:
        print('no 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 = args.doy_end

# in case you want to analyze multiple years of data
    if args.year_end == None:
        year_end = year
    else:
        year_end = args.year_end

# 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

# 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]

    print(lsp)

    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:
            guts.gnssir_guts(station, year, doy, snr_type, extension, lsp)