Ejemplo n.º 1
0
def test_time_deltas():
    """Test the time_deltas attribute."""
    ds = xr.open_dataset(
        get_test_data('irma_gfs_example.nc', as_file_obj=False))
    time = ds['time1']
    truth = 3 * np.ones(8) * units.hr
    assert_array_almost_equal(time.metpy.time_deltas, truth)
Ejemplo n.º 2
0
def lambda_handler(event, context):
    ds = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
    data_var = ds.metpy.parse_cf('Temperature')

    x = data_var.x
    y = data_var.y
    im_data = data_var.isel(time=0).sel(isobaric=1000.)

    fig = plt.figure(figsize=(14, 14))
    ax = fig.add_subplot(1, 1, 1, projection=data_var.metpy.cartopy_crs)

    ax.imshow(im_data, extent=(x.min(), x.max(), y.min(), y.max()),
          cmap='RdBu', origin='lower' if y[0] < y[-1] else 'upper')
    ax.coastlines(color='tab:green', resolution='110m')
    ax.add_feature(cfeature.LAKES.with_scale('110m'), facecolor='none', edgecolor='tab:blue')
    ax.add_feature(cfeature.RIVERS.with_scale('110m'), edgecolor='tab:blue')

    save_path = "/tmp/example.png"
    plt.savefig(save_path)
    
    boto3.resource('s3').meta.client.upload_file(save_path, 'yourdemobucket', 'example.png')

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
Ejemplo n.º 3
0
# Any import of metpy will activate the accessors
import metpy.calc as mpcalc
from metpy.testing import get_test_data

#########################################################################
# Getting Data
# ------------
#
# While xarray can handle a wide variety of n-dimensional data (essentially anything that can
# be stored in a netCDF file), a common use case is working with model output. Such model
# data can be obtained from a THREDDS Data Server using the siphon package, but for this
# tutorial, we will use an example subset of GFS data from Hurrican Irma (September 5th,
# 2017).

# Open the netCDF file as a xarray Dataset
data = xr.open_dataset(get_test_data('irma_gfs_example.nc', False))

# View a summary of the Dataset
print(data)

#########################################################################
# Preparing Data
# --------------
#
# To make use of the data within MetPy, we need to parse the dataset for projection and
# coordinate information following the CF conventions. For this, we use the
# ``data.metpy.parse_cf()`` method, which will return a new, parsed ``DataArray`` or
# ``Dataset``.
#
# Additionally, we rename our data variables for easier reference.
Ejemplo n.º 4
0
import metpy.calc as mpcalc
from metpy.testing import get_test_data
from metpy.units import units

#########################################################################
# Getting Data
# ------------
#
# While xarray can handle a wide variety of n-dimensional data (essentially anything that can
# be stored in a netCDF file), a common use case is working with model output. Such model
# data can be obtained from a THREDDS Data Server using the siphon package, but for this
# tutorial, we will use an example subset of GFS data from Hurrican Irma (September 5th,
# 2017).

# Open the netCDF file as a xarray Dataset
data = xr.open_dataset(get_test_data('irma_gfs_example.nc', False))

# View a summary of the Dataset
print(data)

#########################################################################
# Preparing Data
# --------------
#
# To make use of the data within MetPy, we need to parse the dataset for projection and
# coordinate information following the CF conventions. For this, we use the
# ``data.metpy.parse_cf()`` method.
#
# Additionally, we take a few optional steps to clean up our dataset for later use:
#
# - Rename our data variables for easier reference.
Ejemplo n.º 5
0
def test_ds():
    """Provide an xarray dataset for testing."""
    return xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
Ejemplo n.º 6
0
def test_units_percent():
    """Test that '%' is converted to 'percent'."""
    test_var_percent = xr.open_dataset(
        get_test_data('irma_gfs_example.nc',
                      as_file_obj=False))['Relative_humidity_isobaric']
    assert test_var_percent.metpy.units == units('percent')
Ejemplo n.º 7
0
     kelvin = double(netcdf.getVar(ncid,3,[LLcol LLrow 0], [URcol-LLcol URrow-LLrow 1]));
     %kelvin = double(netcdf.getVar(ncid,1));
     netcdf.close(ncid);
     kelvin(kelvin == -32768) = nan;
     kelvin = flipud(rot90(kelvin));
     sst = (kelvin * 0.01);
"""

import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr

# Any import of metpy will activate the accessors
from metpy.testing import get_test_data

ds = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
data_var = ds.metpy.parse_cf('Temperature')

x = data_var.x
y = data_var.y
im_data = data_var.isel(time=0).sel(isobaric=1000.)

fig = plt.figure(figsize=(14, 14))
ax = fig.add_subplot(1, 1, 1, projection=data_var.metpy.cartopy_crs)

ax.imshow(im_data,
          extent=(x.min(), x.max(), y.min(), y.max()),
          cmap='RdBu',
          origin='lower' if y[0] < y[-1] else 'upper')
ax.coastlines(color='tab:green', resolution='10m')
ax.add_feature(cfeature.LAKES.with_scale('10m'),
Ejemplo n.º 8
0
def test_ds():
    """Provide an xarray dataset for testing."""
    return xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
Ejemplo n.º 9
0
# SPDX-License-Identifier: BSD-3-Clause
"""
XArray Projection Handling
==========================

Use MetPy's XArray accessors to simplify opening a data file and plotting
data on a map using CartoPy.
"""
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr

# Any import of metpy will activate the accessors
from metpy.testing import get_test_data

ds = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
data_var = ds.metpy.parse_cf('Temperature')

x = data_var.x
y = data_var.y
im_data = data_var.isel(time=0).sel(isobaric=1000.)

fig = plt.figure(figsize=(14, 14))
ax = fig.add_subplot(1, 1, 1, projection=data_var.metpy.cartopy_crs)

ax.imshow(im_data, extent=(x.min(), x.max(), y.min(), y.max()),
          cmap='RdBu', origin='lower' if y[0] < y[-1] else 'upper')
ax.coastlines(color='tab:green', resolution='10m')
ax.add_feature(cfeature.LAKES.with_scale('10m'), facecolor='none', edgecolor='tab:blue')
ax.add_feature(cfeature.RIVERS.with_scale('10m'), edgecolor='tab:blue')