METplus Practical Session Guide (Version 5.0) | METplotpy > Histogram

Histogram Overview:

The histogram source code is located in the https://github.com/dtcenter/METplotpy repository, under the METplotpy/metplotpy/plots/histogram directory.  Custom configuration files and sample data are located under the METplotpy/test/histogram directory.  

There are three specialized histogram plots available:

  • Rank Histogram
  • Relative Frequency Histogram
  • Probability Histogram

Detailed information about these plots is available from Read the Docs:

https://metplotpy.readthedocs.io/en/latest/Users_Guide/histogram.html

These instructions are relevant for generating the rank histogram from the command line.  For METplotpy version 2.0, development was performed with Python 3.8 and related third-party packages (i.e. Python packages outside the Python standard library).  

Each histogram plot requires two configuration files, a default and custom configuration file in YAML (https://yaml.org/).  One default configuration file is used for all three histogram plots: histogram_defaults.yaml.  This default configuration file is automatically loaded by the source code.  The custom configuration file is useful for overriding the default settings in the histogram_defaults.yaml configuration file.  If the user chooses to use all the settings in the default configuration file, an empty custom configuration file can be provided (however, the user will have the sample data and output plot located in the specified directories set in the default configuration file- some users may not have permission to do this) .   The custom configuration files and sample data are located in the METplotpy/test/histogram directory of the downloaded/cloned source code.

Set up pre-requisites:

The Python requirements for METplotpy are found in the User's Guide, under the Installation section

METcalcpy is a requirement for METplotpy.  The following description is one of numerous methods to set up the working environment to utilize METcalcpy from the METplotpy source code.   These instructions are suitable for users that are not working within a conda environment:

Clone the METcalcpy repository to a directory where you have read/write permissions (replace /path/to/code with the full path to where you are saving the METcalcpy source code):
mkdir /path/to/code
cd /path/to/code
git clone https://github.com/dtcenter/METcalcpy
The following instructions are for users who have permission to create, modify, and use conda environments (skip if you already set the PYTHONPATH above).  Select either Method 1 or Method 2:
  • Method 1: Follow instructions in Section 1.1.2 of the Installation section of the METplotpy User's Guide
  • Method 2: Using using PyPI (Python Package Index) enter the following:
pip install metcalcpy==2.0.1

Clone the METplotpy repository to a directory where you have read/write permissions (replace /path/to/code with the full path to where you are saving the METplotpy source code):

cd /path/to/code
git clone https://github.com/dtcenter/METplotpy

Create the Rank Histogram plot:

Overview of steps:

  • create a WORKING_DIR where you have read/write permissions
  • set the PYTHONPATH, WORKING_DIR, and METPLOTPY_BASE environments
  • copy the histogram data to the WORKING_DIR
  • copy the custom configuration for the rank histogram to the WORKING_DIR
  • modify the location of the input data and output plot in the custom configuration file
  • run the Python script to generate the rank histogram plot
Create the working directory where you have read/write permissions: 
mkdir -p /path/to/working_dir/histogram

replace /path/to/working_dir with the path leading to the working directory.

 

Set the PYTHONPATH, METPLOTPY_BASE, and WORKING_DIR environment variables. If you used Method 1 above:

csh:

setenv PYTHONPATH /path/to/METcalcpy:/path/to/METcalcpy/metcalcpy:/path/to/METplotpy:/path/to/METplotpy/metplotpy:/path/to/METplotpy/metplotpy/plots
setenv METPLOTPY_BASE /path/to/METplotpy
setenv WORKING_DIR  /path/to/working_dir/histogram

bash:

export PYTHONPATH=/path/to/METcalcpy:/path/to/METcalcpy/metcalcpy:/path/to/METplotpy:/path/to/METplotpy/metplotpy:/path/to/METplotpy/metplotpy/plots
export METPLOTPY_BASE=/path/to/METplotpy
export WORKING_DIR=/path/to/working_dir/histogram

 

 

If you installed METcalcpy using Method 2 above (i.e. PyPI and pip), then set the PYTHONPATH without the METcalcpy paths:

csh:

setenv /path/to/METplotpy:/path/to/METplotpy/metplotpy:/path/to/METplotpy/metplotpy/plots
setenv METPLOTPY_BASE /path/to/METplotpy
setenv WORKING_DIR /path/to/working_dir/histogram

bash:

export PYTHONPATH=/path/to/METplotpy:/path/to/METplotpy/metplotpy:/path/to/METplotpy/metplotpy/plots
export METPLOTPY_BASE=/path/to/METplotpy
export WORKING_DIR=/path/to/working_dir/histogram
Copy data and custom config file to WORKING_DIR:
cp $METPLOTPY_BASE/test/histogram/rank_hist.data $WORKING_DIR
cp $METPLOTPY_BASE/test/histogram/rank_hist.yaml $WORKING_DIR
cd $WORKING_DIR

Modify custom configuration file:

Open the rank_hist.yaml file in a text editor of your choice.  Modify the stat_input and plot_filename to point explicitly to the location of the input data you copied and the name and location of the output plot:
stat_input: /path/to/working_dir/histogram/rank_hist.data
plot_filename: /path/to/working_dir/histogram/rank_hist.png

Save and close the rank_hist.yaml file. 

Generate the rank histogram plot:
python $METPLOTPY_BASE/metplotpy/plots/histogram/rank_hist.py $WORKING_DIR/rank_hist.yaml

 

In your WORKING_DIR, you will now see a rank_hist.png file.  You can view the png file using an appropriate viewer, such as 'display' if on a Linux/Unix host:

cd $WORKING_DIR
display rank_hist.png

 

Your histogram will look like the following:

 

 

 

 

 

Create the Relative Frequency Histogram and Probability Histogram

 

Repeat the steps for the rank histogram, except copy the following to the WORKING_DIR:

Relative frequency histogram:

cp $METPLOTPY_BASE/test/histogram/rel_hist.data $WORKING_DIR
cp $METPLOTPY_BASE/test/histogram/rel_hist.yaml $WORKING_DIR

 

Probability histogram:

cp $METPLOTPY_BASE/test/histogram/prob_hist.data $WORKING_DIR
cp $METPLOTPY_BASE/test/histogram/prob_hist.yaml $WORKING_DIR

 

Make the same modifications in the rel_hist.yaml and prob_hist.yaml files to the stat_input and plot_filename settings.

Relative frequency histogram:

stat_input: /path/to/working_dir/histogram/rel_hist.data
plot_filename: /path/to/working_dir/histogram/rel_hist.png

 

Probability histogram:

stat_input: /path/to/working_dir/histogram/prob_hist.data
plot_filename: /path/to/working_dir/histogram/prob_hist.png

 

Generate the Relative Frequency and Probability Histogram plots using these Python scripts:

Relative frequency histogram:

python $METPLOTPY_BASE/metplotpy/plots/histogram/rel_hist.py $WORKING_DIR/rel_hist.yaml

Probability histogram:

python $METPLOTPY_BASE/metplotpy/plots/histogram/prob_hist.py $WORKING_DIR/prob_hist.yaml

You will see the rel_hist.png and prob_hist.png files in your WORKING_DIR. Your plots will look like the following:

Relative Frequency Histogram:

 

Probability Histogram: