Exemplo n.º 1
0
def get_sp3_final_target(**kwargs):
    """ Final Orbit information in SP3 format from COD

      CODwwwwd.EPH.Z    CODE final GNSS orbits
      COXwwwwd.EPH.Z    CODE final GLONASS orbits (for GPS weeks
                        0990 to 1066)

      kwargs that matter:
      format='sp3' Optional but if given it must be sp3
      type='final' Optional but if given must be 'final'
      acid='cod' to get the GNSS solution, 'cox' to get GLONASS only solution.
        The latter (cox) are only available within the interval for GPS weeks
        0990 to 1066
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      Default values:
      kwargs['format'] = sp3
      kwargs['acid'] = cod
      kwargs['type'] = final

  """
    if 'format' in kwargs and kwargs['format'] not in ['sp3']:
        raise ArgumentError('[ERROR] code::get_sp3_final Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod', 'cox']:
        raise ArgumentError('[ERROR] code::get_sp3_final Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] != 'final':
        raise ArgumentError('[ERROR] code::get_sp3_final Invalid type', 'type',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'sp3'
    if 'type' not in kwargs:
        kwargs['type'] = 'final'
    if 'acid' not in kwargs:
        kwargs['acid'] = 'cod'

    pydt = _date(**kwargs)  ## this may throw
    week, sow = pydt2gps(pydt)
    acn = 'COD' if kwargs['acid'] == 'cod' else 'COX'
    sdate = '{:04d}{:01d}'.format(week, sow2dow(sow))
    frmt = 'EPH'
    url_dir = '{:}'.format(pydt.strftime('%Y'))

    eph = '{:}{:}.{:}.Z'.format(acn, sdate, frmt)
    target = '{:}/CODE/{:}/{:}'.format(CODE_URL, url_dir, eph)
    return target
Exemplo n.º 2
0
 def init_from_args(self, **kwargs):
     self.sta_name = kwargs['station'] if 'station' in kwargs else (' ' * 4)
     self.flag = kwargs['flag'] if 'flag' in kwargs else '1'
     self.old_name = kwargs['old_name'] if 'old_name' in kwargs else (' ' *
                                                                      4)
     self.start_date = kwargs['start'] if 'start' in kwargs else MIN_STA_DATE
     self.stop_date = kwargs['end'] if 'end' in kwargs else MAX_STA_DATE
     self.remark = kwargs['remark'] if 'remark' in kwargs else ''
     if len(self.sta_name) < 4:
         raise ArgumentError(
             '[ERROR] Type001Record::init_from_args Failed to parse station name',
             'station')
     if len(self.old_name) < 4:
         raise ArgumenttError(
             '[ERROR] Type001Record::init_from_args Failed to parse station old name',
             'old_name')
     try:
         self.flag = int(self.flag)
     except:
         raise ArgumentError(
             '[ERROR] Type001Record::init_from_args Failed to parse flag',
             'flag')
Exemplo n.º 3
0
def get_erp_final_target(**kwargs):
    """ Final Earth Rotation Parameters (ERP) files in from COD

      kwargs that matter:
      span='daily' for daily ERP's or 'weekly' for weekly ERP file
      code_dir='code' to download files from CODE_URL/CODE/yyyy or 'bswuser52' 
                to download from CODE_URL/BSWUSER52/ORB/yyyy
      acid='cod' Optional but if given must be cod
      type='final' Optional but if given must be 'final'
      format='bernese' Optional but if given must be 'bernese'
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      Default values:
      kwargs['span'] = daily

      CODwwww7.ERP.Z    Weekly CODE final ERP files as from week 0978 (*)
      CODyyddd.ERP.Z    Daily CODE final ERP files as from week 1706 (*)
      CODwwwwd.ERP.Z    CODE final ERPs belonging to the final orbits (+)
      CODwwww7.ERP.Z    Collection of the 7 daily COD-ERP solutions of the 
                        week (+)

      type=final
                        |span=daily                          | span=weekly                        |
      ------------------+------------------------------------+------------------------------------+
      code_dir=code     | /CODE/yyyy/CODwwwwd.ERP.Z          | /CODE/yyyy/CODwwww7.ERP.Z          |
      code_dir=bswuser52| /BSWUSER52/ORB/yyyy/CODyyddd.ERP.Z | /BSWUSER52/ORB/yyyy/CODwwww7.ERP.Z |


      (*) under /BSWUSER52/ORB/yyyy
      (+) under /CODE/yyyy

      I cannot find any difference between CODwwww7.ERP.Z Vs CODwwww7.ERP.Z,
      and CODyyddd.ERP.Z Vs CODwwwwd.ERP.Z. Hence, we add an optional argument
      'code_dir' which can take the values 'bswuser52' and 'code' and decides 
      which of the two options will be used (aka the remote ftp directory). By 
      default, the value defaults to code_dir=code

  """
    if 'format' in kwargs and kwargs['format'] not in ['bernese']:
        raise ArgumentError('[ERROR] code::get_erp_final Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod']:
        raise ArgumentError('[ERROR] code::get_erp_final Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] != 'final':
        raise ArgumentError('[ERROR] code::get_erp_final Invalid type', 'type',
                            **kwargs)
    if 'span' in kwargs and kwargs['span'] not in ['daily', 'weekly']:
        raise ArgumentError('[ERROR] code::get_erp_final Invalid span', 'span',
                            **kwargs)
    if 'code_dir' in kwargs and kwargs['code_dir'] not in [
            'bswuser52', 'code'
    ]:
        raise ArgumentError('[ERROR] code::get_erp_final Invalid code_dir',
                            'code_dir', **kwargs)

    if 'span' not in kwargs:
        kwargs['span'] = 'daily'
    if 'code_dir' not in kwargs:
        kwargs['code_dir'] = 'code'

    pydt = _date(**kwargs)  ## this may throw
    yy, ddd = pydt2yydoy(pydt)
    week, sow = pydt2gps(pydt)

    if kwargs['code_dir'] == 'code':
        url_dir = '{:}/{:}'.format('CODE', pydt.strftime('%Y'))
    else:
        url_dir = '{:}/{:}/{:}'.format('BSWUSER52', 'ORB', pydt.strftime('%Y'))

    acn = 'COD'
    frmt = 'ERP'
    if kwargs['span'] == 'weekly':
        sdate = '{:04d}{:1d}'.format(week, 7)
    else:
        if kwargs['code_dir'] == 'code':
            sdate = '{:04d}{:01d}'.format(week, sow2dow(sow))
        else:
            sdate = '{:02d}{:03d}'.format(yy, ddd)

    erp = '{:}{:}.{:}.Z'.format(acn, sdate, frmt)
    target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, erp)
    return target
Exemplo n.º 4
0
def get_erp(**kwargs):
    """
      kwargs that matter:
      format Optional but if it exists it must be 'bernese'
      acid Optional but if it exists it must be 'cod'
      span='daily' or 'weekly'; note however that only final products have
          weekly erp products
      type='final', rapid, prediction, .... (see Table)
      save_as: '/some/path/foo.ION' Rename downloaded file to this filename
      save_dir: 'foo/bar' Directory to save remote file; if both save_dir and 
          save_as are given, then the local file will be the concatenation
          of these two, aka os.path.join(save_dir, save_as)
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...
      A datetime is only optional if type=='current'

      Default values:
      kwargs['format'] = bernese
      kwargs['acid'] = cod
      kwargs['type'] = final
      kwargs['span'] = daily

      type=final
                        |span=daily                          | span=weekly                        |
      ------------------+------------------------------------+------------------------------------+
      code_dir=code     | /CODE/yyyy/CODwwwwd.ERP.Z          | /CODE/yyyy/CODwwww7.ERP.Z          |
      code_dir=bswuser52| /BSWUSER52/ORB/yyyy/CODyyddd.ERP.Z | /BSWUSER52/ORB/yyyy/CODwwww7.ERP.Z |
      
      type=current               | COD.ERP_U
      type=urapid or ultra-rapid | CODwwwwd.ERP_U
      type=frapid or final-rapid | CODwwwwd.ERP_M or CODwwwwd.ERP_M.Z
      type=erapid or early-rapid | CODwwwwd.ERP_R
      type=prediction            | CODwwwwd.ERP_P
      type=p2                    | CODwwwwd.ERP_P2
      type=p5                    | CODwwwwd.ERP_5D


      (*) under /BSWUSER52/ORB/yyyy
      (+) under /CODE/yyyy
  """
    """ redundant checks
    if 'span' in kwargs and kwargs['span'] not in ['daily', 'weekly']:
        raise ArgumentError('[ERROR] code::get_erp Invalid span', 'span',
                            **kwargs)
    """
    if 'span' not in kwargs:
        kwargs['span'] = 'daily'
    if kwargs['span'] == 'weekly' and kwargs['type'] != 'final':
        msg = '[ERROR] codeerp::get_erp Invalid span: {:} for non-final product: {:}'.format(
            kwargs['span'], kwargs['type'])
        raise RuntimeError(msg)

    if 'type' in kwargs and kwargs['type'] in [
            'urapid', 'ultra-rapid', 'frapid', 'final-rapid', 'erapid',
            'early-rapid', 'prediction', 'p2', 'p5', 'current'
    ]:
        target = get_erp_rapid_target(**kwargs)
    elif 'type' not in kwargs or 'type' in kwargs and kwargs['type'] == 'final':
        target = get_erp_final_target(**kwargs)
    else:
        raise ArgumentError('[ERROR] code::get_erp Invalid type', 'type',
                            **kwargs)

    indct = {}
    if 'save_as' in kwargs:
        indct['save_as'] = kwargs['save_as']
    if 'save_dir' in kwargs:
        indct['save_dir'] = kwargs['save_dir']
    status, remote, local = web_retrieve(target, **indct)
    return status, remote, local
Exemplo n.º 5
0
def get_erp_rapid_target(**kwargs):
    """ Rapid , Ultra-Rapid and Predicted Final Earth Rotation Parameters (ERP) 
      files in from COD
        
      kwargs that matter:
      acid='cod' Optional but if given must be cod
      format='bernese' Optional but if given must be 'bernese'
      span='daily' Optional but if given must be 'daily'
      type=[...] If not given, default value is 'frapid'
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...
      A datetime is only optional if type=='current'

      CODwwwwd.ERP_M.Z  CODE final rapid ERPs belonging to the final rapid 
                          orbits (-)
      COD.ERP_U         CODE ultra-rapid ERPs belonging to the ultra-rapid 
                          orbit product
      CODwwwwd.ERP_U    CODE ultra-rapid ERPs belonging to the ultra-rapid 
                          orbits
      CODwwwwd.ERP_M    CODE final rapid ERPs belonging to the final rapid 
                          orbits
      CODwwwwd.ERP_R    CODE early rapid ERPs belonging to the early rapid 
                          orbits
      CODwwwwd.ERP_P    CODE predicted ERPs belonging to the predicted
                          24-hour orbits
      CODwwwwd.ERP_P2   CODE predicted ERPs belonging to the predicted
                          48-hour orbits
      CODwwwwd.ERP_5D   CODE predicted ERPs belonging to the predicted
                          5-day orbits

      (-) under /CODE/yyyy_M

      type=current               | COD.ERP_U
      type=urapid or ultra-rapid | CODwwwwd.ERP_U
      type=frapid or final-rapid | CODwwwwd.ERP_M [or CODwwwwd.ERP_M.Z]
      type=erapid or early-rapid | CODwwwwd.ERP_R
      type=prediction            | CODwwwwd.ERP_P
      type=p2                    | CODwwwwd.ERP_P2
      type=p5                    | CODwwwwd.ERP_5D

      files in brackets not available!
  """
    if 'format' in kwargs and kwargs['format'] not in ['bernese']:
        raise ArgumentError('[ERROR] code::get_erp_rapid Invalid format',
                            'format', **kwargs)
    if 'span' in kwargs and kwargs['span'] not in ['daily']:
        raise ArgumentError('[ERROR] code::get_erp_rapid Invalid span', 'span',
                            **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod']:
        raise ArgumentError('[ERROR] code::get_erp_rapid Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] not in [
            'urapid', 'ultra-rapid', 'frapid', 'final-rapid', 'erapid',
            'early-rapid', 'prediction', 'p2', 'p5', 'current'
    ]:
        raise ArgumentError('[ERROR] code::get_erp_rapid Invalid type', 'type',
                            **kwargs)

    if 'type' not in kwargs:
        kwargs['type'] = 'frapid'

    if kwargs['type'] != 'frapid':
        pydt = _date(**kwargs)  ## this may throw
        week, sow = pydt2gps(pydt)
        sdate = '{:04d}{:01d}'.format(week, sow2dow(sow))
    acn = 'COD'
    url_dir = 'CODE'

    if kwargs['type'] in ['urapid', 'ultra-rapid']:
        frmt = 'ERP_U'
    elif kwargs['type'] in ['frapid', 'final-rapid']:
        frmt = 'ERP_M'
    elif kwargs['type'] in ['erapid', 'early-rapid']:
        frmt = 'ERP_R'
    elif kwargs['type'] in ['prediction']:
        frmt = 'ERP_P'
    elif kwargs['type'] in ['p2']:
        frmt = 'ERP_P2'
    elif kwargs['type'] in ['p5']:
        frmt = 'ERP_5D'
    elif kwargs['type'] in ['current']:
        sdate = ''
        frmt = 'ERP_U'

    erp = '{:}{:}.{:}'.format(acn, sdate, frmt)
    target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, erp)
    return target
Exemplo n.º 6
0
def get_trp_rapid_target(**kwargs):
    """ Rapid or Ultra-rapid tropospheric information in SINEX or Bernese format 
      from COD
  
        COD.TRO_U         CODE ultra-rapid troposphere product in SINEX
                          format
        COD_TRO.SNX_U.Z   CODE ultra-rapid solution, as above but with 
                          troposphere parameters for selected sites, SINEX 
                          format
        CODwwwwd.TRO_R    CODE troposphere product from the early rapid
                          solution, SINEX format
        ________Unused________________________________________________________
        COD_TRO.SNX_U.Z   CODE ultra-rapid solution, as above but with 
                          troposphere parameters for selected sites, SINEX 
                          format
        CODwwwwd_TRO.SNX_R.Z  CODE early rapid solution, as above but with 
                          troposphere parameters for selected sites, SINEX 
                          format

      Default Values
      kwargs['format'] = 'sinex'
      kwargs['type'] = 'rapid'
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      aka:
      kwargs           |format=sinex        | format=bernese      |
      -----------------+--------------------+---------------------+
      type=rapid       | CODwwwwd.TRO_R     |                     |
      type=urapid      | COD.TRO_U          |                     |
      type=urapid-sites| COD_TRO.SNX_U.Z    |                     |

  """
    if 'format' in kwargs and kwargs['format'] not in ['sinex', 'tro']:
        raise ArgumentError('[ERROR] code::get_trp_rapid Invalid format',
                            'format', **kwargs)
    if 'type' in kwargs and kwargs['type'] not in [
            'rapid', 'urapid', 'urapid-sites'
    ]:
        raise ArgumentError('[ERROR] code::get_trp_rapid Invalid type', 'type',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'sinex'
    if 'type' not in kwargs:
        kwargs['type'] = 'rapid'

    if kwargs['type'] == 'rapid':
        yy, ddd = _pydt2yydoy(pydt)

    if kwargs['format'] in ['sinex', 'tro']:
        acn = 'COD'
        if kwargs['type'] == 'rapid':
            week, sow = pydt2gps(pydt)
            sdate = '{:04d}{:1d}'.format(week, sow2dow(sow))
            frmt = 'TRO_R'
        elif kwargs['type'] == 'urapid':
            sdate = ''
            frmt = 'TRO_U'
        elif kwargs['type'] == 'urapid-sites':
            sdate = '_TRO'
            frmt = 'SNX_U.Z'
        else:
            raise RuntimeError(
                '[ERROR] code::get_trp_rapid invalid request (#1)')
    else:
        raise RuntimeError('[ERROR] code::get_ion_rapid invalid request (#2)')

    tro = '{:}{:}.{:}'.format(acn, sdate, frmt)
    target = '{:}/CODE/{:}'.format(CODE_URL, tro)
    return target
Exemplo n.º 7
0
def get_trp_final_target(**kwargs):
    """ Final tropospheric information in SINEX or Bernese format from COD

      CODwwwwd.TRO.Z  CODE final troposphere product, SINEX format
      CODyyddd.TRP.Z  Troposphere path delays of final solution
      COEyyddd.TRP.Z  Troposphere path delays of EUREF solution

      kwargs that matter:
      format='sinex' or format='tro' to get the Tropospheric SINEX format.
      format='trp' or format='bernese' to get the Bernese format.
      acid='coe' to get the EUREF solution.
      type='final' Optional but if given must be 'final'
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      Default values:
      kwargs['format'] = bernese
      kwargs['acid'] = cod

      kwargs  | format=bernese                   | format=sinex
      --------+----------------------------------+----------------------------
      acid=coe|BSWUSER52/ATM/yyyy/COEyyddd.TRP.Z |
      acid=cod|BSWUSER52/ATM/yyyy/CODyyddd.TRP.Z |CODE/yyyy/CODwwwwd.TRO.Z
  """
    if 'format' in kwargs and kwargs['format'] not in [
            'sinex', 'tro', 'trp', 'bernese'
    ]:
        raise ArgumentError('[ERROR] code::get_trp_final Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod', 'coe']:
        raise ArgumentError('[ERROR] code::get_trp_final Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] != 'final':
        raise ArgumentError('[ERROR] code::get_trp_final Invalid type', 'type',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'bernese'
    if 'acid' not in kwargs:
        kwargs['acid'] = 'cod'

    frmt = 'TRP' if kwargs['format'] in ['bernese', 'trp'] else 'TRO'

    pydt = _date(**kwargs)  ## this may throw
    yy, ddd = _pydt2yydoy(pydt)
    if kwargs['acid'] == 'coe':
        if kwargs['format'] in ['sinex', 'tro']:
            msg = '[ERROR] code::get_trp_final No product in SINEX format for EUREF solution'
            raise RuntimeError(msg)
        url_dir = 'BSWUSER52/ATM/{:}'.format(pydt.strftime("%Y"))
        acn = 'COE'
        sdate = '{:02d}{:03d}'.format(yy, ddd)
    else:
        acn = 'COD'
        if kwargs['format'] in ['bernese', 'ion']:
            url_dir = 'BSWUSER52/ATM/{:}'.format(pydt.strftime("%Y"))
            sdate = '{:02d}{:03d}'.format(yy, ddd)
        else:
            url_dir = 'CODE/{:}'.format(pydt.strftime("%Y"))
            week, sow = pydt2gps(pydt)
            sdate = '{:04d}{:1d}'.format(week, sow2dow(sow))

    tro = '{:}{:}.{:}.Z'.format(acn, sdate, frmt)
    target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, tro)
    return target
Exemplo n.º 8
0
def get_dcb_final_target(**kwargs):
    """ Final Differential Code Bias (DCB) in DCB format from COD

      *type=final
        span=daily, obs=p1p2             | BSWUSER52/ORB/yyyy/CODyyddd.DCB.Z
        span=monthly, obs=p1c1           | CODE/yyyy/P1C1yymm.DCB.Z
        span=monthly, obs=p1p2           | CODE/yyyy/P1P2yymm.DCB.Z
        span=monthly, obs=p1p2all        | CODE/yyyy/P1P2yymm_ALL.DCB.Z
        span=monthly, obs=p1c1rnx        | CODE/yyyy/P1C1yymm_RINEX.DCB
        span=monthly, obs=p2c2rnx        | CODE/yyyy/P2C2yymm_RINEX.DCB

      kwargs that matter:
      format='dcb' Optional but if given it must be dcb
      type='final' Optional but if given must be 'final'
      acid='cod' Optional but if it exists it must be 'cod'
      span= daily or monthly
      obs= Choose from above table
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      Default values:
      kwargs['format'] = dcb
      kwargs['acid'] = cod
      kwargs['type'] = final
      kwargs['span'] = monthly
      kwargs['obs'] = p1c1

  """
    if 'format' in kwargs and kwargs['format'] not in ['dcb']:
        raise ArgumentError('[ERROR] code::get_dcb_final Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod']:
        raise ArgumentError('[ERROR] code::get_dcb_final Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] != 'final':
        raise ArgumentError('[ERROR] code::get_dcb_final Invalid type', 'type',
                            **kwargs)
    if 'span' in kwargs and kwargs['span'] not in ['monthly', 'daily']:
        raise ArgumentError('[ERROR] code::get_dcb_final Invalid span', 'span',
                            **kwargs)
    if 'obs' in kwargs and kwargs['obs'] not in [
            'p1p2', 'p1c1', 'p1p2all', 'p1c1rnx', 'p2c2rnx'
    ]:
        raise ArgumentError('[ERROR] code::get_dcb_final Invalid obs', 'obs',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'dcb'
    if 'type' not in kwargs:
        kwargs['type'] = 'final'
    if 'acid' not in kwargs:
        kwargs['acid'] = 'cod'
    if 'span' not in kwargs:
        kwargs['span'] = 'monthly'
    if 'obs' not in kwargs:
        kwargs['obs'] = 'p1c1'

    pydt = _date(**kwargs)  ## this may throw
    yy, ddd = pydt2yydoy(pydt)
    mm, yyyy = pydt.strftime('%m'), pydt.strftime('%Y')

    spec = ''
    if kwargs['span'] == 'daily' and kwargs['obs'] == 'p1p2':
        acn = 'COD'
        sdate = '{:02d}{:03d}'.format(yy, ddd)
        url_dir = 'BSWUSER52/ORB/{:}'.format(yyyy)
        frmt = 'DCB.Z'
    elif kwargs['span'] == 'monthly':
        sdate = '{:02d}{:}'.format(yy, mm)
        url_dir = 'CODE/{:}'.format(yyyy)
        if kwargs['obs'] == 'p1c1':
            acn = 'P1C1'
            frmt = 'DCB.Z'
        elif kwargs['obs'] == 'p1p2':
            acn = 'P1P2'
            frmt = 'DCB.Z'
        elif kwargs['obs'] == 'p1p2all':
            acn = 'P1P2'
            spec = '_ALL'
            frmt = 'DCB.Z'
        elif kwargs['obs'] == 'p1c1rnx':
            acn = 'P1C1'
            spec = '_RINEX'
            frmt = 'DCB.Z'
        elif kwargs['obs'] == 'p2c2rnx':
            acn = 'P2C2'
            spec = '_RINEX'
            frmt = 'DCB.Z'
    try:
        dcb = '{:}{:}{:}.{:}'.format(acn, sdate, spec, frmt)
        target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, dcb)
    except:
        msg = '[ERROR] code::get_dcb_final Failed to formulate DCB file'
        raise RuntimeError(msg)
    return target
Exemplo n.º 9
0
def get_dcb_rapid_target(**kwargs):
    """ Rapid and Ultra-Rapid Differential Code Bias (DCB) in DCB format from 
      COD

       [1] type=rapid, span=daily, obs=p1p2        | BSWUSER52/ORB/yyyy/CORyyddd.DCB.Z
       [2] type=current, span=monthly, obs=p1c1    | P1C1.DCB (GPS sats only)
       [3] type=current, span=monthly, obs=p1p2    | P1P2.DCB
       [4] type=current, span=monthly, obs=p1p2all | P1P2_ALL.DCB
       [5] type=current, span=monthly, obs=p1p2gps | P1P2_GPS.DCB
       [6] type=current, span=monthly, obs=p1c1rnx | P1C1_RINEX.DCB
       [7] type=current, span=monthly, obs=p2c2rnx | P1C2_RINEX.DCB
       [8] type=current, span=monthly, obs=p1p2p1c1| CODE.DCB (merged [2] and [3])
       [9] type=current, span=monthly, obs=full    | CODE_FULL.DCB (merged [2], [3], [6] and [7])

      kwargs that matter:
      format='dcb' Optional but if given it must be dcb
      type=rapid or current; See table above
      acid='cod' Optional but if it exists it must be 'cod'
      span= daily or monthly
      obs= Choose from above table
      To provide a date if needed, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...
      A date is needed only in case [1]

      Default values:
      kwargs['format'] = dcb
      kwargs['acid'] = cod
      kwargs['type'] = current
      kwargs['span'] = monthly
      kwargs['obs'] = full

  """
    if 'format' in kwargs and kwargs['format'] not in ['dcb']:
        raise ArgumentError('[ERROR] code::get_dcb_rapid Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod']:
        raise ArgumentError('[ERROR] code::get_dcb_rapid Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] not in ['rapid', 'current']:
        raise ArgumentError('[ERROR] code::get_dcb_rapid Invalid type', 'type',
                            **kwargs)
    if 'span' in kwargs and kwargs['span'] not in ['monthly', 'daily']:
        raise ArgumentError('[ERROR] code::get_dcb_rapid Invalid span', 'span',
                            **kwargs)
    if 'obs' in kwargs and kwargs['obs'] not in [
            'p1p2', 'p1c1', 'p1p2all', 'p1p2gps', 'p1c1rnx', 'p1c2rnx',
            'p1p2p1c1', 'full'
    ]:
        raise ArgumentError('[ERROR] code::get_dcb_rapid Invalid obs', 'obs',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'dcb'
    if 'type' not in kwargs:
        kwargs['type'] = 'current'
    if 'acid' not in kwargs:
        kwargs['acid'] = 'cod'
    if 'span' not in kwargs:
        kwargs['span'] = 'monthly'
    if 'obs' not in kwargs:
        kwargs['obs'] = 'full'

    spec = ''
    if kwargs['type'] == 'rapid' and kwargs['span'] == 'daily' and kwargs[
            'obs'] == 'p1p2':
        pydt = _date(**kwargs)
        yy, ddd = pydt2yydoy(pydt)
        mm, yyyy = pydt.strftime('%m'), pydt.strftime('%Y')
        url_dir = 'BSWUSER52/ORB/{:}'.format(yyyy)
        acn = 'COR'
        sdate = '{:02d}{:03d}'.format(yy, ddd)
        frmt = 'DCB.Z'
    elif kwargs['type'] == 'current' and kwargs['span'] == 'monthly':
        url_dir = 'CODE'
        frmt = 'DCB'
        sdate = ''
        if kwargs['obs'] == 'p1c1':
            acn = 'P1C1'
        elif kwargs['obs'] == 'p1p2':
            acn = 'P1P2'
        elif kwargs['obs'] == 'p1p2all':
            acn = 'P1P2'
            spec = '_ALL'
        elif kwargs['obs'] == 'p1p2gps':
            acn = 'P1P2'
            spec = '_GPS'
        elif kwargs['obs'] == 'p1c1rnx':
            acn = 'P1C1'
            spec = '_RINEX'
        elif kwargs['obs'] == 'p1c2rnx':
            acn = 'P1C2'
            spec = '_RINEX'
        elif kwargs['obs'] == 'p1c2rnx':
            acn = 'CODE'
            spec = ''
        elif kwargs['obs'] == 'p1p2p1c1':
            acn = 'CODE'
            spec = ''
        elif kwargs['obs'] == 'full':
            acn = 'CODE'
            spec = '_FULL'
    try:
        dcb = '{:}{:}{:}.{:}'.format(acn, sdate, spec, frmt)
        target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, dcb)
    except:
        msg = '[ERROR] code::get_dcb_rapid Failed to formulate DCB file'
        raise RuntimeError(msg)
    return target
Exemplo n.º 10
0
def get_ion_rapid_target(**kwargs):
    """ Rapid or Ultra-rapid ionosphere information in IONEX or Bernese format 
      from COD

      CORGddd0.yyI.Z    CODE rapid ionosphere product, IONEX format
      COPGddd0.yyI.Z    CODE 1-day or 2-day ionosphere predictions,
                        in IONEX format
      CODwwwwd.ION_R    CODE rapid ionosphere product, Bernese format
      CODwwwwd.ION_P    CODE 1-day ionosphere predictions, Bernese format
      CODwwwwd.ION_P2   CODE 2-day ionosphere predictions, Bernese format
      CODwwwwd.ION_P5   CODE 5-day ionosphere predictions, Bernese format
      COD.ION_U         Last update of CODE rapid ionosphere product
                        (1 day) complemented with ionosphere predictions 
                        (2 days)

      kwargs that matter:
      format='ionex' or format='inx' to get the IONEX format.
      format='ion' or format='bernese' to get the Bernese format.
      acid='coe' to get the EUREF solution.
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...
  
      Default Values
      kwargs['format'] = 'bernese'
      kwargs['type'] = 'rapid'

      aka:
      kwargs         |format=ionex        | format=bernese      |
      ---------------+--------------------+---------------------+
      type=rapid     |CODE/CORGddd0.yyI.Z | CODE/CODwwwwd.ION_R |
      type=prediction|CODE/COPGddd0.yyI.Z | CODE/CODwwwwd.ION_P |
      type=current or|                    | CODE/COD.ION_U      |
      urapid or      |                    |
      ultra-rapid    |                    |
      type=p2        |                    | CODE/CODwwwwd.ION_P2|
      type=p5        |                    | CODE/CODwwwwd.ION_P5|

      TODO current should be an alias for urapid or ultra-rapid
  """
    if 'format' in kwargs and kwargs['format'] not in [
            'ionex', 'inx', 'ion', 'bernese'
    ]:
        raise ArgumentError('[ERROR] code::get_ion_rapid Invalid format',
                            'format', **kwargs)
    if 'type' in kwargs and kwargs['type'] not in [
            'rapid', 'prediction', 'current', 'p2', 'p5', 'urapid',
            'ultra-rapid'
    ]:
        raise ArgumentError('[ERROR] code::get_ion_rapid Invalid type', 'type',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'bernese'
    if 'type' in kwargs and kwargs['type'] in ['urapid', 'ultra-rapid']:
        kwargs['type'] = 'current'
    if 'type' not in kwargs:
        kwargs['type'] = 'rapid'

    if kwargs['type'] != 'current':
        pydt = _date(**kwargs)  ## this may throw
        yy, ddd = pydt2yydoy(pydt)

    if kwargs['format'] in ['ionex', 'inx']:
        sdate = '{:03d}0'.format(ddd)
        frmt = '{:}I.Z'.format(pydt.strftime("%y"))
        if 'type' in kwargs and kwargs['type'] == 'rapid':
            acn = 'CORG'
        elif 'type' in kwargs and kwargs['type'] == 'prediction':
            acn = 'COPG'
        else:
            raise RuntimeError(
                '[ERROR] code::get_ion_rapid invalid request (#1)')

    if kwargs['format'] in ['bernese', 'ion']:
        acn = 'COD'
        if kwargs['type'] == 'current':
            frmt = 'ION_U'
            sdate = ''
        else:
            week, sow = pydt2gps(pydt)
            sdate = '{:04d}{:1d}'.format(week, sow2dow(sow))
            if kwargs['type'] == 'rapid':
                frmt = 'ION_R'
            elif kwargs['type'] == 'prediction':
                frmt = 'ION_P'
            elif kwargs['type'] == 'p2':
                frmt = 'ION_P2'
            elif kwargs['type'] == 'p5':
                frmt = 'ION_P5'
            else:
                raise RuntimeError(
                    '[ERROR] code::get_ion_rapid invalid request (#2)')

    ion = '{:}{:}.{:}'.format(acn, sdate, frmt)
    target = '{:}/CODE/{:}'.format(CODE_URL, ion)
    return target
Exemplo n.º 11
0
def get_ion_final_target(**kwargs):
    """ Final ionosphere information in IONEX or Bernese format from COD

      kwargs that matter:
      format='ionex' or format='inx' to get the IONEX format.
      format='ion' or format='bernese' to get the Bernese format.
      acid='coe' to get the EUREF solution.
      type='final' Optional but if given must be 'final'
      To provide a date, use either:
        * pydt=datetime.datetime(...) or 
        * year=... and doy=...

      Default values:
      kwargs['format'] = bernese
      kwargs['acid'] = cod

      kwargs  |format=ionex                 | format=bernese               |
      --------+-----------------------------+------------------------------+
      acid=coe|BSWUSER52/ATM/yyyy/COEyyddd.INX.Z| BSWUSER52/ATM/yyyy/COEyyddd.ION.Z|
      acid=cod|CODE/yyyy/CODGddd0.yyI.Z     | CODE/yyyy/CODwwwwd.ION.Z     |
  """
    if 'format' in kwargs and kwargs['format'] not in [
            'ionex', 'inx', 'ion', 'bernese'
    ]:
        raise ArgumentError('[ERROR] code::get_ion_final Invalid format',
                            'format', **kwargs)
    if 'acid' in kwargs and kwargs['acid'] not in ['cod', 'coe']:
        raise ArgumentError('[ERROR] code::get_ion_final Invalid acid', 'acid',
                            **kwargs)
    if 'type' in kwargs and kwargs['type'] != 'final':
        raise ArgumentError('[ERROR] code::get_ion_final Invalid type', 'type',
                            **kwargs)

    if 'format' not in kwargs:
        kwargs['format'] = 'bernese'
    if 'acid' not in kwargs:
        kwargs['acid'] = 'cod'

    pydt = _date(**kwargs)  ## this may throw
    yy, ddd = pydt2yydoy(pydt)
    if kwargs['format'] in ['bernese', 'ion']:
        frmt = 'ION'
    else:
        if kwargs['acid'] == 'coe':
            frmt = 'INX'
        else:
            frmt = '{:02d}I'.format(yy)

    if kwargs['acid'] == 'coe':
        url_dir = 'BSWUSER52/ATM/{:}'.format(pydt.strftime("%Y"))
        acn = 'COE'
        sdate = '{:02d}{:03d}'.format(yy, ddd)
    else:
        url_dir = 'CODE/{:}'.format(pydt.strftime("%Y"))
        if kwargs['format'] in ['bernese', 'ion']:
            acn = 'COD'
            week, sow = pydt2gps(pydt)
            sdate = '{:04d}{:01d}'.format(week, sow2dow(sow))
        else:
            acn = 'CODG'
            sdate = '{:03d}0'.format(ddd)

    ion = '{:}{:}.{:}.Z'.format(acn, sdate, frmt)
    target = '{:}/{:}/{:}'.format(CODE_URL, url_dir, ion)
    return target