Skip to content

Instantly share code, notes, and snippets.

@mikecharles
Created January 12, 2017 16:57
Show Gist options
  • Save mikecharles/d7996602da52f5f6d77232d02130c024 to your computer and use it in GitHub Desktop.
Save mikecharles/d7996602da52f5f6d77232d02130c024 to your computer and use it in GitHub Desktop.
Load extended GEFS dataset

To run this, just create a virtualenv and install cpc.geofiles:

$ pip install cpc.geofiles
#!/usr/bin/env python
from cpc.geogrids import Geogrid
from cpc.geofiles.loading import load_ens_fcsts
# Needs to be a list - if you want a single date, put it within []s
issued_dates = ['20170105']
# Use the range function, or a list - note that fhrs will have N digits, where N is the number of digits in the largest fhr
fhrs = range(390, 840+1, 6)
# Use the range function, or a list - note that fhrs will have N digits, where N is the number of digits in the largest member
members = range(20+1)
# Template of the full path to the data files - the following template vars are supported:
# - {{ yyyy }} <-- 4-digit year
# - {{ mm }} <-- 2-digit month
# - {{ dd }} <-- 2-digit day
# - {{ cc }} <-- 2-digit cycle
# - {{ fhr }} <-- N-digit forecast hour, where N is the number of digits in the largest fhr
file_template = '/path/to/data/{{ yyyy }}/{{ mm }}/{{ dd }}/00/gefs_{{ yyyy }}{{ mm }}{{ dd }}_00z_f{{ fhr }}_m{{ member }}.grb2'
# Binary, grib1 or grib2
data_type = 'grib2'
# Another package cpc.geogrids has several pre-defined grids - this one is the 1-deg global grid
geogrid = Geogrid('1deg-global')
# Statistic to calculate over the forecast hour dimension (mean or sum)
fhr_stat = 'mean'
# Grib variable name
grib_var = 'TMP'
# Grib level name
grib_level = '2 m above ground'
# Whether to print out all the wgrib commands when loading the data
debug = True
# Load the ensemble forecast dataset
dataset = load_ens_fcsts(issued_dates, fhrs, members, file_template, data_type, geogrid,
grib_var=grib_var, grib_level=grib_level, debug=debug)
# The resulting dataset object will contain the following data attributes (access with dataset.X):
#
# - ens <-- full ensemble forecast - shape is (num_days, num_members, num_grid_points)
# - ens_mean <-- ensemble mean forecast - shape is (num_days, num_grid_points)
# - ens_spread <-- ensemble forecast spread - shape is (num_days, num_grid_points)
#
# and the following QC attributes:
#
# - dates_with_files_not_loaded
# - files_not_loaded
# - dates_loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment