def stations(filenames):
    """Yield the metadata for each station listed in *filenames*."""

    rows = itertools.chain(*[open(f) for f in filenames])

    ids = set(l[:11] for l in rows if re.match(r'\w{11}', l))
    meta = gio.station_metadata(path=os.path.join(input, 'v2.inv'))
    lost = False
    for id in ids:
        if id in meta:
            yield meta[id]
        else:
            lost = True
    if lost:
        raise Exception("Couldn't find metadata for some stations.")
Exemple #2
0
def where_stations(stations=[], out=None,
  inv=os.path.join(input, 'v2.inv')):
    """Implementation of whatstations command."""

    from code import eqarea
    from code import giss_data

    stations = set(l[:11] for l in
      itertools.chain(*[open(f) for f in stations]) if ':' not in l)
    meta = gio.station_metadata(path=inv)
    assert meta
    # Restrict meta to the set *stations*
    meta = dict((uid,m) for uid,m in meta.iteritems() if uid in stations)

    count = eqarea.GridCounter()
    for s in meta.itervalues():
        count(s.lat, s.lon)
    for c,cell in count.boxes():
        m = c > 0
        out.write("%sMASK%.3f\n" % (giss_data.boxuid(cell), m))
Exemple #3
0
def ghcnmetaasdict(ghcnmeta):
    """Take an open file descriptor on the 'v2.inv' file and return a
    dictionary."""

    stations = gio.station_metadata(file=ghcnmeta, format='v2')
    return stations
Exemple #4
0
def ghcnmetaasdict(ghcnmeta):
    """Take an open file descriptor on the 'v2.inv' file and return a
    dictionary."""

    stations = gio.station_metadata(file=ghcnmeta, format='v2')
    return stations