Browse Source

Added fix for issues from xarray 0.9, which was caused by xarray no longer including default dimensions in to coordinate mappings. Updated documentation and notebooks. Modified documentation URL in setup. Dropping requirement for numpy 1.9

main 1.0b2
Bill Ladwig 8 years ago
parent
commit
b4b4677c15
  1. 2
      README.md
  2. 32
      conda_recipe/LICENSE
  3. 19
      conda_recipe/meta.yaml
  4. BIN
      doc/source/_static/images/basemap_500.png
  5. BIN
      doc/source/_static/images/basemap_front.png
  6. BIN
      doc/source/_static/images/basemap_slp.png
  7. BIN
      doc/source/_static/images/cartopy_500.png
  8. BIN
      doc/source/_static/images/cartopy_cross.png
  9. BIN
      doc/source/_static/images/cartopy_slp.png
  10. BIN
      doc/source/_static/images/matthew.png
  11. BIN
      doc/source/_static/images/matthew_cross.png
  12. 320
      doc/source/basic_usage.rst
  13. 22
      doc/source/index.rst
  14. 11
      doc/source/new.rst
  15. 215
      doc/source/plot.rst
  16. 2
      requirements.txt
  17. 2
      setup.py
  18. 2
      src/wrf/version.py
  19. 418
      test/ipynb/Doc_Examples.ipynb
  20. 125
      test/ipynb/SLS_Example.ipynb
  21. 19
      test/ipynb/WRF_Workshop_Demo.ipynb
  22. 18702
      test/ipynb/WRF_python_demo.ipynb

2
README.md

@ -11,5 +11,5 @@ Installation via conda:
Documentation is available at: Documentation is available at:
http://wrf-python.readthedocs.io http://wrf-python.rtfd.org

32
conda_recipe/LICENSE

@ -0,0 +1,32 @@
PLEASE READ THIS SOFTWARE LICENSE ("LICENSE") CAREFULLY BEFORE USING THE
SOFTWARE. BY USING THE SOFTWARE, YOU ARE AGREEING TO BE BOUND BY ALL OF THE
TERMS OF THIS LICENSE. IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE,
DO NOT USE THE SOFTWARE.
Copyright © 2016 the University Corporation for Atmospheric Research ("UCAR").
All rights reserved. Developed by NCAR's Computational and Information Systems
Laboratory, UCAR, www2.cisl.ucar.edu.
Redistribution and use of the Software in source and binary forms, with or
without modification, is permitted provided that the following conditions
are met:
- Neither the names of NCAR's Computational and Information Systems Laboratory,
the University Corporation for Atmospheric Research, nor the names of its
sponsors or contributors may be used to endorse or promote products derived
from this Software without specific prior written permission.
- Redistributions of source code must retain the above copyright notices, this
list of conditions, and the disclaimer below.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions, and the disclaimer below in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.

19
conda_recipe/meta.yaml

@ -12,41 +12,32 @@ source:
build: build:
number: 1 number: 1
detect_binary_files_with_prefix: true detect_binary_files_with_prefix: true
skip: True # [win32 or np>=112 or (win and py>=35)] skip: True # [win32 or (win and py>=35)]
requirements: requirements:
build: build:
- pip - setuptools
- numpy x.x - numpy x.x
- wrapt - wrapt
- m2w64-toolchain # [win] - m2w64-toolchain # [win]
- gcc # [unix] - gcc # [unix]
- libgcc # [unix]
- python - python
- vc 9 # [win and py27]
- vc 10 # [win and py34]
- vc 14 # [win and py>=35]
run: run:
- numpy x.x - numpy x.x
- python - python
- wrapt - wrapt
- m2w64-toolchain # [win] - m2w64-toolchain # [win]
- gcc # [unix] - libgfortran # [unix]
- libgcc # [unix] - libgcc # [unix]
- xarray
- vc 9 # [win and py27]
- vc 10 # [win and py34]
- vc 14 # [win and py>=35]
test: test:
requires:
- nose
imports: imports:
- wrf - wrf
about: about:
home: https://github.com/NCAR/wrf-python home: https://github.com/NCAR/wrf-python
license: "NCL Source Code" license: "UCAR"
license_file: '{{ environ["RECIPE_DIR"] }}/LICENSE'
summary: "Diagnostic and interpolation routines for WRF-ARW data." summary: "Diagnostic and interpolation routines for WRF-ARW data."
extra: extra:

BIN
doc/source/_static/images/basemap_500.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 229 KiB

BIN
doc/source/_static/images/basemap_front.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 86 KiB

BIN
doc/source/_static/images/basemap_slp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 144 KiB

BIN
doc/source/_static/images/cartopy_500.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 279 KiB

BIN
doc/source/_static/images/cartopy_cross.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 30 KiB

BIN
doc/source/_static/images/cartopy_slp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 161 KiB

BIN
doc/source/_static/images/matthew.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 84 KiB

BIN
doc/source/_static/images/matthew_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

320
doc/source/basic_usage.rst

