예제 #1
0
def grok_station_xml( data, tmin, tmax ):
    
    stations = {}
    station_channels = {}

    for (sta, sta_epo, cha, cha_epo) in xmlzip(data, ('Station', 'StationEpoch', 'Channel', 'Epoch')):

        sta_beg, sta_end, cha_beg, cha_end = [ tdatetime(x) for x in 
                (sta_epo.StartDate, sta_epo.EndDate, cha_epo.StartDate, cha_epo.EndDate) ]

        if not (sta_beg <= tmin and tmax <= sta_end and cha_beg <= tmin and tmax <= cha_end):
            continue

        nslc = tuple([ str(x.strip()) for x in 
                (sta.net_code, sta.sta_code, cha.loc_code, cha.chan_code) ])

        lat, lon, ele, dep, azi, dip = [ float(cha_epo.attrs[x]) for x in 'Lat Lon Elevation Depth Azimuth Dip'.split() ]

        nsl = nslc[:3]
        if nsl not in stations:
            stations[nsl] = model.Station(nsl[0], nsl[1], nsl[2], lat, lon, ele, dep)
        
        stations[nsl].add_channel(model.Channel(nslc[-1], azi, dip))

    return stations.values()
예제 #2
0
    def _get_stations_from_file(self):

        orientations = self._get_channel_orientations()

        # make station to locations map, cause these are not included in the
        # rdseed.stations file

        p = self.get_pile()
        ns_to_l = {}
        for nslc in p.nslc_ids:
            ns = nslc[:2]
            if ns not in ns_to_l:
                ns_to_l[ns] = set()

            ns_to_l[ns].add(nslc[2])

        # make

        rdseed_station_file = os.path.join(self.tempdir, 'rdseed.stations')

        f = open(rdseed_station_file, 'r')

        # sometimes there are line breaks in the station description strings

        txt = f.read()
        rows = dumb_parser(txt)
        f.close()

        icolname = 6
        icolcomp = 5

        stations = []

        for cols in rows:
            network, station = cols[1], cols[0]
            for location in ns_to_l[network, station]:

                channels = []
                for channel in cols[icolcomp].split():
                    if (network, station, location, channel) in orientations:
                        azimuth, dip = orientations[network, station, location,
                                                    channel]
                    else:
                        azimuth, dip = None, None  # let Channel guess from name
                    channels.append(model.Channel(channel, azimuth, dip))

                s = model.Station(network=cols[1],
                                  station=cols[0],
                                  location=location,
                                  lat=float(cols[2]),
                                  lon=float(cols[3]),
                                  elevation=float(cols[4]),
                                  name=cols[icolname],
                                  channels=channels)
                stations.append(s)

        return stations
예제 #3
0
파일: iris_ws.py 프로젝트: carinaj/pyrocko
def grok_station_xml(data, tmin, tmax):
    dom = minidom.parseString(data)

    channel_prio = [['BHZ', 'HHZ'], ['BH1', 'BHN', 'HH1', 'HHN'],
                    ['BH2', 'BHE', 'HH2', 'HHE']]

    stations = {}
    station_channels = {}

    for (sta, sta_epo, cha,
         cha_epo) in tear(dom,
                          ('Station', 'StationEpoch', 'Channel', 'Epoch')):
        sta_beg, sta_end, cha_beg, cha_end = [
            tdatetime(x) for x in (sta_epo.D.startdate, sta_epo.D.enddate,
                                   cha_epo.D.startdate, cha_epo.D.enddate)
        ]

        if not (sta_beg <= tmin and tmax <= sta_end and cha_beg <= tmin
                and tmax <= cha_end):
            continue

        nslc = tuple([
            str(x.strip()) for x in (sta.D.net_code, sta.D.sta_code,
                                     cha.D.loc_code, cha.D.chan_code)
        ])
        lat, lon, ele, dep, azi, dip = [
            float(x)
            for x in (cha_epo.D.lat, cha_epo.D.lon, cha_epo.D.elevation,
                      cha_epo.D.depth, cha_epo.D.azimuth, cha_epo.D.dip)
        ]

        nsl = nslc[:3]
        if nsl not in stations:
            stations[nsl] = model.Station(nsl[0], nsl[1], nsl[2], lat, lon,
                                          ele, dep)

        stations[nsl].add_channel(model.Channel(nslc[-1], azi, dip))

    return stations.values()
