Esempio n. 1
0
def maskit(inp, out):
    """Given a land percent file as input, produce a GISTEMP cell mask
    as output."""

    land = grid(inp)
    resolution = land.resolution
    for subbox in eqarea.grid8k():
        values = [land.a[y][x] for x,y in centrein(subbox, resolution)]
        # For GISTEMP we mask as land if there is _any_ land in the
        # cell.
        if sum(values) > 0:
            mask = 1
        else:
            mask = 0
        out.write("%sMASK%.3f\n" % (giss_data.boxuid(subbox), mask))
Esempio n. 2
0
def where_cells(cells=[], out=None):
    """Implementation of wherecells."""

    from code import eqarea
    from code import giss_data

    cells = set(l[:11] for l in
      itertools.chain(*[open(f) for f in cells]))
    cells = [map(float, re.match(r'([-+]\d+\.\d+)([-+]\d+\.\d+)', l).groups())
      for l in cells]
    count = eqarea.GridCounter()
    for lat,lon in cells:
        count(lat, lon)
    for c,cell in count.boxes():
        m = c > 0
        out.write("%sMASK%.3f\n" % (giss_data.boxuid(cell), m))
Esempio n. 3
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))
def rectangle(out, latbound=(-90.0,+90.0), lonbound=(-180.0,+180.0)):
    """*latbound* should be a pair of (southernbound, northernbound),
    *lonbound* should be a pair of (westernbound, easternbound).
    On *out* will be written a step5mask file where every cell whose
    centre is within the specified rectangle will be marked as
    "1.000" and every other cell marked as "0.000".
    """

    from code import eqarea
    from code import giss_data

    s,n = latbound
    w,e = lonbound

    for cell in eqarea.grid8k():
        lat,lon = eqarea.centre(cell)
        if s <= lat < n and w <= lon < e:
            m = 1.0
        else:
            m = 0.0
        out.write("%sMASK%.3f\n" % (giss_data.boxuid(cell), m))
Esempio n. 5
0
def rectangle(out, latbound=(-90.0, +90.0), lonbound=(-180.0, +180.0)):
    """*latbound* should be a pair of (southernbound, northernbound),
    *lonbound* should be a pair of (westernbound, easternbound).
    On *out* will be written a step5mask file where every cell whose
    centre is within the specified rectangle will be marked as
    "1.000" and every other cell marked as "0.000".
    """

    from code import eqarea
    from code import giss_data

    s, n = latbound
    w, e = lonbound

    for cell in eqarea.grid8k():
        lat, lon = eqarea.centre(cell)
        if s <= lat < n and w <= lon < e:
            m = 1.0
        else:
            m = 0.0
        out.write("%sMASK%.3f\n" % (giss_data.boxuid(cell), m))