Beispiel #1
0
def buildStations(stdict, cnsnlist):
    ''' Builds station database from a list of stations taken
    from the website:
    http://www.earthquakescanada.nrcan.gc.ca/stndon/data_avail-eng.php'''

    reg = re.compile(r'^[BH][H].$')
    d = {}
    q = defaultdict(int)

    with open(cnsnlist) as stations:
        for s in stations:
            field = s.rstrip().split()
            station = field[0]
            if station not in stdict and reg.match(field[1]):
                d[ station ] = {'network': field[-1],
                                'lat' : float(field[2]),
                                'lon' : float(field[3]),
                                'start': float(field[5]),
                                'stop': 0 if not is_number( field[6] ) else field[6],
                                'status': "not aquired"
                             }
                q[ field[0] ] += 1

    # Remove Stations that don't offer 3 components
    for key in q:
        if q[key] < 3:
            del d[key]

    stdict = dict(stdict.items() + d.items()) # Merge the old dict with new items

    open(dbfile,'w').write( json.dumps(stdict, sort_keys = True, indent = 2 ))
def buildStations(stdict, cnsnlist):
    ''' Builds station database from a list of stations taken
    from the website:
    http://www.earthquakescanada.nrcan.gc.ca/stndon/data_avail-eng.php'''

    reg = re.compile(r'^[BH][H].$')
    d = {}
    q = defaultdict(int)

    with open(cnsnlist) as stations:
        for s in stations:
            field = s.rstrip().split()
            station = field[0]
            if station not in stdict and reg.match(field[1]):
                d[station] = {
                    'network': field[-1],
                    'lat': float(field[2]),
                    'lon': float(field[3]),
                    'start': float(field[5]),
                    'stop': 0 if not is_number(field[6]) else field[6],
                    'status': "not aquired"
                }
                q[field[0]] += 1

    # Remove Stations that don't offer 3 components
    for key in q:
        if q[key] < 3:
            del d[key]

    stdict = dict(stdict.items() +
                  d.items())  # Merge the old dict with new items

    open(dbfile, 'w').write(json.dumps(stdict, sort_keys=True, indent=2))
Beispiel #3
0
def queryStns(stdict, args, scp):
    ''' Queries the json dictionary structure containing stations for given
    queries, logical commands and arguments. This is meant to be coupled with
    a CLI interface'''

    qdict = stdict

    # Reduce station list if piped station data was present
    if args.stationList: #check for piped data or station list or ALL stations
        qdict = ( { k:v for k, v in stdict.items() if k in args.stationList } )

    # Run Query
    if args.query:
        value = args.query[2] if not is_number(args.query[2]) else float(args.query[2])
        operator = args.query[1]
        attrib = args.query[0]
        qdict = ({ k:v for k, v in qdict.items()
                   if (attrib in scp.flattendict(qdict[k])
                       and compare(scp.flattendict(qdict[k])[attrib], value, operator))  } )

    # Filter by attribute if required
    if args.attribute:
        # Further trim the list by selecting only
        # the stations that have the particular attribute
        # and get rid of all other attributes.
        adict = {}
        attrib = args.attribute[0]
        for k in qdict.keys():
            if attrib in scp.flattendict(qdict[k]):
                adict[k] = {}
                adict[k][attrib] = scp.flattendict(qdict[k])[attrib]

        qdict = adict

    return qdict
def queryStns(stdict, args, scp):
    ''' Queries the json dictionary structure containing stations for given
    queries, logical commands and arguments. This is meant to be coupled with
    a CLI interface'''

    qdict = stdict

    # Reduce station list if piped station data was present
    if args.stationList:  #check for piped data or station list or ALL stations
        qdict = ({k: v for k, v in stdict.items() if k in args.stationList})

    # Run Query
    if args.query:
        value = args.query[2] if not is_number(args.query[2]) else float(
            args.query[2])
        operator = args.query[1]
        attrib = args.query[0]
        qdict = ({
            k: v
            for k, v in qdict.items()
            if (attrib in scp.flattendict(qdict[k]) and compare(
                scp.flattendict(qdict[k])[attrib], value, operator))
        })

    # Filter by attribute if required
    if args.attribute:
        # Further trim the list by selecting only
        # the stations that have the particular attribute
        # and get rid of all other attributes.
        adict = {}
        attrib = args.attribute[0]
        for k in qdict.keys():
            if attrib in scp.flattendict(qdict[k]):
                adict[k] = {}
                adict[k][attrib] = scp.flattendict(qdict[k])[attrib]

        qdict = adict

    return qdict
def isEitherPoorOrNumber(s):
    if isPoor(s) or is_number(s):
        return True
    else:
        return False
def isEitherPoorOrNumber(s):
    if isPoor(s) or is_number(s):
        return True
    else:
        return False
)
reNew = re.compile(r'^stack_(\w)\.sac')
newfs = []
oldfs = []

###########################################################################
# Get random event directory
###########################################################################
checkdir = '/media/TerraS/CN'
stations = os.listdir(checkdir)
while True:
    station = stations[random.randint(0, len(stations) - 1)]
    events = os.listdir(checkdir + '/' + station)
    event = events[random.randint(0, len(events) - 1)]
    if not is_number(
            event
    ):  # Make sure event dir is right format, skip those not in number format
        print "skipping event", event
        continue
    eventdir = os.path.join(checkdir, station, event)
    print "Going to compare data in event directory: ", eventdir
    ###########################################################################
    # Read in files
    ###########################################################################
    files = os.listdir(eventdir)
    comps = []
    for fs in files:
        try:
            m1 = reNew.match(fs)
            comps.append(
                (m1.group(1),