@ -36,25 +36,24 @@ Result:
.. code-block:: none .. code-block:: none
<xarray.DataArray u'slp' (south_north: 1059, west_east: 1799)> <xarray.DataArray u'slp' (south_north: 1059, west_east: 1799)>
array([[ 1012.22033691, 1012.29815674, 1012.24786377, ..., array([[ 1012.220337, 1012.298157, 1012.247864, ..., 1010.132019,
1010.13201904, 1009.93231201, 1010.06707764], 1009.932312, 1010.067078],
[ 1012.43286133, 1012.44476318, 1012.33666992, ..., [ 1012.432861, 1012.444763, 1012.33667 , ..., 1010.1073 ,
1010.1072998 , 1010.10845947, 1010.04760742], 1010.108459, 1010.047607],
[ 1012.39544678, 1012.38085938, 1012.41705322, ..., [ 1012.395447, 1012.380859, 1012.417053, ..., 1010.22937 ,
1010.22937012, 1010.05596924, 1010.02679443], 1010.055969, 1010.026794],
..., ...,
[ 1009.0423584 , 1009.06921387, 1008.98779297, ..., [ 1009.042358, 1009.069214, 1008.987793, ..., 1019.19281 ,
1019.19281006, 1019.14434814, 1019.1105957 ], 1019.144348, 1019.110596],
[ 1009.22485352, 1009.07513428, 1008.98638916, ..., [ 1009.224854, 1009.075134, 1008.986389, ..., 1019.071899,
1019.07189941, 1019.04266357, 1019.0612793 ], 1019.042664, 1019.061279],
[ 1009.18896484, 1009.1071167 , 1008.97979736, ..., [ 1009.188965, 1009.107117, 1008.979797, ..., 1018.917786,
1018.91778564, 1018.95684814, 1019.04748535]], dtype=float32) 1018.956848, 1019.047485]], dtype=float32)
Coordinates: Coordinates:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... Dimensions without coordinates: south_north, west_east
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XY MemoryOrder: XY
@ -62,10 +61,10 @@ Result:
units: hPa units: hPa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
.. _extract_ncvars: .. _extract_ncvars:
@ -94,26 +93,35 @@ Result:
.. code-block:: none .. code-block:: none
<xarray.DataArray u'P' (bottom_top: 50, south_north: 1059, west_east: 1799)> <xarray.DataArray u'P' (bottom_top: 50, south_north: 1059, west_east: 1799)>
array([[[ 1.21753906e+03, 1.22532031e+03, 1.22030469e+03, ..., array([[[ 1.217539e+03, 1.225320e+03, ..., 9.876406e+02, 1.001117e+03],
1.00760156e+03, 9.87640625e+02, 1.00111719e+03], [ 1.238773e+03, 1.240047e+03, ..., 1.005297e+03, 9.991719e+02],
[ 1.23877344e+03, 1.24004688e+03, 1.22926562e+03, ..., ...,
1.00519531e+03, 1.00529688e+03, 9.99171875e+02], [ 9.208594e+02, 9.059141e+02, ..., 1.902922e+03, 1.904805e+03],
[ 1.23503906e+03, 1.23367188e+03, 1.23731250e+03, ..., [ 9.172734e+02, 9.091094e+02, ..., 1.894375e+03, 1.903422e+03]],
1.01739844e+03, 1.00005469e+03, 9.97093750e+02],
..., [[ 1.219562e+03, 1.210273e+03, ..., 9.973984e+02, 9.907891e+02],
[ 1.77978516e+00, 1.77050781e+00, 1.79003906e+00, ..., [ 1.224578e+03, 1.223508e+03, ..., 9.985547e+02, 9.921172e+02],
4.22949219e+00, 4.25659180e+00, 4.13647461e+00], ...,
[ 1.73291016e+00, 1.76879883e+00, 1.77978516e+00, ..., [ 9.012734e+02, 9.052031e+02, ..., 1.897766e+03, 1.894500e+03],
4.24047852e+00, 4.24707031e+00, 4.13549805e+00], [ 9.137500e+02, 9.071719e+02, ..., 1.893273e+03, 1.893664e+03]],
[ 1.71533203e+00, 1.65722656e+00, 1.67480469e+00, ...,
4.06884766e+00, 4.03637695e+00, 4.04785156e+00]]], dtype=float32) ...,
[[ 7.233154e+00, 7.224121e+00, ..., 3.627930e+00, 3.613770e+00],
[ 7.226318e+00, 7.358154e+00, ..., 3.725098e+00, 3.634033e+00],
...,
[ 5.354248e+00, 5.406006e+00, ..., 1.282715e+01, 1.264844e+01],
[ 5.295410e+00, 5.177490e+00, ..., 1.256274e+01, 1.257642e+01]],
[[ 2.362061e+00, 2.376221e+00, ..., 1.151367e+00, 1.156982e+00],
[ 2.342529e+00, 2.403809e+00, ..., 1.198486e+00, 1.155273e+00],
...,
[ 1.732910e+00, 1.768799e+00, ..., 4.247070e+00, 4.135498e+00],
[ 1.715332e+00, 1.657227e+00, ..., 4.036377e+00, 4.047852e+00]]], dtype=float32)
Coordinates: Coordinates:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
* bottom_top (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... Dimensions without coordinates: bottom_top, south_north, west_east
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -121,10 +129,9 @@ Result:
units: Pa units: Pa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
Disabling xarray and metadata Disabling xarray and metadata
@ -267,10 +274,8 @@ Result:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
* Time (Time) datetime64[ns] 2016-10-07 2016-10-07 2016-10-07 * Time (Time) datetime64[ns] 2016-10-07 2016-10-07 2016-10-07
* bottom_top (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
datetime (Time) datetime64[ns] 2016-10-07T00:00:00 ... datetime (Time) datetime64[ns] 2016-10-07T00:00:00 ...
Dimensions without coordinates: bottom_top, south_north, west_east
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -278,10 +283,9 @@ Result:
units: Pa units: Pa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
Combining Multiple Files Using the 'join' Method Combining Multiple Files Using the 'join' Method
@ -326,28 +330,19 @@ Result:
.. code-block:: none .. code-block:: none
<xarray.DataArray u'P' (file: 3, bottom_top: 50, south_north: 1059, west_east: 1799)> <xarray.DataArray u'P' (file: 3, bottom_top: 50, south_north: 1059, west_east: 1799)>
array([[[[ 1.21753906e+03, 1.22532031e+03, 1.22030469e+03, ..., array([[[[ 1.217539e+03, ..., 1.001117e+03],
1.00760156e+03, 9.87640625e+02, 1.00111719e+03], ...,
[ 1.23877344e+03, 1.24004688e+03, 1.22926562e+03, ..., [ 9.172734e+02, ..., 1.903422e+03]],
1.00519531e+03, 1.00529688e+03, 9.99171875e+02], ...,
[ 1.23503906e+03, 1.23367188e+03, 1.23731250e+03, ..., [[ 2.362061e+00, ..., 1.156982e+00],
1.01739844e+03, 1.00005469e+03, 9.97093750e+02], ...,
..., [ 1.715332e+00, ..., 4.047852e+00]]]], dtype=float32)
[ 1.77978516e+00, 1.77050781e+00, 1.79003906e+00, ...,
4.22949219e+00, 4.25659180e+00, 4.13647461e+00],
[ 1.73291016e+00, 1.76879883e+00, 1.77978516e+00, ...,
4.24047852e+00, 4.24707031e+00, 4.13549805e+00],
[ 1.71533203e+00, 1.65722656e+00, 1.67480469e+00, ...,
4.06884766e+00, 4.03637695e+00, 4.04785156e+00]]]], dtype=float32)
Coordinates: Coordinates:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
* bottom_top (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... * file (file) int64 0 1 2
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... datetime (file) datetime64[ns] 2016-10-07 ...
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... Dimensions without coordinates: bottom_top, south_north, west_east
* file (file) int64 0 1 2
datetime (file) datetime64[ns] 2016-10-07T00:00:00 ...
Time int64 0
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -355,10 +350,9 @@ Result:
units: Pa units: Pa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
Note how the 'Time' dimension was replaced with the 'file' dimension, due to the Note how the 'Time' dimension was replaced with the 'file' dimension, due to the
@ -388,28 +382,20 @@ Result
.. code-block:: none .. code-block:: none
<xarray.DataArray u'P' (file: 3, Time: 1, bottom_top: 50, south_north: 1059, west_east: 1799)> <xarray.DataArray u'P' (file: 3, Time: 1, bottom_top: 50, south_north: 1059, west_east: 1799)>
array([[[[[ 1.21753906e+03, 1.22532031e+03, 1.22030469e+03, ..., array([[[[[ 1.217539e+03, ..., 1.001117e+03],
1.00760156e+03, 9.87640625e+02, 1.00111719e+03],
[ 1.23877344e+03, 1.24004688e+03, 1.22926562e+03, ...,
1.00519531e+03, 1.00529688e+03, 9.99171875e+02],
[ 1.23503906e+03, 1.23367188e+03, 1.23731250e+03, ...,
1.01739844e+03, 1.00005469e+03, 9.97093750e+02],
..., ...,
[ 1.77978516e+00, 1.77050781e+00, 1.79003906e+00, ..., [ 9.172734e+02, ..., 1.903422e+03]],
4.22949219e+00, 4.25659180e+00, 4.13647461e+00],
[ 1.73291016e+00, 1.76879883e+00, 1.77978516e+00, ..., ...,
4.24047852e+00, 4.24707031e+00, 4.13549805e+00], [[ 2.362061e+00, ..., 1.156982e+00],
[ 1.71533203e+00, 1.65722656e+00, 1.67480469e+00, ..., ...,
4.06884766e+00, 4.03637695e+00, 4.04785156e+00]]]]], dtype=float32) [ 1.715332e+00, ..., 4.047852e+00]]]]], dtype=float32)
Coordinates: Coordinates:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
* bottom_top (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... * file (file) int64 0 1 2
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... datetime (file, Time) datetime64[ns] 2016-10-07 2016-10-07 2016-10-07
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... Dimensions without coordinates: Time, bottom_top, south_north, west_east
* file (file) int64 0 1 2
datetime (file, Time) datetime64[ns] 2016-10-07T00:00:00 ...
* Time (Time) int64 0
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -417,10 +403,9 @@ Result
units: Pa units: Pa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
Dictionaries of WRF File Sequences Dictionaries of WRF File Sequences
@ -459,28 +444,21 @@ Result:
.. code-block:: none .. code-block:: none
<xarray.DataArray 'P' (key_0: 2, Time: 2, bottom_top: 50, south_north: 1059, west_east: 1799)> <xarray.DataArray 'P' (key_0: 2, Time: 2, bottom_top: 50, south_north: 1059, west_east: 1799)>
array([[[[[ 1.21753906e+03, 1.22532031e+03, 1.22030469e+03, ..., array([[[[[ 1.217539e+03, ..., 1.001117e+03],
1.00760156e+03, 9.87640625e+02, 1.00111719e+03], ...,
[ 1.23877344e+03, 1.24004688e+03, 1.22926562e+03, ..., [ 9.172734e+02, ..., 1.903422e+03]],
1.00519531e+03, 1.00529688e+03, 9.99171875e+02],
[ 1.23503906e+03, 1.23367188e+03, 1.23731250e+03, ..., ...,
1.01739844e+03, 1.00005469e+03, 9.97093750e+02], [[ 2.362061e+00, ..., 1.156982e+00],
..., ...,
[ 1.77978516e+00, 1.77050781e+00, 1.79003906e+00, ..., [ 1.715332e+00, ..., 4.047852e+00]]]]], dtype=float32)
4.22949219e+00, 4.25659180e+00, 4.13647461e+00],
[ 1.73291016e+00, 1.76879883e+00, 1.77978516e+00, ...,
4.24047852e+00, 4.24707031e+00, 4.13549805e+00],
[ 1.71533203e+00, 1.65722656e+00, 1.67480469e+00, ...,
4.06884766e+00, 4.03637695e+00, 4.04785156e+00]]]]], dtype=float32)
Coordinates: Coordinates:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
* Time (Time) datetime64[ns] 2016-10-07T00:00:00 ... * Time (Time) datetime64[ns] 2016-10-07 ...
* bottom_top (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... datetime (Time) datetime64[ns] 2016-10-07 ...
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... * key_0 (key_0) <U6 u'label1' u'label2'
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... Dimensions without coordinates: bottom_top, south_north, west_east
datetime (Time) datetime64[ns] 2016-10-07T00:00:00 ...
* key_0 (key_0) <U6 u'ens1' u'ens2'
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -488,10 +466,9 @@ Result:
units: Pa units: Pa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
Interpolation Routines Interpolation Routines
-------------------------- --------------------------
@ -542,17 +519,15 @@ Result:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... Dimensions without coordinates: south_north, west_east
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
Attributes: Attributes:
FieldType: 104 FieldType: 104
units: m units: m
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
level: 500 hPa level: 500 hPa
missing_value: 9.96920996839e+36 missing_value: 9.96920996839e+36
_FillValue: 9.96920996839e+36 _FillValue: 9.96920996839e+36
@ -623,17 +598,16 @@ Result:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ... xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ...
* vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ... * vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ...
* idx (idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Dimensions without coordinates: idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: pressure description: pressure
units: hPa units: hPa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (0.0, 529.0) to (1797.0, 529.0) orientation: (0.0, 529.0) to (1797.0, 529.0)
missing_value: 9.96920996839e+36 missing_value: 9.96920996839e+36
_FillValue: 9.96920996839e+36 _FillValue: 9.96920996839e+36
@ -689,17 +663,16 @@ Result:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ... xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ...
* vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ... * vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ...
* idx (idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Dimensions without coordinates: idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: pressure description: pressure
units: hPa units: hPa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (0.0, 529.0) to (1797.0, 529.0) ; center=CoordPair(x=899.0, y=529.0) ; angle=90.0 orientation: (0.0, 529.0) to (1797.0, 529.0) ; center=CoordPair(x=899.0, y=529.0) ; angle=90.0
missing_value: 9.96920996839e+36 missing_value: 9.96920996839e+36
_FillValue: 9.96920996839e+36 _FillValue: 9.96920996839e+36
@ -760,17 +733,16 @@ Result:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ... xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ...
* vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ... * vertical (vertical) float32 0.0 261.828 523.656 785.484 1047.31 1309.14 ...
* idx (idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Dimensions without coordinates: idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: pressure description: pressure
units: hPa units: hPa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (0.0, 529.0) to (1797.0, 529.0) orientation: (0.0, 529.0) to (1797.0, 529.0)
missing_value: 9.96920996839e+36 missing_value: 9.96920996839e+36
_FillValue: 9.96920996839e+36 _FillValue: 9.96920996839e+36
@ -827,17 +799,16 @@ Result:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ... xy_loc (idx) object CoordPair(x=0.0, y=529.0, lat=34.5279502869, lon=-127.398925781) ...
* vertical (vertical) float32 1000.0 2000.0 3000.0 * vertical (vertical) float32 1000.0 2000.0 3000.0
* idx (idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Dimensions without coordinates: idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: pressure description: pressure
units: hPa units: hPa
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (0.0, 529.0) to (1797.0, 529.0) orientation: (0.0, 529.0) to (1797.0, 529.0)
missing_value: 9.96920996839e+36 missing_value: 9.96920996839e+36
_FillValue: 9.96920996839e+36 _FillValue: 9.96920996839e+36
@ -893,17 +864,16 @@ Result:
Coordinates: Coordinates:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ... xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ...
* line_idx (line_idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ... Dimensions without coordinates: line_idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: TEMP at 2 M description: TEMP at 2 M
units: K units: K
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (899.0, 0.0) to (899.0, 1057.0) orientation: (899.0, 0.0) to (899.0, 1057.0)
@ -943,17 +913,16 @@ Result:
Coordinates: Coordinates:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ... xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ...
* line_idx (line_idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ... Dimensions without coordinates: line_idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: TEMP at 2 M description: TEMP at 2 M
units: K units: K
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (899.0, 0.0) to (899.0, 1057.0) ; center=CoordPair(x=899, y=529) ; angle=0.0 orientation: (899.0, 0.0) to (899.0, 1057.0) ; center=CoordPair(x=899, y=529) ; angle=0.0
@ -1001,17 +970,16 @@ Result:
Coordinates: Coordinates:
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ... xy_loc (line_idx) object CoordPair(x=899.0, y=0.0, lat=24.3645858765, lon=-97.5) ...
* line_idx (line_idx) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ... Dimensions without coordinates: line_idx
Attributes: Attributes:
FieldType: 104 FieldType: 104
description: TEMP at 2 M description: TEMP at 2 M
units: K units: K
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
orientation: (899.0, 0.0) to (899.0, 1057.0) orientation: (899.0, 0.0) to (899.0, 1057.0)
@ -1067,9 +1035,8 @@ Result:
XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ... XLONG (south_north, west_east) float32 -122.72 -122.693 -122.666 ...
XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ... XLAT (south_north, west_east) float32 21.1381 21.1451 21.1521 ...
Time datetime64[ns] 2016-10-07 Time datetime64[ns] 2016-10-07
* south_north (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
* west_east (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
* interp_level (interp_level) int64 200 300 500 1000 * interp_level (interp_level) int64 200 300 500 1000
Dimensions without coordinates: south_north, west_east
Attributes: Attributes:
FieldType: 104 FieldType: 104
MemoryOrder: XYZ MemoryOrder: XYZ
@ -1077,10 +1044,9 @@ Result:
units: K units: K
stagger: stagger:
coordinates: XLONG XLAT coordinates: XLONG XLAT
projection: LambertConformal(bottom_left=(21.138123, -122.71953), projection: LambertConformal(stand_lon=-97.5, moad_cen_lat=38.5000038147,
top_right=(47.843636, -60.901367), stand_lon=-97.5, truelat1=38.5, truelat2=38.5, pole_lat=90.0,
moad_cen_lat=38.5000038147, truelat1=38.5, truelat2=38.5, pole_lon=0.0)
pole_lat=90.0, pole_lon=0.0)
vert_interp_type: eth vert_interp_type: eth
@ -1122,7 +1088,7 @@ Result:
Coordinates: Coordinates:
* lat_lon (lat_lon) <U3 u'lat' u'lon' * lat_lon (lat_lon) <U3 u'lat' u'lon'
xy_coord object CoordPair(x=400, y=200) xy_coord object CoordPair(x=400, y=200)
idx int64 0 Dimensions without coordinates: idx
<xarray.DataArray u'xy' (x_y: 2)> <xarray.DataArray u'xy' (x_y: 2)>
@ -1130,7 +1096,7 @@ Result:
Coordinates: Coordinates:
latlon_coord object CoordPair(lat=28.5581640822, lon=-112.678276173) latlon_coord object CoordPair(lat=28.5581640822, lon=-112.678276173)
* x_y (x_y) <U1 u'x' u'y' * x_y (x_y) <U1 u'x' u'y'
idx int64 0 Dimensions without coordinates: idx
Example With Multiple Coordinates Example With Multiple Coordinates
@ -1163,7 +1129,7 @@ Result:
Coordinates: Coordinates:
* lat_lon (lat_lon) <U3 u'lat' u'lon' * lat_lon (lat_lon) <U3 u'lat' u'lon'
xy_coord (idx) object CoordPair(x=400, y=200) CoordPair(x=105, y=205) xy_coord (idx) object CoordPair(x=400, y=200) CoordPair(x=105, y=205)
* idx (idx) int64 0 1 Dimensions without coordinates: idx
<xarray.DataArray u'xy' (x_y: 2, idx: 2)> <xarray.DataArray u'xy' (x_y: 2, idx: 2)>
@ -1172,7 +1138,7 @@ Result:
Coordinates: Coordinates:
latlon_coord (idx) object CoordPair(lat=28.5581640822, lon=-112.678276173) ... latlon_coord (idx) object CoordPair(lat=28.5581640822, lon=-112.678276173) ...
* x_y (x_y) <U1 u'x' u'y' * x_y (x_y) <U1 u'x' u'y'
* idx (idx) int64 0 1 Dimensions without coordinates: idx
Mapping Helper Routines Mapping Helper Routines

22
doc/source/index.rst

@ -3,15 +3,28 @@
You can adapt this file completely to your liking, but it should at least You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive. contain the root `toctree` directive.
.. meta::
:description: Diagnostic and interpolation routines for WRF ARW data
:keywords: wrf, python, wrf-python, weather research and forecasting,
weather research and forecasting model, model, weather,
numerical weather prediction, model, matplotlib, cartopy,
wrf-arw, arw, ncar, ucar, cisl, ncl, ncar command language,
national center for atmospheric research,
university corporation for atmospheric research,
pynio, pyngl, interpolation
wrf-python wrf-python
=========== ===========
A collection of diagnostic and interpolation routines for use with output from
the Weather Research and Forecasting (WRF-ARW) Model.
wrf-python is a package to help users working with the Weather This package provides over 30 diagnostic calculations,
Research and Forecasting Model (WRF-ARW) output. wrf-python includes over several interpolation routines, and utilities to help with plotting
thirty diagnostics calculations along with various interpolation routines. When via cartopy, basemap, or PyNGL. The functionality is similar to what is
coupled with either matplotlib or PyNGL, users can create plots like this: provided by the NCL WRF package.
When coupled with either matplotlib or PyNGL, users can create plots like this:
.. image:: _static/images/matthew.png .. image:: _static/images/matthew.png
:scale: 100% :scale: 100%
@ -33,7 +46,6 @@ Documentation
./license ./license
Indices and tables Indices and tables
================== ==================

11
doc/source/new.rst

@ -29,4 +29,15 @@ v1.0b1
issues with distutils, numpy distutils, and mingw compiler. Will attempt issues with distutils, numpy distutils, and mingw compiler. Will attempt
to find a workaround before the next release. Windows users should use to find a workaround before the next release. Windows users should use
Python 2.7 or Python 3.4 for now. Python 2.7 or Python 3.4 for now.
v1.0b2
----------
- Beta release 2.
- xarray 0.9 no longer includes default index dimensions in the coordinate
mappings. This was causing a crash in the routines that cause a reduction
in dimension shape, mainly the interpolation routines. This has been
fixed.
- Documentation updated to show the new output from xarray.

215
doc/source/plot.rst

@ -40,9 +40,9 @@ Plotting a Two-dimensional Field
import cartopy.crs as crs import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature from cartopy.feature import NaturalEarthFeature
from wrf import (to_np, getvar, smooth2d, get_cartopy, latlon_coords, from wrf import to_np, getvar, smooth2d, get_cartopy, cartopy_xlim, cartopy_ylim
cartopy_xlim, cartopy_ylim)
# Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
# Get the sea level pressure # Get the sea level pressure
@ -51,16 +51,15 @@ Plotting a Two-dimensional Field
# Smooth the sea level pressure since it tends to be noisy near the mountains # Smooth the sea level pressure since it tends to be noisy near the mountains
smooth_slp = smooth2d(slp, 3) smooth_slp = smooth2d(slp, 3)
# Get the latitude and longitude coordinate arrays # Get the latitude and longitude points
lats, lons = latlon_coords(smooth_slp) lats, lons = latlon_coords(slp)
# The WrfProj.cartopy() method returns a cartopy.crs projection object
cart_proj = get_cartopy(smooth_slp)
# Create a figure that's 10x10 # Get the cartopy mapping object
fig = plt.figure(figsize=(10,10)) cart_proj = get_cartopy(slp)
# Get the GeoAxes set to the projection used by WRF # Create a figure
fig = plt.figure(figsize=(12,9))
# Set the GeoAxes to the projection used by WRF
ax = plt.axes(projection=cart_proj) ax = plt.axes(projection=cart_proj)
# Download and add the states and coastlines # Download and add the states and coastlines
@ -70,22 +69,21 @@ Plotting a Two-dimensional Field
ax.coastlines('50m', linewidth=0.8) ax.coastlines('50m', linewidth=0.8)
# Make the contour outlines and filled contours for the smoothed sea level pressure. # Make the contour outlines and filled contours for the smoothed sea level pressure.
plt.contour(to_np(lons), to_np(lats), to_np(smooth_slp), 10, colors="black", plt.contour(to_np(lons), to_np(lats), to_np(smooth_slp), 10, colors="black", transform=crs.PlateCarree())
transform=crs.PlateCarree()) plt.contourf(to_np(lons), to_np(lats), to_np(smooth_slp), 10, transform=crs.PlateCarree(), cmap=get_cmap("jet"))
plt.contourf(to_np(lons), to_np(lats), to_np(smooth_slp), 10, transform=crs.PlateCarree())
# Add a color bar # Add a color bar
plt.colorbar(ax=ax, shrink=.47) plt.colorbar(ax=ax, shrink=.62)
# Set the map limits # Set the map limits. Not really necessary, but used for demonstration.
ax.set_xlim(cartopy_xlim(smooth_slp)) ax.set_xlim(cartopy_xlim(smooth_slp))
ax.set_ylim(cartopy_ylim(smooth_slp)) ax.set_ylim(cartopy_ylim(smooth_slp))
# Add the gridlines # Add the gridlines
ax.gridlines() ax.gridlines(color="black", linestyle="dotted")
plt.title("Sea Level Pressure (hPa)") plt.title("Sea Level Pressure (hPa)")
plt.show() plt.show()
Horizontal Interpolation to a Pressure Level Horizontal Interpolation to a Pressure Level
@ -104,9 +102,9 @@ Horizontal Interpolation to a Pressure Level
import cartopy.crs as crs import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature from cartopy.feature import NaturalEarthFeature
from wrf import (getvar, interplevel, to_np, get_cartopy, from wrf import getvar, interplevel, to_np, latlon_coords, get_cartopy, cartopy_xlim, cartopy_ylim
latlon_coords, cartopy_xlim, cartopy_ylim)
# Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
# Extract the pressure, geopotential height, and wind variables # Extract the pressure, geopotential height, and wind variables
@ -125,12 +123,12 @@ Horizontal Interpolation to a Pressure Level
# Get the lat/lon coordinates # Get the lat/lon coordinates
lats, lons = latlon_coords(ht_500) lats, lons = latlon_coords(ht_500)
# Get the cartopy map projection information # Get the map projection information
cart_proj = get_cartopy(ht_500) cart_proj = get_cartopy(ht_500)
# Create the figure # Create the figure
fig = plt.figure(figsize=(10,10)) fig = plt.figure(figsize=(12,9))
ax = plt.axes([0.1,0.1,0.8,0.8], projection=cart_proj) ax = plt.axes(projection=cart_proj)
# Download and add the states and coastlines # Download and add the states and coastlines
states = NaturalEarthFeature(category='cultural', scale='50m', facecolor='none', states = NaturalEarthFeature(category='cultural', scale='50m', facecolor='none',
@ -138,13 +136,13 @@ Horizontal Interpolation to a Pressure Level
ax.add_feature(states, linewidth=0.5) ax.add_feature(states, linewidth=0.5)
ax.coastlines('50m', linewidth=0.8) ax.coastlines('50m', linewidth=0.8)
# Create the 500 hPa geopotential height contours # Add the 500 hPa geopotential height contours
levels = np.arange(520., 580., 6.) levels = np.arange(520., 580., 6.)
contours = plt.contour(to_np(lons), to_np(lats), to_np(ht_500), levels=levels, colors="black", contours = plt.contour(to_np(lons), to_np(lats), to_np(ht_500), levels=levels, colors="black",
transform=crs.PlateCarree()) transform=crs.PlateCarree())
plt.clabel(contours, inline=1, fontsize=10, fmt="%i") plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
# Wind Speed contours # Add the wind speed contours
levels = [25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 110, 120] levels = [25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 110, 120]
wspd_contours = plt.contourf(to_np(lons), to_np(lats), to_np(wspd_500), levels=levels, wspd_contours = plt.contourf(to_np(lons), to_np(lats), to_np(wspd_500), levels=levels,
cmap=get_cmap("rainbow"), cmap=get_cmap("rainbow"),
@ -186,19 +184,18 @@ plot, see :ref:`cross_example`.
import cartopy.feature as cfeature import cartopy.feature as cfeature
from netCDF4 import Dataset from netCDF4 import Dataset
from wrf import (getvar, to_np, vertcross, smooth2d, CoordPair, GeoBounds, from wrf import (getvar, to_np, vertcross, smooth2d, CoordPair, GeoBounds, get_cartopy,
latlon_coords, get_cartopy, cartopy_xlim, cartopy_ylim) latlon_coords, cartopy_xlim, cartopy_ylim)
# Open the output NetCDF file # Open the NetCDF file
filename = "wrfout_d01_2016-10-07_00_00_00" ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
ncfile = DataSet(filename)
# Get the WRF variables # Get the WRF variables
slp = getvar(ncfile, "slp") slp = getvar(ncfile, "slp")
smooth_slp = smooth2d(slp, 3) smooth_slp = smooth2d(slp, 3)
ctt = getvar(ncfile, "ctt") ctt = getvar(ncfile, "ctt")
height = getvar(ncfile, "z") z = getvar(ncfile, "z", timeidx=0)
dbz = getvar(ncfile, "dbz") dbz = getvar(ncfile, "dbz", timeidx=0)
Z = 10**(dbz/10.) Z = 10**(dbz/10.)
wspd = getvar(ncfile, "wspd_wdir", units="kt")[0,:] wspd = getvar(ncfile, "wspd_wdir", units="kt")[0,:]
@ -206,53 +203,47 @@ plot, see :ref:`cross_example`.
start_point = CoordPair(lat=26.76, lon=-80.0) start_point = CoordPair(lat=26.76, lon=-80.0)
end_point = CoordPair(lat=26.76, lon=-77.8) end_point = CoordPair(lat=26.76, lon=-77.8)
# Compute the vertical cross-section interpolation. Also, include the # Compute the vertical cross-section interpolation. Also, include the lat/lon points along the cross-section
# lat/lon points along the cross-section in the metadata by setting # in the metadata by setting latlon to True.
# latlon to True. z_cross = vertcross(Z, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True)
z_cross = vertcross(Z, height, wrfin=ncfile, start_point=start_point, wspd_cross = vertcross(wspd, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True)
end_point=end_point, latlon=True, meta=True)
wspd_cross = vertcross(wspd, height, wrfin=ncfile, start_point=start_point,
end_point=end_point, latlon=True, meta=True)
dbz_cross = 10.0 * np.log10(z_cross) dbz_cross = 10.0 * np.log10(z_cross)
# Get the latitude and longitude coordinate arrays # Get the lat/lon points
lats, lons = latlon_coords(slp) lats, lons = latlon_coords(slp)
# Get the cartopy projection object # Get the cartopy projection object
cart_proj = get_cartopy(slp) cart_proj = get_cartopy(slp)
# Create the figure which will have 3 subplots, one on the left, and # Create a figure that will have 3 subplots
# two vertically stacked on the right. fig = plt.figure(figsize=(10,7))
fig = plt.figure(figsize=(7,5))
ax_ctt = fig.add_subplot(1,2,1,projection=cart_proj) ax_ctt = fig.add_subplot(1,2,1,projection=cart_proj)
ax_wspd = fig.add_subplot(2,2,2) ax_wspd = fig.add_subplot(2,2,2)
ax_dbz = fig.add_subplot(2,2,4) ax_dbz = fig.add_subplot(2,2,4)
# Download and create the states, land, and oceans using cartopy features # Download and create the states, land, and oceans using cartopy features
states = cfeature.NaturalEarthFeature(category='cultural', scale='50m', facecolor='none', states = cfeature.NaturalEarthFeature(category='cultural', scale='50m', facecolor='none',
name='admin_1_states_provinces_shp') name='admin_1_states_provinces_shp')
land = cfeature.NaturalEarthFeature(category='physical', name='land', scale='50m', land = cfeature.NaturalEarthFeature(category='physical', name='land', scale='50m',
facecolor=cfeature.COLORS['land']) facecolor=cfeature.COLORS['land'])
ocean = cfeature.NaturalEarthFeature(category='physical', name='ocean', scale='50m', ocean = cfeature.NaturalEarthFeature(category='physical', name='ocean', scale='50m',
facecolor=cfeature.COLORS['water']) facecolor=cfeature.COLORS['water'])
# Make the ctt contours. # Make the pressure contours
contour_levels = [960, 965, 970, 975, 980, 990] contour_levels = [960, 965, 970, 975, 980, 990]
c1 = ax_ctt.contour(to_np(lons), to_np(lats), to_np(smooth_slp), levels=contour_levels, c1 = ax_ctt.contour(lons, lats, to_np(smooth_slp), levels=contour_levels, colors="white",
colors="white", transform=crs.PlateCarree(), zorder=3, linewidths=1.0) transform=crs.PlateCarree(), zorder=3, linewidths=1.0)
# Create the filled cloud top temperature contours # Create the filled cloud top temperature contours
contour_levels = [-80.0, -70.0, -60, -50, -40, -30, -20, -10, 0, 10] contour_levels = [-80.0, -70.0, -60, -50, -40, -30, -20, -10, 0, 10]
ctt_contours = ax_ctt.contourf(lons, lats, to_np(ctt), contour_levels, ctt_contours = ax_ctt.contourf(to_np(lons), to_np(lats), to_np(ctt), contour_levels, cmap=get_cmap("Greys"),
cmap=get_cmap("Greys"), transform=crs.PlateCarree(), transform=crs.PlateCarree(), zorder=2)
zorder=2)
# Draw the yellow cross section line ax_ctt.plot([start_point.lon, end_point.lon], [start_point.lat, end_point.lat], color="yellow",
ax_ctt.plot([start_point.lon, end_point.lon], [start_point.lat, end_point.lat], marker="o", transform=crs.PlateCarree(), zorder=3)
color="yellow", marker="o", transform=crs.PlateCarree(), zorder=3)
# Create the label bar for cloud top temperature # Create the color bar for cloud top temperature
cb_ctt = fig.colorbar(ctt_contours, ax=ax_ctt, shrink=.5) cb_ctt = fig.colorbar(ctt_contours, ax=ax_ctt, shrink=.60)
cb_ctt.ax.tick_params(labelsize=5) cb_ctt.ax.tick_params(labelsize=5)
# Draw the oceans, land, and states # Draw the oceans, land, and states
@ -265,21 +256,21 @@ plot, see :ref:`cross_example`.
CoordPair(lat=30.0, lon=-72.0)) CoordPair(lat=30.0, lon=-72.0))
ax_ctt.set_xlim(cartopy_xlim(ctt, geobounds=hur_bounds)) ax_ctt.set_xlim(cartopy_xlim(ctt, geobounds=hur_bounds))
ax_ctt.set_ylim(cartopy_ylim(ctt, geobounds=hur_bounds)) ax_ctt.set_ylim(cartopy_ylim(ctt, geobounds=hur_bounds))
ax_ctt.gridlines() ax_ctt.gridlines(color="white", linestyle="dotted")
# Make the contour plot for wspd # Make the contour plot for wind speed
wspd_contours = ax_wspd.contourf(to_np(wspd_cross)) wspd_contours = ax_wspd.contourf(to_np(wspd_cross), cmap=get_cmap("jet"))
# Add the color bar # Add the color bar
cb_wspd = fig.colorbar(wspd_contours, ax=ax_wspd) cb_wspd = fig.colorbar(wspd_contours, ax=ax_wspd)
cb_wspd.ax.tick_params(labelsize=5) cb_wspd.ax.tick_params(labelsize=5)
# Make the contour plot for dbz # Make the contour plot for dbz
levels = [5 + 5*n for n in range(15)] levels = [5 + 5*n for n in range(15)]
dbz_contours = ax_dbz.contourf(to_np(dbz_cross), levels=levels) dbz_contours = ax_dbz.contourf(to_np(dbz_cross), levels=levels, cmap=get_cmap("jet"))
cb_dbz = fig.colorbar(dbz_contours, ax=ax_dbz) cb_dbz = fig.colorbar(dbz_contours, ax=ax_dbz)
cb_dbz.ax.tick_params(labelsize=5) cb_dbz.ax.tick_params(labelsize=5)
# Set the x-ticks to use latitude and longitude labels. # Set the x-ticks to use latitude and longitude labels
coord_pairs = to_np(dbz_cross.coords["xy_loc"]) coord_pairs = to_np(dbz_cross.coords["xy_loc"])
x_ticks = np.arange(coord_pairs.shape[0]) x_ticks = np.arange(coord_pairs.shape[0])
x_labels = [pair.latlon_str() for pair in to_np(coord_pairs)] x_labels = [pair.latlon_str() for pair in to_np(coord_pairs)]
@ -288,7 +279,7 @@ plot, see :ref:`cross_example`.
ax_dbz.set_xticks(x_ticks[::20]) ax_dbz.set_xticks(x_ticks[::20])
ax_dbz.set_xticklabels(x_labels[::20], rotation=45, fontsize=4) ax_dbz.set_xticklabels(x_labels[::20], rotation=45, fontsize=4)
# Set the y-ticks to be height. # Set the y-ticks to be height
vert_vals = to_np(dbz_cross.coords["vertical"]) vert_vals = to_np(dbz_cross.coords["vertical"])
v_ticks = np.arange(vert_vals.shape[0]) v_ticks = np.arange(vert_vals.shape[0])
ax_wspd.set_yticks(v_ticks[::20]) ax_wspd.set_yticks(v_ticks[::20])
@ -301,7 +292,7 @@ plot, see :ref:`cross_example`.
ax_wspd.set_ylabel("Height (m)", fontsize=5) ax_wspd.set_ylabel("Height (m)", fontsize=5)
ax_dbz.set_ylabel("Height (m)", fontsize=5) ax_dbz.set_ylabel("Height (m)", fontsize=5)
# Add titles # Add a title
ax_ctt.set_title("Cloud Top Temperature (degC)", {"fontsize" : 7}) ax_ctt.set_title("Cloud Top Temperature (degC)", {"fontsize" : 7})
ax_wspd.set_title("Cross-Section of Wind Speed (kt)", {"fontsize" : 7}) ax_wspd.set_title("Cross-Section of Wind Speed (kt)", {"fontsize" : 7})
ax_dbz.set_title("Cross-Section of Reflectivity (dBZ)", {"fontsize" : 7}) ax_dbz.set_title("Cross-Section of Reflectivity (dBZ)", {"fontsize" : 7})
@ -333,25 +324,27 @@ Plotting a Two-Dimensional Field
from matplotlib.cm import get_cmap from matplotlib.cm import get_cmap
from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import Basemap
from wrf import to_np, getvar, smooth2d, latlon_coords, get_basemap from wrf import to_np, getvar, smooth2d, get_basemap, latlon_coords
# Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
# Get the sea level pressure # Get the sea level pressure
slp = getvar(ncfile, "slp") slp = getvar(ncfile, "slp")
# Smooth the sea level pressure since it tends to be noisey near the mountains # Smooth the sea level pressure since it tends to be noisy near the mountains
smooth_slp = smooth2d(slp, 3) smooth_slp = smooth2d(slp, 3)
# Get the latitude and longitude coordinates # Get the latitude and longitude points
lats, lons = latlon_coords(slp) lats, lons = latlon_coords(slp)
# Get the basemap projection object # Get the basemap object
bm = get_basemap(slp) bm = get_basemap(slp)
# Create a figure that's 10x10 # Create a figure
fig = plt.figure(figsize=(10,10)) fig = plt.figure(figsize=(12,9))
# Add geographic outlines
bm.drawcoastlines(linewidth=0.25) bm.drawcoastlines(linewidth=0.25)
bm.drawstates(linewidth=0.25) bm.drawstates(linewidth=0.25)
bm.drawcountries(linewidth=0.25) bm.drawcountries(linewidth=0.25)
@ -362,12 +355,13 @@ Plotting a Two-Dimensional Field
# Draw the contours and filled contours # Draw the contours and filled contours
bm.contour(x, y, to_np(smooth_slp), 10, colors="black") bm.contour(x, y, to_np(smooth_slp), 10, colors="black")
bm.contourf(x, y, to_np(smooth_slp), 10) bm.contourf(x, y, to_np(smooth_slp), 10, cmap=get_cmap("jet"))
# Add a color bar # Add a color bar
plt.colorbar(shrink=.47) plt.colorbar(shrink=.62)
plt.title("Sea Level Pressure (hPa)") plt.title("Sea Level Pressure (hPa)")
plt.show() plt.show()
@ -387,6 +381,7 @@ Horizontal Interpolation to a Pressure Level
from wrf import getvar, interplevel, to_np, get_basemap, latlon_coords from wrf import getvar, interplevel, to_np, get_basemap, latlon_coords
# Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
# Extract the pressure, geopotential height, and wind variables # Extract the pressure, geopotential height, and wind variables
@ -405,27 +400,28 @@ Horizontal Interpolation to a Pressure Level
# Get the lat/lon coordinates # Get the lat/lon coordinates
lats, lons = latlon_coords(ht_500) lats, lons = latlon_coords(ht_500)
# Get the basemap projection object # Get the basemap object
bm = get_basemap(ht_500) bm = get_basemap(ht_500)
# Create the figure # Create the figure
fig = plt.figure(figsize=(8,8)) fig = plt.figure(figsize=(12,9))
ax = plt.axes([0.1,0.1,0.8,0.8]) ax = plt.axes()
# Get the x and y coordinates # Convert the lat/lon coordinates to x/y coordinates in the projection space
x, y = bm(to_np(lons), to_np(lats)) x, y = bm(to_np(lons), to_np(lats))
# Create the 500 hPa geopotential height contours # Add the 500 hPa geopotential height contours
levels = np.arange(520., 580., 6.) levels = np.arange(520., 580., 6.)
contours = bm.contour(x, y, to_np(ht_500), levels=levels, colors="black") contours = bm.contour(x, y, to_np(ht_500), levels=levels, colors="black")
plt.clabel(contours, inline=1, fontsize=10, fmt="%i") plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
# Wind Speed contours # Add the wind speed contours
levels = [25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 110, 120] levels = [25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 110, 120]
wspd_contours = bm.contourf(x, y, to_np(wspd_500), levels=levels, wspd_contours = bm.contourf(x, y, to_np(wspd_500), levels=levels,
cmap=get_cmap("rainbow")) cmap=get_cmap("rainbow"))
plt.colorbar(wspd_contours, ax=ax, orientation="horizontal", pad=.05) plt.colorbar(wspd_contours, ax=ax, orientation="horizontal", pad=.05)
# Add the geographic boundaries
bm.drawcoastlines(linewidth=0.25) bm.drawcoastlines(linewidth=0.25)
bm.drawstates(linewidth=0.25) bm.drawstates(linewidth=0.25)
bm.drawcountries(linewidth=0.25) bm.drawcountries(linewidth=0.25)
@ -435,9 +431,10 @@ Horizontal Interpolation to a Pressure Level
to_np(v_500[::125, ::125]), length=6) to_np(v_500[::125, ::125]), length=6)
plt.title("500 MB Height (dm), Wind Speed (kt), Barbs (kt)") plt.title("500 MB Height (dm), Wind Speed (kt), Barbs (kt)")
plt.show() plt.show()
Panel Plots from the Front Page Panel Plots from the Front Page
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -458,9 +455,8 @@ plot, see :ref:`cross_example`.
from wrf import getvar, to_np, vertcross, smooth2d, CoordPair, get_basemap, latlon_coords from wrf import getvar, to_np, vertcross, smooth2d, CoordPair, get_basemap, latlon_coords
# Open the output NetCDF file # Open the NetCDF file
filename = "/Users/ladwig/Documents/wrf_files/wrfout_d01_2016-10-07_00_00_00" ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
ncfile = Dataset(filename)
# Get the WRF variables # Get the WRF variables
slp = getvar(ncfile, "slp") slp = getvar(ncfile, "slp")
@ -475,29 +471,28 @@ plot, see :ref:`cross_example`.
start_point = CoordPair(lat=26.76, lon=-80.0) start_point = CoordPair(lat=26.76, lon=-80.0)
end_point = CoordPair(lat=26.76, lon=-77.8) end_point = CoordPair(lat=26.76, lon=-77.8)
# Compute the vertical cross-section interpolations. Also, include the lat/lon points along the cross-section # Compute the vertical cross-section interpolation. Also, include the lat/lon points along the cross-section in
# in the metadata by setting latlon to True. # the metadata by setting latlon to True.
z_cross = vertcross(Z, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True) z_cross = vertcross(Z, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True)
wspd_cross = vertcross(wspd, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True) wspd_cross = vertcross(wspd, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True)
dbz_cross = 10.0 * np.log10(z_cross) dbz_cross = 10.0 * np.log10(z_cross)
# Extract the latitude and longitude coordinate arrays # Get the latitude and longitude points
lats, lons = latlon_coords(slp) lats, lons = latlon_coords(slp)
# Create a figure that will have 3 subplots. One on the left, # Create the figure that will have 3 subplots
# two vertically stacked on the right. fig = plt.figure(figsize=(10,7))
fig = plt.figure(figsize=(8,5))
ax_ctt = fig.add_subplot(1,2,1) ax_ctt = fig.add_subplot(1,2,1)
ax_wspd = fig.add_subplot(2,2,2) ax_wspd = fig.add_subplot(2,2,2)
ax_dbz = fig.add_subplot(2,2,4) ax_dbz = fig.add_subplot(2,2,4)
# Get the basemap projection class # Get the basemap object
bm = get_basemap(slp) bm = get_basemap(slp)
# Get the x, y values # Convert the lat/lon points in to x/y points in the projection space
x, y = bm(to_np(lons), to_np(lats)) x, y = bm(to_np(lons), to_np(lats))
# Make the pressure contours. # Make the pressure contours
contour_levels = [960, 965, 970, 975, 980, 990] contour_levels = [960, 965, 970, 975, 980, 990]
c1 = bm.contour(x, y, to_np(smooth_slp), levels=contour_levels, colors="white", c1 = bm.contour(x, y, to_np(smooth_slp), levels=contour_levels, colors="white",
zorder=3, linewidths=1.0, ax=ax_ctt) zorder=3, linewidths=1.0, ax=ax_ctt)
@ -511,12 +506,11 @@ plot, see :ref:`cross_example`.
bm.plot([point_x[0], point_x[1]], [point_y[0], point_y[1]], color="yellow", bm.plot([point_x[0], point_x[1]], [point_y[0], point_y[1]], color="yellow",
marker="o", zorder=3, ax=ax_ctt) marker="o", zorder=3, ax=ax_ctt)
# Create the label bar for cloud top temperature # Create the color bar for cloud top temperature
cb_ctt = fig.colorbar(ctt_contours, ax=ax_ctt, shrink=.68) cb_ctt = fig.colorbar(ctt_contours, ax=ax_ctt, shrink=.60)
cb_ctt.ax.tick_params(labelsize=5) cb_ctt.ax.tick_params(labelsize=5)
# Draw the oceans, land, and states. Use the same colors as the cartopy # Draw the oceans, land, and states
# example
bm.drawcoastlines(linewidth=0.25, ax=ax_ctt) bm.drawcoastlines(linewidth=0.25, ax=ax_ctt)
bm.drawstates(linewidth=0.25, ax=ax_ctt) bm.drawstates(linewidth=0.25, ax=ax_ctt)
bm.drawcountries(linewidth=0.25, ax=ax_ctt) bm.drawcountries(linewidth=0.25, ax=ax_ctt)
@ -526,13 +520,12 @@ plot, see :ref:`cross_example`.
# Draw Parallels # Draw Parallels
parallels = np.arange(np.amin(lats), 30., 2.5) parallels = np.arange(np.amin(lats), 30., 2.5)
bm.drawparallels(parallels, ax=ax_ctt) bm.drawparallels(parallels, ax=ax_ctt, color="white")
merids = np.arange(-85.0, -72.0, 2.5) merids = np.arange(-85.0, -72.0, 2.5)
bm.drawmeridians(merids, ax=ax_ctt) bm.drawmeridians(merids, ax=ax_ctt, color="white")
# Get the x and y coordinate ranges for the cropped region around the # Crop the image to the hurricane region
# hurricane
x_start, y_start = bm(-85.0, np.amin(lats)) x_start, y_start = bm(-85.0, np.amin(lats))
x_end, y_end = bm(-72.0, 30.0) x_end, y_end = bm(-72.0, 30.0)
@ -540,14 +533,14 @@ plot, see :ref:`cross_example`.
ax_ctt.set_ylim([y_start, y_end]) ax_ctt.set_ylim([y_start, y_end])
# Make the contour plot for wspd # Make the contour plot for wspd
wspd_contours = ax_wspd.contourf(to_np(wspd_cross)) wspd_contours = ax_wspd.contourf(to_np(wspd_cross), cmap=get_cmap("jet"))
# Add the color bar # Add the color bar
cb_wspd = fig.colorbar(wspd_contours, ax=ax_wspd) cb_wspd = fig.colorbar(wspd_contours, ax=ax_wspd)
cb_wspd.ax.tick_params(labelsize=5) cb_wspd.ax.tick_params(labelsize=5)
# Make the contour plot for dbz # Make the contour plot for dbz
levels = [5 + 5*n for n in range(15)] levels = [5 + 5*n for n in range(15)]
dbz_contours = ax_dbz.contourf(to_np(dbz_cross), levels=levels) dbz_contours = ax_dbz.contourf(to_np(dbz_cross), levels=levels, cmap=get_cmap("jet"))
cb_dbz = fig.colorbar(dbz_contours, ax=ax_dbz) cb_dbz = fig.colorbar(dbz_contours, ax=ax_dbz)
cb_dbz.ax.tick_params(labelsize=5) cb_dbz.ax.tick_params(labelsize=5)
@ -573,7 +566,7 @@ plot, see :ref:`cross_example`.
ax_wspd.set_ylabel("Height (m)", fontsize=5) ax_wspd.set_ylabel("Height (m)", fontsize=5)
ax_dbz.set_ylabel("Height (m)", fontsize=5) ax_dbz.set_ylabel("Height (m)", fontsize=5)
# Add a title # Add titles
ax_ctt.set_title("Cloud Top Temperature (degC)", {"fontsize" : 7}) ax_ctt.set_title("Cloud Top Temperature (degC)", {"fontsize" : 7})
ax_wspd.set_title("Cross-Section of Wind Speed (kt)", {"fontsize" : 7}) ax_wspd.set_title("Cross-Section of Wind Speed (kt)", {"fontsize" : 7})
ax_dbz.set_title("Cross-Section of Reflectivity (dBZ)", {"fontsize" : 7}) ax_dbz.set_title("Cross-Section of Reflectivity (dBZ)", {"fontsize" : 7})
@ -598,34 +591,34 @@ plotted using the standard matplotlib API.
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap from matplotlib.cm import get_cmap
import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature
from netCDF4 import Dataset from netCDF4 import Dataset
from wrf import to_np, getvar, CoordPair, vertcross from wrf import to_np, getvar, CoordPair, vertcross
# Open the output NetCDF file with PyNIO # Open the NetCDF file
filename = "wrfout_d01_2016-10-07_00_00_00" filename = "wrfout_d01_2016-10-07_00_00_00"
ncfile = Dataset(filename) ncfile = Dataset(filename)
# Extract pressure and model height # Extract the model height and wind speed
z = getvar(ncfile, "z") z = getvar(ncfile, "z")
wspd = getvar(ncfile, "uvmet_wspd_wdir", units="kt")[0,:] wspd = getvar(ncfile, "uvmet_wspd_wdir", units="kt")[0,:]
# Define the start point and end point for the cross section using # Create the start point and end point for the cross section
# latitude and longitude coordinates.
start_point = CoordPair(lat=26.76, lon=-80.0) start_point = CoordPair(lat=26.76, lon=-80.0)
end_point = CoordPair(lat=26.76, lon=-77.8) end_point = CoordPair(lat=26.76, lon=-77.8)
# Compute the vertical cross-section interpolation. Also, include the lat/lon # Compute the vertical cross-section interpolation. Also, include the lat/lon points along the cross-section.
# points along the cross-section in the metadata by setting latlon to True. wspd_cross = vertcross(wspd, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True)
wspd_cross = vertcross(wspd, z, wrfin=ncfile, start_point=start_point,
end_point=end_point, latlon=True, meta=True)
# Create the figure # Create the figure
fig = plt.figure(figsize=(10,5)) fig = plt.figure(figsize=(12,6))
ax = plt.axes([0.1,0.1,0.8,0.8]) ax = plt.axes()
# Make the contour plot # Make the contour plot
wspd_contours = ax.contourf(to_np(wspd_cross)) wspd_contours = ax.contourf(to_np(wspd_cross), cmap=get_cmap("jet"))
# Add the color bar # Add the color bar
plt.colorbar(wspd_contours, ax=ax) plt.colorbar(wspd_contours, ax=ax)

2
requirements.txt

@ -1,2 +1,2 @@
numpy>=1.9.0 numpy>=1.10
wrapt>=1.10 wrapt>=1.10

2
setup.py

@ -55,7 +55,7 @@ numpy.distutils.core.setup(
"GitHub Repository:\n\n" "GitHub Repository:\n\n"
"https://github.com/NCAR/wrf-python\n\n" "https://github.com/NCAR/wrf-python\n\n"
"Documentation:\n\n" "Documentation:\n\n"
"https://wrf-python.readthedocs.io\n"), "https://wrf-python.rtfd.org\n"),
url = "https://github.com/NCAR/wrf-python", url = "https://github.com/NCAR/wrf-python",
keywords = ["python", "wrf-python", "wrf", "forecast", "model", keywords = ["python", "wrf-python", "wrf", "forecast", "model",
"weather research and forecasting", "interpolation", "weather research and forecasting", "interpolation",

2
src/wrf/version.py

@ -1,2 +1,2 @@
__version__ = "1.0b1" __version__ = "1.0b2"

418
test/ipynb/Doc_Examples.ipynb

File diff suppressed because one or more lines are too long

125
test/ipynb/SLS_Example.ipynb

@ -0,0 +1,125 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"from __future__ import (absolute_import, division, print_function, unicode_literals)\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.cm import get_cmap\n",
"import cartopy.crs as crs\n",
"import cartopy.feature as cfeature\n",
"from netCDF4 import Dataset as nc\n",
"\n",
"from wrf import to_np, getvar, smooth2d\n",
"\n",
"# Open the output NetCDF with netcdf-python\n",
"filename = \"/Users/ladwig/Documents/wrf_files/wrfout_d01_2016-10-07_00_00_00\"\n",
"ncfile = nc(filename)\n",
"\n",
"# Get sea level pressure and cloud top temperature\n",
"slp = getvar(ncfile, \"slp\")\n",
"ctt = getvar(ncfile, \"ctt\")\n",
"\n",
"print (ctt)\n",
"\n",
"# Smooth the SLP\n",
"smooth_slp = smooth2d(slp, 3)\n",
"\n",
"# Extract the latitude and longitude coordinate arrays as regular numpy array instead of xarray.DataArray\n",
"lons = ctt.coords[\"XLONG\"]\n",
"lats = ctt.coords[\"XLAT\"]\n",
"\n",
"# Get the cartopy projection class\n",
"wrf_proj = slp.attrs[\"projection\"]\n",
"cart_proj = wrf_proj.cartopy()\n",
"\n",
"# Create the figure\n",
"fig = plt.figure(figsize=(8,8))\n",
"ax = plt.axes([0.1,0.1,0.8,0.8], projection=cart_proj)\n",
"\n",
"# Download and create the states, land, and oceans using cartopy features\n",
"states = cfeature.NaturalEarthFeature(category='cultural', scale='50m', facecolor='none',\n",
" name='admin_1_states_provinces_shp')\n",
"land = cfeature.NaturalEarthFeature(category='physical', name='land', scale='50m', \n",
" facecolor=cfeature.COLORS['land'])\n",
"ocean = cfeature.NaturalEarthFeature(category='physical', name='ocean', scale='50m', \n",
" facecolor=cfeature.COLORS['water'])\n",
"\n",
"# Make the pressure contours.\n",
"#contour_levels = [960, 962, 965, 967, 970, 975, 980, 985, 990, 995]\n",
"#c1 = plt.contour(lons, lats, to_np(smooth_slp), levels=contour_levels, colors=\"white\", \n",
"# transform=crs.PlateCarree(), zorder=3, linewidth=1.3)\n",
"\n",
"# Add pressure contour labels\n",
"#plt.clabel(c1, contour_levels, inline=True, fmt='%1.1f', fontsize=8)\n",
"\n",
"# Create the filled cloud top temperature contours\n",
"#contour_levels = [-80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30]\n",
"contour_levels = np.arange(-80.0, 10.0, 10.0)\n",
"plt.contourf(to_np(lons), to_np(lats), to_np(ctt), contour_levels, cmap=get_cmap(\"Greys\"),\n",
" transform=crs.PlateCarree(), zorder=2)\n",
"\n",
"# Create the label bar for cloud top temperature\n",
"cb2 = plt.colorbar(ax=ax, shrink=.80)\n",
"\n",
"# Draw the oceans, land, and states\n",
"ax.add_feature(ocean)\n",
"ax.add_feature(land)\n",
"ax.add_feature(states, linewidth=.5, edgecolor=\"black\")\n",
"\n",
"# Crop the domain to the region around the hurricane\n",
"ax.set_extent([-85., -75.0, np.amin(lats), 30.0], crs=crs.PlateCarree())\n",
"# Set the map limits\n",
"#ax.set_xlim(wrf_proj.cartopy_xlim())\n",
"#ax.set_ylim(wrf_proj.cartopy_ylim())\n",
"\n",
"ax.gridlines(crs=crs.PlateCarree(), draw_labels=False)\n",
"\n",
"# Add the title and show the image\n",
"#plt.title(\"Hurricane Matthew Cloud Top Temperature (degC) and Sea Level Pressure (hPa)\")\n",
"#plt.title(\"Hurricane Matthew Cloud Top Temperature (degC)\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

19
test/ipynb/WRF_Workshop_Demo.ipynb

@ -69,7 +69,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -81,24 +81,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": false
}, },
"outputs": [ "outputs": [],
{
"ename": "NIOError",
"evalue": "Unable to open file",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNIOError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-9e6cb63ecf8c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mfilename\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"wrfout_d01_2010-06-13_21-00-00\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mpynio_filename\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfilename\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\".nc\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mncfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen_file\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpynio_filename\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;31m# Alternative using netCDF4-python (for reference)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/Users/ladwig/miniconda2/lib/python2.7/site-packages/PyNIO/Nio.pyc\u001b[0m in \u001b[0;36mopen_file\u001b[0;34m(filename, mode, options, history, format)\u001b[0m\n\u001b[1;32m 733\u001b[0m \u001b[0mmask_above_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_option_value\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0m_Nio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moption_defaults\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'MaskAboveValue'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 734\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 735\u001b[0;31m \u001b[0mfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_Nio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen_file\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mhistory\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 736\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 737\u001b[0m \u001b[0mfile_proxy\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_proxy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfile\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m__del__\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m__del__\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcreate_variable\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcreate_variable\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcreate_group\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcreate_group\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNIOError\u001b[0m: Unable to open file"
]
}
],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",

18702
test/ipynb/WRF_python_demo.ipynb

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save