File: raster_declarative.py

package info (click to toggle)
metpy 1.7.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,584 kB
  • sloc: python: 41,853; makefile: 111; javascript: 57
file content (48 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#  Copyright (c) 2021 MetPy Developers.
#  Distributed under the terms of the BSD 3-Clause License.
#  SPDX-License-Identifier: BSD-3-Clause
"""
Raster Plots using Declarative Syntax
=====================================

The MetPy declarative syntax allows for a simplified interface to creating common
meteorological analyses including surface observation plots. This example creates
a temperature raster plot, though other potential raster plots include radar.
"""

import xarray as xr

from metpy.cbook import get_test_data
from metpy.plots import MapPanel, PanelContainer, RasterPlot
from metpy.units import units

###########################
# Import the temperature data from the NARR file.
narr_data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

###########################
# Preview the data:
narr_data

###########################
# Create the 'RasterPlot' object and provide it with the NARR data. Specify the level to be
# plotted, and use the Data variables column to specify the data field to be plotted.
raster = RasterPlot()
raster.data = narr_data
raster.field = 'Temperature'
raster.level = 700 * units.hPa

###########################
# Add the plot to a Map Panel and Panel Container.
panel = MapPanel()
panel.area = 'us'
panel.projection = 'lcc'
panel.layers = ['coastline']
panel.plots = [raster]

pc = PanelContainer()
pc.size = (8, 8)
pc.panels = [panel]
pc.draw()

pc.show()