Example #1
0
def getNetworkInventory(network, user1):
        '''
        Retrieve all stations from one WEBDC network

       :type network: str
       :param network: name of network to search for station
        '''

        inv  = None
        isOk = False

        for i in range(5):
            try:
               client = Client(user=user1)                                            #hs
               #client  = Client(user=user1, timeout=100)                             #hs
               inv = client.getInventory(network, '*', '*', '*', restricted=None,permanent=None)
               isOk= True
               break

            except:
              return None
        #endfor

        if not isOk:  return None   # return _getFromCatalog(network)
        else:         return inv
Example #2
0
def getArclinkInst(station,usermail,pwdkeys):

    inst = 'no_instrument_available'

    #if station.loc == '': station.loc='--'

    sn = station.net+'.'+station.sta+'.'+station.loc+'.'+station.comp
    print 'SN ',sn

    client = Client(user=usermail,dcid_keys=pwdkeys)
    inv= client.getInventory(station.net, station.sta, station.loc, station.comp, instruments=True)
    print 'INV: ',inv

    try:
        stats = inv[sn]
        print 'STATS ',stats

        t= stats[0]
        z= t['paz']
        inst = z['name']
        inst = inst.replace(' ','_')

    except:
        inst = 'no_instrument_available'

    return inst
Example #3
0
def ARC_available(input_dics, event, target_path, event_number):
    """
    Check the availability of ArcLink stations
    """
    print "Check the availability of ArcLink stations"
    client_arclink = Client_arclink(user='******',
                                    timeout=input_dics['arc_avai_timeout'])
    Sta_arc = []
    try:
        inventories = client_arclink.getInventory(
            network=input_dics['net'],
            station=input_dics['sta'],
            location=input_dics['loc'],
            channel=input_dics['cha'],
            starttime=UTCDateTime(event['t1']),
            endtime=UTCDateTime(event['t2']),
            min_latitude=input_dics['mlat_rbb'],
            max_latitude=input_dics['Mlat_rbb'],
            min_longitude=input_dics['mlon_rbb'],
            max_longitude=input_dics['Mlon_rbb'])

        for inv_key in inventories.keys():
            netsta = inv_key.split('.')
            if len(netsta) == 4:
                sta = '%s.%s' % (netsta[0], netsta[1])
                if not inventories[sta]['depth']:
                    inventories[sta]['depth'] = 0.0
                Sta_arc.append([
                    netsta[0], netsta[1], netsta[2], netsta[3],
                    inventories[sta]['latitude'],
                    inventories[sta]['longitude'],
                    inventories[sta]['elevation'], inventories[sta]['depth']
                ])

    except Exception as e:
        exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+')
        ee = 'arclink -- Event: %s --- %s\n' % (str(event_number + 1), e)
        exc_file.writelines(ee)
        exc_file.close()
        print 'ERROR: %s' % ee

    if len(Sta_arc) == 0:
        Sta_arc.append([])
    Sta_arc.sort()
    return Sta_arc
Example #4
0
def ARC_available(input_dics, event, target_path, event_number):
    """
    Check the availability of ArcLink stations
    """
    print "Check the availability of ArcLink stations"
    client_arclink = Client_arclink(user='******',
                                    timeout=input_dics['arc_avai_timeout'])
    Sta_arc = []
    try:
        inventories = client_arclink.getInventory(
            network=input_dics['net'],
            station=input_dics['sta'],
            location=input_dics['loc'],
            channel=input_dics['cha'],
            starttime=UTCDateTime(event['t1']),
            endtime=UTCDateTime(event['t2']),
            min_latitude=input_dics['mlat_rbb'],
            max_latitude=input_dics['Mlat_rbb'],
            min_longitude=input_dics['mlon_rbb'],
            max_longitude=input_dics['Mlon_rbb'])

        for inv_key in inventories.keys():
            netsta = inv_key.split('.')
            if len(netsta) == 4:
                sta = '%s.%s' % (netsta[0], netsta[1])
                if not inventories[sta]['depth']:
                    inventories[sta]['depth'] = 0.0
                Sta_arc.append([netsta[0], netsta[1], netsta[2], netsta[3],
                                inventories[sta]['latitude'],
                                inventories[sta]['longitude'],
                                inventories[sta]['elevation'],
                                inventories[sta]['depth']])

    except Exception as e:
        exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+')
        ee = 'arclink -- Event: %s --- %s\n' % (str(event_number+1), e)
        exc_file.writelines(ee)
        exc_file.close()
        print 'ERROR: %s' % ee

    if len(Sta_arc) == 0:
        Sta_arc.append([])
    Sta_arc.sort()
    return Sta_arc
Example #5
0
def getInventory(station, usermail_1, key_1):

    client = Client(user=usermail_1, dcid_keys=key_1)
    inv= client.getInventory(station.net, station.sta, loc, station.comp, instruments=True)

    return inv
Example #6
0
def getArclinkInst_2(station, usermail, pwdkeys):

    #if station.loc == '--': loc = ''

    sta2  = station
    sta2.lon  = -1
    sta2.lat  = -1
    sta2.ele  = -1
    sta2.gain = -1
    sta2.dip  = -1
    sta2.azi  = -1
    sta2.inst = 'no_instrument_available'

    loc = station.loc

    if loc == '00' or loc == '01' or loc == '10' or loc == '11':     # no entry for this loc
       print 'Use key file'
       return getFromKeyFile(sta2)

    loc= ''

    client = Client(user=usermail, dcid_keys=pwdkeys)

    try   : inv = client.getInventory(station.net, station.sta, loc, station.comp, instruments=True)
    except: return getFromKeyFile(sta2)

    #inv = WebDC.getInventory(station, usermail, pwdkeys)  # ??? noch einbauen

    print 'INV: ',inv
    keys = inv.keys()

    if len(keys) == 0:
       print 'No keys'
       return None

    if Globals.isDebug:               #    save inventory

       file= Server.InventoryFileName(station, '.txt')
       fp  = open(file, 'w')
       lines   = []

       for k in keys:
          lines.append('key = ' + str(k) + '\n')
          lines.append('inv = ' + str(inv[k]) + '\n')

       Basic.writeTextFile(file, lines)
    #endif

    inv1 = inv  [station.net + '.' + station.sta]
    sta2.lon = inv1 ['longitude']
    sta2.lat = inv1 ['latitude']
    sta2.ele = inv1 ['elevation']

    key  = station.net + '.' + station.sta + '.' + loc + '.' + station.comp
    inv1 = inv [key]

    z  = inv1 [0]
    z1 = z ['paz']

    if 'gain' in z1: sta2.gain = z1 ['gain']

    if 'name' in z1:
       inst  = z1 ['name']
       sta2.inst = inst.replace(' ','_')

    sta3 = sta2
    return sta3