Example #1
0
# <codecell>

# cube = proc_cube(cube, bbox=bbox, time=(start, stop), units=units)
cube = get_surface(cube)  # Get a 2D surface cube.  I am working on 3D...
cube

# <codecell>

from utilities import get_nearest_water, make_tree

obs = dict(lon=-77.7867, lat=34.2133)

tree, lon, lat = make_tree(cube)
kw = dict(k=10, max_dist=0.04, min_var=0.01)
series, dist, idx = get_nearest_water(cube, tree, obs['lon'], obs['lat'], **kw)

print('Distance (degrees): {}'.format(dist))
print('Indices: {!r}'.format(idx))

# <codecell>

series

# <codecell>

%matplotlib inline
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cartopy.feature import NaturalEarthFeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
        fname = '{:%Y-%m-%d}-{}.nc'.format(stop, mod_name)
        log.info(fmt(' Downloading to file {} '.format(fname)))
        try:  # Make tree.
            tree, lon, lat = make_tree(cube)
            fig, ax = plt_grid(lon, lat)
        except CoordinateNotFoundError as e:
            log.warning('Cannot make KDTree for: {}'.format(mod_name))
            continue
        # Get model series at observed locations.
        raw_series = dict()
        for station, obs in observations.iterrows():
            a = obs_data[obs['station']]
            try:
                kw = dict(k=10, max_dist=0.04, min_var=0.01)
                args = cube, tree, obs.lon, obs.lat
                series, dist, idx = get_nearest_water(*args, **kw)
            # RuntimeError may occurs, but you should run it again!
            except ValueError as e:
                log.warning(e)
                continue
            if not series:
                status = "Found Land"
            else:
                raw_series.update({obs['station']: series})
                series = as_series(series)
                status = "Found Water"
                ax.plot(lon[idx], lat[idx], 'g.')

            log.info('[{}] {}'.format(status, obs.name))

        if raw_series:  # Save cube.
        fname = '{:%Y-%m-%d}-{}.nc'.format(stop, mod_name)
        log.info(fmt(' Downloading to file {} '.format(fname)))
        try:  # Make tree.
            tree, lon, lat = make_tree(cube)
            fig, ax = plt_grid(lon, lat)
        except CoordinateNotFoundError as e:
            log.warning('Cannot make KDTree for: {}'.format(mod_name))
            continue
        # Get model series at observed locations.
        raw_series = dict()
        for station, obs in observations.iterrows():
            a = obs_data[obs['station']]
            try:
                kw = dict(k=10, max_dist=0.04, min_var=0.01)
                args = cube, tree, obs.lon, obs.lat
                series, dist, idx = get_nearest_water(*args, **kw)
            # RuntimeError may occurs, but you should run it again!
            except ValueError as e:
                log.warning(e)
                continue
            if not series:
                status = "Found Land"
            else:
                raw_series.update({obs['station']: series})
                series = as_series(series)
                status = "Found Water"
                ax.plot(lon[idx], lat[idx], 'g.')

            log.info('[{}] {}'.format(status, obs.name))

        if raw_series:  # Save cube.