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

Feature 1230 stratosphere metrics #1354

Merged
merged 29 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6faee19
Initial checkin for Meridial Mean use case
Jan 8, 2022
052b0ef
Merge branch 'feature_1230_stratosphere_metrics' of ssh://github.com/…
Jan 8, 2022
286c5c8
Changed the name and directories
hankenstein2 Jan 13, 2022
8116994
Added some documentation
hankenstein2 Jan 13, 2022
9067afc
Fixed config variables
Jan 13, 2022
fdada66
Merge branch 'develop' of https://github.com/dtcenter/METplus into fe…
Jan 18, 2022
8fa83b8
Issue 1230 Stratospheric metrics (zonal/meridional use case) put INPU…
Jan 18, 2022
14982f6
Issue #1230 remove import of metplotpy-this isn't called
Jan 18, 2022
c9dfaeb
Issue #1230_stratosphere_metric Add use case to the list of use cases…
Jan 18, 2022
d294744
Issue 1230 Remove the INPUT_BASE from the user_env_vars section
Jan 19, 2022
3375c74
Issue #1230 redundant files
Jan 19, 2022
eae6687
Issue #1230 redundant files
Jan 19, 2022
bfd27c3
Issue #1230 redundant files
Jan 19, 2022
87af9f3
Issue #120 replace INPUT_BASE with INPUT_FILE_NAME
Jan 19, 2022
ca61d9c
Issue #1230 remove entry for INPUT_FILE_NAME, this goes in the system…
Jan 19, 2022
820d0c1
Update all_use_cases.txt
bikegeek Jan 19, 2022
bb03c37
Update use_case_groups.json
bikegeek Jan 19, 2022
a861c13
Issue #1230 put INPUT_FILE_NAME back under the user_env_vars
Jan 19, 2022
c5504f3
Merge branch 'feature_1230_stratosphere_metrics' of https://github.co…
Jan 19, 2022
32a6c16
Issue #1230 forgot to include the filename
Jan 19, 2022
acd0cfe
Issue #1230 clean up config file, remove uneccessary comments, group …
Jan 19, 2022
fba8e42
Issue #1230 remove extraneous and incorrect path to the input_filenam…
Jan 19, 2022
2f4836e
Removed pingouin dependency
Jan 19, 2022
ba0cbc7
Issue #1230 another cut and paste error fixed for the Stratosphere us…
Jan 19, 2022
ead149d
Issue #1230 type in name, obs_Only should be obsOnly
Jan 19, 2022
215dca9
Issue #1230 added the metdatadb to the env, code imports metdatadb an…
Jan 20, 2022
ef48837
issue #1230 removed pingouin dependency from comment to reduce any co…
Jan 20, 2022
9dba59a
issue #1230 turn off the test for the Stratosphere metrics use case
Jan 20, 2022
1b8df6a
Added use case image
Jan 21, 2022
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
5 changes: 5 additions & 0 deletions .github/parm/use_case_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
"index_list": "11",
"run": false
},
{
"category": "s2s",
"index_list": "12",
"run": false
},
{
"category": "space_weather",
"index_list": "0-1",
Expand Down
2 changes: 0 additions & 2 deletions ci/docker/docker_env/scripts/metplotpy_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# matplotlib==3.3.0
# scipy==1.5.1
# plotly==4.9.0
# pingouin==0.3.8
# cartopy==0.18.0
# eofs==1.3.0
# cmocean==2.0
Expand All @@ -34,7 +33,6 @@ conda create -y --clone ${BASE_ENV} --name ${ENV_NAME}
conda install -y --name ${ENV_NAME} -c conda-forge matplotlib==3.3.0
conda install -y --name ${ENV_NAME} -c conda-forge scipy==1.5.1
conda install -y --name ${ENV_NAME} -c conda-forge plotly==4.9.0
conda install -y --name ${ENV_NAME} -c conda-forge pingouin==0.3.8
conda install -y --name ${ENV_NAME} -c conda-forge cartopy==0.18.0
conda install -y --name ${ENV_NAME} -c conda-forge eofs==1.3.0
conda install -y --name ${ENV_NAME} -c conda-forge cmocean==2.0
Expand Down
Binary file added docs/_static/s2s-zonal_means.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"""
UserScript: Make zonal and meridonial means
========================================================================

model_applications/
s2s/
UserScript_obsERA_obsOnly_Stratosphere.py

"""

##############################################################################
# Scientific Objective
# --------------------
#
# This use case calls functions in METcalcpy to create zonal and meridonial
# means
#

##############################################################################
# Datasets
# --------
#
# SSWC_v1.0_varFull_ERAi_d20130106_s20121107_e20130307_c20160701.nc

##############################################################################
# METplus Components
# ------------------
#
# This use case runs the UserScript wrapper tool to run a user provided script,
# in this case, meridonial.py.
#

##############################################################################
# METplus Workflow
# ----------------
#
# This use case does not loop but plots the entire time period of data
#
# UserScript
# This uses data from 20130106,20121107,20130307,20160701
#
#

##############################################################################
# METplus Configuration
# ---------------------
#
# METplus first loads all of the configuration files found in parm/metplus_config,
# then it loads any configuration files passed to METplus via the command line
# with the -c option, i.e. -c parm/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere.conf
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere.conf
#

#############################################################################
# MET Configuration
# ---------------------
#
# There are no MET tools used in this use case.
#

##############################################################################
# Python Embedding
# ----------------
#
# There is no python embedding in this use case
#

##############################################################################
# Running METplus
# ---------------
#
# This use case can be run two ways:
#
# 1) Passing in meridonial_means.conf,
# then a user-specific system configuration file::
#
# run_metplus.py \
# -c /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere.conf \
# -c /path/to/user_system.conf
#
# 2) Modifying the configurations in parm/metplus_config, then passing in meridonial.conf::
#
# run_metplus.py \
# -c /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere.conf
#
# The former method is recommended. Whether you add them to a user-specific configuration file or modify the metplus_config files, the following variables must be set correctly:
#
# * **INPUT_BASE** - Path to directory where sample data tarballs are unpacked (See Datasets section to obtain tarballs). This is not required to run METplus, but it is required to run the examples in parm/use_cases
# * **OUTPUT_BASE** - Path where METplus output will be written. This must be in a location where you have write permissions
# * **MET_INSTALL_DIR** - Path to location where MET is installed locally
#
# and for the [exe] section, you will need to define the location of NON-MET executables.
# If the executable is in the user's path, METplus will find it from the name.
# If the executable is not in the path, specify the full path to the executable here (i.e. RM = /bin/rm)
# The following executables are required for performing series analysis use cases:
#
# Example User Configuration File::
#
# [dir]
# INPUT_BASE = /path/to/sample/input/data
# OUTPUT_BASE = /path/to/output/dir
# MET_INSTALL_DIR = /path/to/met-X.Y
#
# [exe]
# RM = /path/to/rm
# CUT = /path/to/cut
# TR = /path/to/tr
# NCAP2 = /path/to/ncap2
# CONVERT = /path/to/convert
# NCDUMP = /path/to/ncdump
#

##############################################################################
# Expected Output
# ---------------
#
# A successful run will output the following both to the screen and to the logfile::
#
# INFO: METplus has successfully finished running.
#

##############################################################################
# Keywords
# --------
#
# .. note::
#
# * UserScriptUseCase
# * S2SAppUseCase
#
# Navigate to the :ref:`quick-search` page to discover other similar use cases.
#
#
#
# sphinx_gallery_thumbnail_path = '_static/s2s-zonal_means.png'
1 change: 1 addition & 0 deletions internal_tests/use_cases/all_use_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Category: s2s
9:: UserScript_obsERA_obsOnly_OMI:: model_applications/s2s/UserScript_obsERA_obsOnly_OMI.conf:: spacetime_env, metdatadb
10:: UserScript_obsERA_obsOnly_RMM:: model_applications/s2s/UserScript_obsERA_obsOnly_RMM.conf:: spacetime_env, metdatadb
11:: UserScript_fcstGFS_obsERA_WeatherRegime:: model_applications/s2s/UserScript_fcstGFS_obsERA_WeatherRegime.conf:: weatherregime_env,cartopy,metplus
12:: UserScript_obsERA_obsOnly_Stratosphere:: model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere.conf:: metplotpy_env,metdatadb,metplus

Category: space_weather
0::GridStat_fcstGloTEC_obsGloTEC_vx7:: model_applications/space_weather/GridStat_fcstGloTEC_obsGloTEC_vx7.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

[config]

# time looping - options are INIT, VALID, RETRO, and REALTIME
# If set to INIT or RETRO:
# INIT_TIME_FMT, INIT_BEG, INIT_END, and INIT_INCREMENT must also be set
# If set to VALID or REALTIME:
# VALID_TIME_FMT, VALID_BEG, VALID_END, and VALID_INCREMENT must also be set
LOOP_BY = REALTIME

# %Y = 4 digit year, %m = 2 digit month, %d = 2 digit day, etc.
# see www.strftime.org for more information
# %Y%m%d%H expands to YYYYMMDDHH
VALID_TIME_FMT = %Y%m%d%H

# BLank for this usecase but the parameter still needs to be there
VALID_BEG =

# BLank for this usecase but the parameter still needs to be there
VALID_END =

# BLank for this usecase but the parameter still needs to be there
VALID_INCREMENT =

# List of forecast leads to process for each run time (init or valid)
# In hours if units are not specified
# If unset, defaults to 0 (don't loop through forecast leads)
LEAD_SEQ =

# Order of loops to process data - Options are times, processes
# Not relevant if only one item is in the PROCESS_LIST
# times = run all wrappers in the PROCESS_LIST for a single run time, then
# increment the run time and run all wrappers again until all times have
# been evaluated.
# processes = run the first wrapper in the PROCESS_LIST for all times
# specified, then repeat for the next item in the PROCESS_LIST until all
# wrappers have been run
LOOP_ORDER = processes

PROCESS_LIST = UserScript

USER_SCRIPT_RUNTIME_FREQ = RUN_ONCE

USER_SCRIPT_COMMAND = {PARM_BASE}/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere/meridonial_mean.py


[user_env_vars]
INPUT_FILE_NAME = {INPUT_BASE}/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere/SSWC_v1.0_varFull_ERAi_d20130106_s20121107_e20130307_c20160701.nc
YAML_CONFIG_NAME = {METPLUS_BASE}/parm/use_cases/model_applications/s2s/UserScript_obsERA_obsOnly_Stratosphere/meridonial_mean.yaml


LOG_FILE = "Meridonial_means.log"

LOG_LEVEL = "INFO"

OUTPUT_DIR = {OUTPUT_BASE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
These files are a use case to show how to compute meridial and zonal means

You need METcalcpy and METdatadb in your python path or your conda environment
i.e.
export PYTHONPATH=<path>/METdatadb:<path>/METcalcpy

The file SSWC_v1.0_varFull_ERAi_d20130106_s20121107_e20130307_c20160701.nc needs to be
on disk somewhere on your computer and referenced correctly in the file
meridial_mean.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3

"""
Create meridonial mean statistics

"""
import os
import sys
import logging
import yaml
import xarray as xr # http://xarray.pydata.org/
import metcalcpy.util.read_env_vars_in_config as readconfig
import metcalcpy.pre_processing.directional_means as directional_means
import METreadnc.util.read_netcdf as read_netcdf


def main():
"""
Use existing default meridonial mean config file found in METcalcpy to
grab the test file
"""


"""
Read Meridial Mean YAML configuration file
user can use their own, if none specified at the command line,
use the "default" example YAML config file, spectra_plot_coh2.py
Using a custom YAML reader so we can use environment variables
"""

try:
input_config_file = os.getenv("YAML_CONFIG_NAME","meridonial_mean.yaml")
config = readconfig.parse_config(input_config_file)
logging.info(config)
except yaml.YAMLError as exc:
logging.error(exc)

"""
Read METplus config file paramaters
"""
#input_file_name = os.environ.get("INPUT_FILE_NAME","SSWC_v1.0_varFull_ERAi_d20130106_s20121107_e20130307_c20160701.nc")
input_file = config["input_filename"]

"""
Setup logging
"""
logfile = "meridonial_mean.log"
logging_level = os.environ.get("LOG_LEVEL","logging.INFO")
logging.basicConfig(stream=logfile, level=logging_level)

"""
Read dataset
"""
try:
logging.info('Opening ' + input_file[0])
file_reader = read_netcdf.ReadNetCDF()

#file_reader returns a list of xarrays even if there is only one file requested to be read
#so we change it from a list to a single
ds = file_reader.read_into_xarray(input_file)[0]
except IOError as exc:
logging.error('Unable to open ' + input_file)
logging.error(exc)
sys.exit(1)
logging.debug(ds)
ds = ds[['uwndFull_TS','vwndFull_TS','tempFull_TS','geopFull_TS']]
ds = ds.rename({'timeEv60':'time',
'lat':'latitude', # pyzome currently expects dimensions named latitude and longitude
'lon':'longitude',
'uwndFull_TS':'u',
'vwndFull_TS':'v',
'tempFull_TS':'T',
'geopFull_TS':'Z'})

uzm = directional_means.zonal_mean(ds.u)
Tzm = directional_means.zonal_mean(ds.T)
T_6090 = directional_means.meridional_mean(Tzm, 60, 90)

print(T_6090)

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
input_filename:
- !ENV '${INPUT_FILE_NAME}'