예제 #4
0
 def get_pyrocko_stations(self):
     from_stations = {}
     for gs in self.stations:
         ps = model.Station(
             network = gs.network,
             station = gs.station,
             location = '',
             lat = gs.lat,
             lon = gs.lon,
             elevation = gs.elevation*km)
             
         from_stations[gs.network, gs.station] = ps
     
     from_channels = {}
     for gc in self.channels:
         nsl = gc.network, gc.station, gc.auxid
         if nsl not in from_channels:
             ps = model.Station(
                 network = gc.network,
                 station = gc.station,
                 location = gc.auxid,
                 lat = gc.lat,
                 lon = gc.lon,
                 elevation = gc.elevation*km,
                 depth = gc.depth*km)
             from_channels[nsl] = ps
             
         pc = model.Channel(name=gc.channel, azimuth=gc.hang, dip=gc.vang-90.0)
         from_channels[nsl].add_channel(pc)
     
     for nsl, ps in from_channels.iteritems():
         ns = nsl[:2]
         if ns in from_stations:
             del from_stations[ns]
         
     return from_stations.values() + from_channels.values()
예제 #5
0
 def _get_channel_description_from_file(self, nslc):
     return model.Channel(nslc[3], None, None, 1.)
예제 #6
0
def read_station_header_file(fn):
    def m(i, *args):
        if len(ltoks) >= i + len(args) and (tuple(ltoks[i:i + len(args)])
                                            == args):
            return True
        return False

    def f(i):
        return float(toks[i])

    def s(i):
        if len(toks) > i:
            return toks[i]
        else:
            return ''

    fi = open(fn, 'r')

    stations = []
    atsec, station, channel = None, None, None

    for line in fi:
        toks = line.split()
        ltoks = line.lower().split()
        if m(2, 'station', 'header'):
            atsec = 'station'
            station = {'channels': []}
            stations.append(station)
            continue

        if m(2, 'station') and m(5, 'channel'):
            atsec = 'channel'
            channel = {}
            station['channels'].append(channel)
            continue

        if atsec == 'station':
            if m(1, 'station', 'code:'):
                station['station'] = s(3)

            elif m(1, 'network', 'code:'):
                station['network'] = s(3)

            elif m(1, 'name:'):
                station['name'] = ' '.join(toks[2:])

        if atsec == 'channel':
            if m(1, 'channel:'):
                channel['channel'] = s(2)

            elif m(1, 'location:'):
                channel['location'] = s(2)

            elif m(1, 'latitude:'):
                station['lat'] = f(2)

            elif m(1, 'longitude:'):
                station['lon'] = f(2)

            elif m(1, 'elevation:'):
                station['elevation'] = f(2)

            elif m(1, 'local', 'depth:'):
                channel['depth'] = f(3)

            elif m(1, 'azimuth:'):
                channel['azimuth'] = f(2)

            elif m(1, 'dip:'):
                channel['dip'] = f(2)

    fi.close()

    nsl_stations = {}
    for station in stations:
        for channel in station['channels']:

            def cs(k, default=None):
                return channel.get(k, station.get(k, default))

            nsl = station['network'], station['station'], channel['location']
            if nsl not in nsl_stations:
                nsl_stations[nsl] = model.Station(network=station['network'],
                                                  station=station['station'],
                                                  location=channel['location'],
                                                  lat=cs('lat'),
                                                  lon=cs('lon'),
                                                  elevation=cs('elevation'),
                                                  depth=cs('depth', None),
                                                  name=station['name'])

            nsl_stations[nsl].add_channel(
                model.Channel(channel['channel'],
                              azimuth=channel['azimuth'],
                              dip=channel['dip']))

    return nsl_stations.values()