Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update develop-ref after #1800 #1808

Merged
merged 172 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
ebddb56
Start on write netcdf pickle alternative.
Jan 26, 2021
0fdbfdd
Write dataplane array.
Jan 26, 2021
6d46603
Start on read of netcdf as pickle alternative.
Jan 26, 2021
6fe4245
Create attribute variables.
Feb 2, 2021
644db21
Use global attributes for met_info attrs.
Feb 3, 2021
6594062
Add grid structure.
Feb 4, 2021
c6667e3
Read metadata back into met_info.attrs.
Feb 4, 2021
1e6eb9e
Convert grid.nx and grid.ny to int.
Feb 4, 2021
e005585
Rename _name key to name.
Feb 4, 2021
ab986ca
Removed pickle write.
Feb 4, 2021
760b690
Fixed write_pickle_dataplane to work for both numpy and xarray.
Feb 5, 2021
791ebf0
Use items() to iterate of key, value attrs.
Feb 5, 2021
c5f17e8
Write temporary text file.
Feb 13, 2021
d6142e8
Renamed scripts.
Feb 17, 2021
b39ca28
Changed script names in Makefile.am.
Feb 17, 2021
7cc2d77
Replaced pickle with tmp_nc.
Feb 17, 2021
df0db18
Fixed wrapper script names.
Feb 17, 2021
044c704
Test for attrs in met_in.met_data.
Feb 17, 2021
d798e9d
Initial version of read_tmp_point module.
Feb 18, 2021
8116e75
Added read_tmp_point.py to install list.
Feb 18, 2021
7b57715
Start on Python3_Script::read_tmp_point.
Feb 18, 2021
5502da9
Write MPR tmp ascii file.
Feb 18, 2021
961b4fc
Renamed to read_tmp_ascii to use for point point and MPR.
Feb 18, 2021
4c0963d
Renamed to read_tmp_ascii to use for point point and MPR.
Feb 18, 2021
91122be
Define Python3_Script::import_read_tmp_ascii_py.
Feb 19, 2021
fef8484
Call Python3_Script::import_read_tmp_ascii_py.
Feb 19, 2021
93e9762
Append MET_BASE/wrappers to sys.path.
Feb 20, 2021
44d8328
Finished implementation of Python3_Script::import_read_tmp_ascii_py.
Feb 20, 2021
3953aba
Call Python3_Script::read_tmp_ascii in python_handler.
Feb 20, 2021
25961d6
Revised python3_script::read_tmp_ascii with call to run, PyRun_String.
Feb 22, 2021
794e8fb
Return PyObject* from Python3_Script::run.
Feb 22, 2021
d569cfb
Restored call to run_python_string for now.
Feb 22, 2021
ab0f2c6
Per #1429, enhance error message from DataLine::get_item(). (#1682)
JohnHalleyGotway Feb 26, 2021
b2754b4
Feature 1429 tc_log second try (#1686)
JohnHalleyGotway Feb 26, 2021
a1aead4
Feature 1588 ps_log (#1687)
JohnHalleyGotway Feb 26, 2021
2ba6cd9
#1454 Disabled plot_data_plane_CESM_SSMI_microwave and plot_data_plan…
Feb 26, 2021
fe5f318
#1454 Moved NC attribute name to nc_utils.h
Feb 26, 2021
c1463b2
#1454 Corrected sanity checking for lat/lon projection based on the p…
Feb 26, 2021
ac4d7f9
#1454 Corrected sanity checking for lat/lon projection based on the p…
Feb 26, 2021
371dd2c
#1454 Corrected data.delta_lon
Mar 1, 2021
24c2bd8
#1454 Change bact to use diff instead of absolute value of diff
Mar 1, 2021
e224ce1
454 Deleted instea dof commenting out
Mar 1, 2021
c8e9049
454 Deleted instea dof commenting out
Mar 1, 2021
0f5366c
Merge pull request #1688 from dtcenter/feature_1454_nccf_grid_definition
hsoh-u Mar 1, 2021
996197c
Feature 1684 bss and 1685 single reference model (#1689)
JohnHalleyGotway Mar 2, 2021
40b57af
Per #1691, add met-10.0.0-beta4 release notes. (#1692)
JohnHalleyGotway Mar 2, 2021
23dc482
Updated Python documentation
jprestop Mar 3, 2021
9c9c54c
Per #1694, add VarInfo::magic_str_attr() to construct a field summary…
JohnHalleyGotway Mar 4, 2021
a16bebc
Per #1694, fixing 2 issues here. There was a bug in the computation o…
JohnHalleyGotway Mar 4, 2021
21e3eb7
Per #1694, just switching to consistent variable name.
JohnHalleyGotway Mar 5, 2021
0f84a5a
Just consistent spacing.
JohnHalleyGotway Mar 5, 2021
5f551d2
Merge pull request #1696 from dtcenter/bugfix_1694_grid_diag
davidfillmore Mar 5, 2021
f21b2e6
Added python3_script::import_read_tmp_ascii.
Mar 5, 2021
ba85a46
Merge branch 'develop' into feature_1319_no_pickle
Mar 5, 2021
31ae2e4
Restored read_tmp_ascii call.
Mar 5, 2021
f8becb9
Added lookup into ascii module.
Mar 5, 2021
9224844
Adding files for ReadTheDocs
jprestop Mar 5, 2021
1b41a0a
Adding .yaml file for ReadTheDocs
jprestop Mar 5, 2021
8382b33
Updated path to requirements.txt file
jprestop Mar 5, 2021
0303f1f
Updated path to conf.py file
jprestop Mar 5, 2021
99a6363
Removing ReadTheDocs files and working in separate branch
jprestop Mar 5, 2021
b0c8813
Return PyObject* from read_tmp_ascii.
Mar 7, 2021
bd9ed77
Put point_data in global namespace.
Mar 7, 2021
b358bed
Remove temporary ascii file.
Mar 7, 2021
4506173
Added tmp_ascii_path.
Mar 7, 2021
d6ed4b9
Removed read_obs_from_pickle.
Mar 7, 2021
592c937
Trying different options for formats (#1702)
jprestop Mar 9, 2021
d80aafa
Per #1706, add bugfix to the develop branch. Also add a new job to un…
JohnHalleyGotway Mar 10, 2021
6ed8fc4
Feature 1471 python_grid (#1704)
JohnHalleyGotway Mar 10, 2021
0f08b74
Committing a fix for unit_python.xml directly to the develop branch. …
Mar 11, 2021
2b5e37f
Merge branch 'develop-ref' into develop
JohnHalleyGotway Mar 11, 2021
48bb906
Add *.dSYM to the .gitignore files in the src and internal_tests dire…
JohnHalleyGotway Mar 11, 2021
6568493
Replaced tmp netcdf _name attribute with name_str.
Mar 12, 2021
22f5e98
Append user script path to system path.
Mar 15, 2021
18fb169
Merge pull request #1699 from dtcenter/feature_1319_no_pickle
davidfillmore Mar 15, 2021
dee5d3b
Revert "Feature 1319 no pickle" (#1717)
JohnHalleyGotway Mar 15, 2021
92f0ff0
Fixed typos, added content, and modified release date format
jprestop Mar 17, 2021
40fce11
#1715 Initial release
Mar 18, 2021
1ac92d7
#1715 Do not combined if there are no overlapping beteewn TQZ and UV …
Mar 18, 2021
9a97135
#1715 Added pb2nc_compute_pbl_cape
Mar 18, 2021
edb124b
#1715 Added pb2nc_compute_pbl_cape
Mar 18, 2021
aefabdb
#1715 Reduced obs_bufr_var. Removed pb_report_type
Mar 18, 2021
b7fb7c1
#1715 Added a blank line for Error/Warning
Mar 18, 2021
7998d89
Merge pull request #1719 from dtcenter/bugfix_1715_pb2nc_seg_fault_wi…
hsoh-u Mar 18, 2021
8dbef78
Per #1725, return good status from TrackInfoArray::add() when using a…
JohnHalleyGotway Mar 19, 2021
5866b2a
Per #1705, update the threshold node heirarchy by adding a climo_prob…
JohnHalleyGotway Mar 19, 2021
1a9f73a
Bugfix 1716 develop perc_thresh (#1722)
JohnHalleyGotway Mar 19, 2021
8dfd7c0
Update pull_request_template.md
JohnHalleyGotway Mar 19, 2021
e2f77e4
Feature 1733 exc (#1734)
JohnHalleyGotway Mar 29, 2021
6055600
Bugfix 1737 develop little_r (#1739)
JohnHalleyGotway Mar 30, 2021
804b1ac
Feature GitHub actions (#1742)
jprestop Apr 1, 2021
853ad34
Feature 1575 large_diffs (#1741)
JohnHalleyGotway Apr 1, 2021
d26e62d
Feature 1319 no pickle (#1720)
davidfillmore Apr 2, 2021
9e6613e
Feature 1736 out_stat (#1744)
JohnHalleyGotway Apr 4, 2021
338c6e2
Per #1319, this is a hotfix to the develop branch. While running unit…
Apr 4, 2021
4b7b768
Merge branch 'develop' of https://github.com/dtcenter/MET into develop
Apr 4, 2021
69f5b5c
Just lining up a log message in the output of gen_vx_mask.
Apr 5, 2021
dd22521
Per #1319, setting PATH as an envvar might cause problems. All variab…
Apr 5, 2021
e18f0b5
Trying to get the PATH setting correct for unit_python.xml.
Apr 5, 2021
1bafac0
Changed weblink for METplus documentation
jprestop Apr 5, 2021
9a9bbc7
per #1319 added netCDF4 python package to MET docker image so it is a…
georgemccabe Apr 5, 2021
1757cb1
Feature 1747 pylonglong (#1748)
JohnHalleyGotway Apr 6, 2021
acf97fc
Hotfix for the develop branch in tc_pairs.cc. The METplus unit tests …
Apr 7, 2021
c06e6da
Turned specific section numbers into linked sections because section …
jprestop Apr 9, 2021
b92a6f6
Removed hard-coded references to section numbers
jprestop Apr 9, 2021
11866b3
Feature 1714 tc_gen (#1750)
JohnHalleyGotway Apr 9, 2021
5ba033c
Merge branch 'develop-ref' into develop
JohnHalleyGotway Apr 12, 2021
a2bad6c
feature_1552_gcc_10 (#1752)
jprestop Apr 14, 2021
aa02a0e
#1755 Support time string for slicing at MetNcCFDataFile::collect_tim…
Apr 15, 2021
800bfa1
#1755 Support time string for slicing at MetNcCFDataFile::collect_tim…
Apr 15, 2021
3c170e9
Merge pull request #1756 from dtcenter/bugfix_1755_nccf_timelevel_by_…
hsoh-u Apr 15, 2021
c3329cd
Feature 1735 stat_analysis (#1754)
JohnHalleyGotway Apr 16, 2021
909c80b
Per #1753, this one change to write_tmp_data.py solves this problem. …
Apr 16, 2021
ad553d7
Per #1753, make the read_tmp_dataplane.py script less verbose.
Apr 16, 2021
e4134ab
Per #1753, there are 3 calls to the user's python version throughout …
Apr 16, 2021
8ab5382
Merge remote-tracking branch 'origin/develop' into feature_1753_pytho…
Apr 16, 2021
68e96be
Merge branch 'feature_1753_python_fill' into develop
Apr 16, 2021
7b0a8d0
Per #1753, wrap the call to get_fill_value() in a try block in case t…
Apr 16, 2021
55aa8f7
Per #1620, correct bug in read_ascii_mpr.py script. The MPR line type…
JohnHalleyGotway Apr 22, 2021
9d8ee06
Feature 1700 python (#1765)
JohnHalleyGotway Apr 26, 2021
43247de
Feature 1766 v10.0.0_beta5 (#1767)
JohnHalleyGotway Apr 26, 2021
e0004da
Merge branch 'develop-ref' into develop
JohnHalleyGotway Apr 27, 2021
ddf29e0
Bugfix 1768 edeck (#1769)
JohnHalleyGotway Apr 27, 2021
9190a29
Feature 1771 release_notes (#1772)
JohnHalleyGotway Apr 28, 2021
205c4a8
Committing hotfix to the develop branch to fix a bad merge that cause…
JohnHalleyGotway Apr 28, 2021
b32edba
Update compile_MET_all.sh
jprestop Apr 29, 2021
30417be
Update pull_request_template.md
jprestop May 3, 2021
cfe37ea
Per #1731, add ioda2nc documentation.
JohnHalleyGotway May 3, 2021
5201e14
Changes to make the authorship list consistent with METplus.
JohnHalleyGotway May 4, 2021
d6618d6
Rename CIR to CIRA.
JohnHalleyGotway May 4, 2021
bb9f18e
Per #1731, fix alignment issued caused by tabs vs spaces.
JohnHalleyGotway May 5, 2021
01bdecb
Per #1777, fixing memory management in DbfHeader::set_subrecords(). I…
JohnHalleyGotway May 5, 2021
e45c8dd
Feature 1731 authorship (#1776)
JohnHalleyGotway May 5, 2021
4427233
Updated input sources to include newly acceptable data formats
j-opatz May 7, 2021
278e57b
Per #1731, add more details about the grid-diag bin definition.
JohnHalleyGotway May 7, 2021
ebf7d8b
Merge branch 'feature_1731_docs' of https://github.com/dtcenter/MET i…
JohnHalleyGotway May 7, 2021
a8d2a99
Per #1731, clarify wording.
JohnHalleyGotway May 7, 2021
200897e
Update met/docs/Users_Guide/tc-pairs.rst
j-opatz May 7, 2021
3978109
Changes to align Xarray language with that used in Xarray documentati…
DanielAdriaansen May 7, 2021
c13bc9e
Corrects plural of DataArray.
DanielAdriaansen May 7, 2021
4ef85f9
Aligns references to NumPy arrays with NumPy docs to refer to them as…
DanielAdriaansen May 7, 2021
3a914ef
Fixes formatting of note for Xarray.
DanielAdriaansen May 7, 2021
82532cb
Update met/docs/Users_Guide/tc-pairs.rst
j-opatz May 7, 2021
8568cd3
Fixes hyperlink reference.
DanielAdriaansen May 7, 2021
4da81e2
Fixes line spacing in note directive.
DanielAdriaansen May 7, 2021
d0512c1
Changes to reference again.
DanielAdriaansen May 7, 2021
d0bd336
#1782 Set the time offset to 0 if the time dimension does not exist a…
May 7, 2021
e376795
Updates to link and note directive.
DanielAdriaansen May 7, 2021
9d1c71e
Corrects plural of DataArray once more.
DanielAdriaansen May 7, 2021
ee10119
Adds more clarity to NumPy heading.
DanielAdriaansen May 7, 2021
560995b
Adds bold for emphasis.
DanielAdriaansen May 7, 2021
35bfce7
Removes bold in note directive.
DanielAdriaansen May 7, 2021
649a51b
Merge pull request #1784 from dtcenter/feature_1468_pyembed_docs
DanielAdriaansen May 7, 2021
a56f1ee
Merge pull request #1781 from dtcenter/feature_1731_docs
j-opatz May 7, 2021
6c9b78e
Merge pull request #1783 from dtcenter/bugfix_1782_point_stat_NCCF
hsoh-u May 7, 2021
50b77c0
Feature 1778 debug (#1785)
JohnHalleyGotway May 8, 2021
d39433e
Made suggested changes by Tara Jensen
jprestop May 10, 2021
1e50cd2
Update python embedding docs to list required packages for the base p…
JohnHalleyGotway May 10, 2021
3b7b7fe
Feature 1786 v10.0.0 (#1787)
JohnHalleyGotway May 10, 2021
7283fb3
Per #1789, remove duplicate plot_point_obs configuration section. (#1…
JohnHalleyGotway May 12, 2021
a0dcfd9
Update the version of Fortify on kiowa from 19.2.0 to 20.2.1.
May 14, 2021
9a242f5
#1795 Release memory at time_values
May 20, 2021
754889b
Bugfix 1798 develop py_grid_string (#1800)
JohnHalleyGotway May 20, 2021
fa51ade
#1794 Corrected the offset for Filter
May 20, 2021
c2ab531
Github Issue #1801: Comment out code that checks for BEST track to su…
bikegeek May 20, 2021
8d9128c
#1795 Cleanup
May 21, 2021
c8449c3
#1795 Create DataCube for 2D or 3D only, not both to avoid memory leak
May 21, 2021
564c657
Bugfix 1395 develop comp script (#1804)
jprestop May 21, 2021
7a88a83
Gitub Issue #1801 Remove code that checks for -bmodel filter to suppo…
bikegeek May 21, 2021
385088d
Merge pull request #1806 from dtcenter/task_1801_dev_plot_tcmpr
bikegeek May 21, 2021
3cb3f0e
Merge pull request #1802 from dtcenter/bugfix_1795_fortify_nccf
hsoh-u May 21, 2021
f1dcd76
Merge branch 'develop-ref' into develop
JohnHalleyGotway May 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- [ ] Will this PR result in changes to the test suite? **[Yes or No]**</br>
If **yes**, describe the new output and/or changes to the existing output:</br>

- [ ] Please complete this pull request review by **[Fill in date]**.</br>

## Pull Request Checklist ##
See the [METplus Workflow](https://dtcenter.github.io/METplus/Contributors_Guide/github_workflow.html) for details.
- [ ] Complete the PR definition above.
Expand Down
8 changes: 4 additions & 4 deletions met/README
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ This is the main directory for the Model Evaluation Tools source code release.
================================================================================

For questions, please:
- Refer to the MET User's Guide in the /doc sub-directory.
- Refer to the MET website: http://www.dtcenter.org/met/users
- Refer to the MET User's Guide: https://met.readthedocs.io/en/latest
- Refer to the MET website: http://dtcenter.org/community-code/model-evaluation-tools-met
- Send mail to met_help@ucar.edu.

Dependencies
Expand Down Expand Up @@ -52,7 +52,7 @@ Dependencies

- It is suggested that the following tools be used in conjunction with MET:
- Unified Post-Processor
- http://www.dtcenter.org/wrf-nmm/users
- http://dtcenter.org/community-code/unified-post-processor-upp

NOTE: The required libraries should be compiled with the same set of compilers
to be used in compiling MET.
Expand All @@ -63,7 +63,7 @@ How to compile and run?
For more detailed instructions on building MET and for a list of supported
platforms and compilers, please refer to the MET User's Guide in the doc/
sub-directory, or the MET Online Tutorial:
http://www.dtcenter.org/met/users/support/online_tutorial
http://dtcenter.org/community-code/model-evaluation-tools-met/online-tutorial

- Set the $CXX and $F77 environment variables to specify the C++ and FORTRAN
compilers to be used. If not set, configure will search for compilers and the
Expand Down
13 changes: 8 additions & 5 deletions met/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([MET], [m4_esyscmd_s(echo ${MET_BUILD_VERSION:-8.1})], [met_help@ucar.edu], [], [http://www.dtcenter.org/met/users])
AC_INIT([MET], [m4_esyscmd_s(echo ${MET_BUILD_VERSION:-development})], [met_help@ucar.edu], [], [http://dtcenter.org/community-code/model-evaluation-tools-met])
AC_CONFIG_SRCDIR([src/tools/tc_utils/tc_dland/tc_dland.cc])
AC_CONFIG_HEADERS([config.h])

Expand Down Expand Up @@ -1041,11 +1041,14 @@ CPPFLAGS=$CPPFLAGS' -DMET_BASE="\"$(pkgdatadir)\""'

AC_SUBST(FC_LIBS, [-lgfortran])

# The CXXFLAGS default to "-O2 -g". The optimization is causing
# problems so just set it to "-g" if the user hasn't overridden it
# themselves.
# For GNU compilers, CFLAGS, CXXFLAGS, and FFLAGS default to "-O2 -g".
# The CXXFLAGS "-O2" optimization has caused problems in the past.
# For Intel compilers, "-g" slows down runtimes considerably (MET #1778).
# For development, retain the "-g" option. Otherwise, discard it.

: ${CXXFLAGS="-g"}
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CFLAGS="-g -O2"}], [: ${CFLAGS="-O2"}])
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CXXFLAGS="-g"} ], [: ${CXXFLAGS=""}] )
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${FFLAGS="-g -O2"}], [: ${FFLAGS="-O2"}])

# Checks for programs.

Expand Down
9 changes: 7 additions & 2 deletions met/data/wrappers/read_tmp_dataplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
ds = nc.Dataset(netcdf_filename, 'r')
met_data = ds['met_data'][:]
met_attrs = {}

# grid is defined as a dictionary or string
grid = {}
for attr, attr_val in ds.__dict__.items():
if 'grid' in attr:
if 'grid.' in attr:
grid_attr = attr.split('.')[1]
grid[grid_attr] = attr_val
else:
met_attrs[attr] = attr_val
met_attrs['grid'] = grid

if grid:
met_attrs['grid'] = grid

met_attrs['name'] = met_attrs['name_str']
del met_attrs['name_str']
met_info['met_data'] = met_data
Expand Down
Binary file modified met/docs/Flowchart/MET_flowchart.pptx
Binary file not shown.
Binary file added met/docs/Flowchart/MET_flowchart_v10.0.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 19 additions & 8 deletions met/docs/Users_Guide/appendixF.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ Appendix F Python Embedding
Introduction
____________

MET includes the ability to embed Python to a limited degree. Users may use Python scripts and whatever associated Python packages they wish in order to prepare 2D gridded data fields, point observations, and matched pairs as input to the MET tools. We fully expect that this degree of embedding will increase in the future. In addition, plans are in place to extend Python with MET in upcoming releases, allowing users to invoke MET tools directly from their Python script. While MET version 8.0 was built on Python 2.x, MET version 9.0 is built on Python 3.6+.
MET includes the ability to embed Python to a limited degree. Users may use Python scripts and whatever associated Python packages they wish in order to prepare 2D gridded data fields, point observations, and matched pairs as input to the MET tools. We fully expect that this degree of embedding will increase in the future. In addition, plans are in place to extend Python with MET in upcoming releases, allowing users to invoke MET tools directly from their Python script. While MET version 8.0 was built on Python 2.x, MET versions 9.0 and beyond are built on Python 3.6+.

Compiling Python Support
________________________

In order to use Python embedding, the user's local Python installation must have the C-language Python header files and libraries. Sometimes when Python is installed locally, these header files and libraries are deleted at the end of the installation process, leaving only the binary executable and run-time shared object files. But the Python header files and libraries must be present to compile support in MET for Python embedding. Assuming the requisite Python files are present, and that Python embedding is enabled when building MET (which is done by passing the **--enable-python** option to the **configure** command line), the MET C++ code will use these in the compilation process to link directly to the Python libraries.

The local Python installation must also support a minimum set of required packages. The MET build includes some python wrapper scripts to facilitate the passing of data in memory as well as the reading and writing of temporary files. The packages required by those wrapper scripts are **sys, os, argparse, importlib, numpy and netCDF4**. While most of these are standard packages and readily available, numpy and netCDF4 may not be. Users are advised to confirm their availability prior to compiling MET with python embedding support.

In addition to the **configure** option mentioned above, two variables, **MET_PYTHON_CC** and **MET_PYTHON_LD**, must also be set for the configuration process. These may either be set as environment variables or as command line options to **configure**. These constants are passed as compiler command line options when building MET to enable the compiler to find the requisite Python header files and libraries in the user's local filesystem. Fortunately, Python provides a way to set these variables properly. This frees the user from the necessity of having any expert knowledge of the compiling and linking process. Along with the **Python** executable, there should be another executable called **python3-config**, whose output can be used to set these environment variables as follows:

• On the command line, run “**python3-config --cflags**”. Set the value of **MET_PYTHON_CC** to the output of that command.
Expand Down Expand Up @@ -43,14 +45,16 @@ Setting this environment variable triggers slightly different processing logic i

With this approach, users should be able to execute Python scripts in their own custom environments.

.. _pyembed-2d-data:

Python Embedding for 2D data
____________________________

We now describe how to write Python scripts so that the MET tools may extract 2D gridded data fields from them. Currently, MET offers two ways to interact with Python scripts: by using NumPy arrays or by using Xarray objects. The interface to be used (NumPy or Xarray) is specified on the command line (more on this later). The user's scripts can use any Python libraries that are supported by the local Python installation, or any personal or institutional libraries or code that are desired in order to implement the Python script, so long as the data has been loaded into either a NumPy array or an Xarray object by the end of the script. This offers advantages when using data file formats that MET does not directly support. If there is Python code to read the data format, the user can use those tools to read the data, and then copy the data into a NumPy array or an Xarray object. MET can then ingest the data via the Python script. Note that whether a NumPy array or an Xarray object is used, the data should be stored as double precision floating point numbers. Using different data types, such as integers or single precision floating point numbers, will lead to unexpected results in MET.
We now describe how to write Python scripts so that the MET tools may extract 2D gridded data fields from them. Currently, MET offers two ways to interact with Python scripts: by using NumPy N-dimensional arrays (ndarrays) or by using Xarray DataArrays. The interface to be used (NumPy or Xarray) is specified on the command line (more on this later). The user's scripts can use any Python libraries that are supported by the local Python installation, or any personal or institutional libraries or code that are desired in order to implement the Python script, so long as the data has been loaded into either a NumPy ndarray or an Xarray DataArray by the end of the script. This offers advantages when using data file formats that MET does not directly support. If there is Python code to read the data format, the user can use those tools to read the data, and then copy the data into a NumPy ndarray or an Xarray DataArray. MET can then ingest the data via the Python script. Note that whether a NumPy ndarray or an Xarray DataArray is used, the data should be stored as double precision floating point numbers. Using different data types, such as integers or single precision floating point numbers, will lead to unexpected results in MET.

**Using NumPy**
**Using NumPy N-dimensional Arrays**

The data must be loaded into a 2D NumPy array named **met_data**. In addition there must be a Python dictionary named **attrs** which contains metadata such as timestamps, grid projection and other information. Here is an example **attrs** dictionary:
The data must be loaded into a 2D NumPy ndarray named **met_data**. In addition there must be a Python dictionary named **attrs** which contains metadata such as timestamps, grid projection and other information. Here is an example **attrs** dictionary:

.. code-block:: none

Expand Down Expand Up @@ -87,8 +91,7 @@ The data must be loaded into a 2D NumPy array named **met_data**. In addition th

}


In the dictionary, valid time, initialization time, lead time and accumulation time (if any) must be indicated by strings. Valid and initialization times must be given in YYYYMMDD[_HH[MMSS]] format, and lead and accumulation times must be given in HH[MMSS] format, where the square brackets indicate optional elements. The dictionary must also include strings for the name, long_name, level, and units to describe the data. The rest of the **attrs** dictionary gives the grid size and projection information in the same format that is used in the netCDF files written out by the MET tools. Those entries are also listed below. Note that the **grid** entry in the **attrs** dictionary can either be defined as a string or as a dictionary itself.
In the **attrs** dictionary, valid time, initialization time, lead time and accumulation time (if any) must be indicated by strings. Valid and initialization times must be given in YYYYMMDD[_HH[MMSS]] format, and lead and accumulation times must be given in HH[MMSS] format, where the square brackets indicate optional elements. The dictionary must also include strings for the name, long_name, level, and units to describe the data. The rest of the **attrs** dictionary gives the grid size and projection information in the same format that is used in the netCDF files written out by the MET tools. Those entries are also listed below. Note that the **grid** entry in the **attrs** dictionary can either be defined as a string or as a dictionary itself.

If specified as a string, **grid** can be defined as follows:

Expand Down Expand Up @@ -171,9 +174,17 @@ When specified as a dictionary, the contents of the **grid** dictionary vary bas

Additional information about supported grids can be found in :ref:`appendixB`.

**Using Xarray Objects**
**Using Xarray DataArrays**

To use Xarray DataArrays, a similar procedure to the NumPy case is followed. The Xarray DataArray can be represented as a NumPy N-dimensional array (ndarray) via the **values** property of the DataArray, and an **attrs** property that contains a dictionary of attributes. The user must name the Xarray DataArray to be **met_data**. When one of the MET tools runs the Python script, it will look for an Xarray DataArray named **met_data**, and will retrieve the data and metadata from the **values** and **attrs** properties, respectively, of the Xarray DataArray. The Xarray DataArray **attrs** dictionary is populated in the same way as for the NumPy interface (please see :ref:`pyembed-2d-data` for requirements of each entry in the **attrs** dictionary). The **values** NumPy ndarray property of the Xarray DataArray is also populated in the same way as the NumPy case.

.. note::
Currently, MET does not support Xarray Dataset structures. If you have a Dataset in Xarray, you can create a DataArray of a single variable using:

met_data = xr.DataArray(ds.varname,attrs=ds.attrs)

To use Xarray objects, a similar procedure to the NumPy case is followed. An Xarray object has a NumpyArray called **values**, and an attributes dictionary called **attrs**. The user must name the Xarray object to be **met_data**. When one of the MET tools runs the Python script, it will look for an Xarray object named **met_data**, and will retrieve the data and metadata from the **values** and **attrs** parts, respectively, of the Xarray object. The Xarray **attrs** dictionary is populated in the same way as for the NumPy interface. The **values** Numpy array part of the Xarray object is also populated in the same way as the NumPy case.
| ds = your Dataset name
| varname = variable name in the Dataset you'd like to use in MET

__________________

Expand Down
Loading