Skip to content

Commit

Permalink
Merge branch 'master' of github.com:djgagne/hagelslag into djgagne
Browse files Browse the repository at this point in the history
  • Loading branch information
djgagne committed Nov 28, 2023
2 parents e7d8280 + 3d24400 commit 2460e12
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 8 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Install grib dependencies
shell: bash -l {0}
run: |
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev libopenjp2-7 libopenjp2-tools libopenjp2-7-dev
ldconfig -p | grep libjasper
- name: "Set up Python 3.8"
- name: "Set up Python 3"
uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
Expand Down
70 changes: 70 additions & 0 deletions config/MPAS_interpolated_HRRR.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import numpy as np
import pandas as pd
from hagelslag.processing.ObjectMatcher import shifted_centroid_distance
from hagelslag.processing.ObjectMatcher import centroid_distance, time_distance

# NOTE: HRRR variables must be listed in the following format:
# {HRRR_VARIABLE_NAME}-{HRRR_level}
# For example, Composite Reflectivity (REFC) which is at the (entire_atmosphere) level
# would be listed as 'REFC-entire_atmosphere'

# 'ensemble_name' must be lsited as 'HRRR-ZARR'
# 'model_path' must be "hrrrzarr/sfc/"
# 'end_hour' must be no more than n-1 number of forecast hours in model

# Support for model runs with different forecast lengths, use 'HRRR_alt_end_hour' for an alternative
# forecast length that is used for each model run hour listed in 'HRRR_alt_hours'. If neither is provided,
# 'end_hour' will be used for all model runs.

## output path
scratch_path = "/glade/scratch/cbecker/MPAS_interp_HRRR/"

# Historical runs
date_index = pd.date_range(start='2023-04-24', end='2023-05-31', freq='1D', tz='UTC').to_pydatetime()

# Real Time runs
# Use pd.Timedelta to correspond with delay in data availability from hour that script is submitted
# date_index = pd.DatetimeIndex([pd.Timestamp.utcnow().strftime("%Y-%m-%d-%H")]) - pd.Timedelta(hours=3)

ensemble_members = ["1", "2", "3", "4", "5"]

config = dict(dates=date_index,
start_hour=1,
end_hour=132,
HRRR_alt_end_hour=47,
HRRR_alt_run_hours=[0, 6, 12, 18],
watershed_variable="refl10cm_max",
ensemble_name="MPAS-interp",
ensemble_members=ensemble_members,
model_path="/glade/campaign/mmm/parc/schwartz/HWT2023/mpas/",
segmentation_approach="hyst",
model_watershed_params=(35, 50),
size_filter=12,
gaussian_window=1,
mrms_path=None,
mrms_variable="MESH_Max_60min_00.50",
mrms_watershed_params=(13, 1, 125, 100, 100),
object_matcher_params=([shifted_centroid_distance], np.array([1.0]),
np.array([24000])),
track_matcher_params=([centroid_distance, time_distance],
np.array([80000, 2])),
storm_variables=["refl10cm_max", "updraft_helicity_max", "updraft_helicity_max01",
"updraft_helicity_max03"],
potential_variables=[],
tendency_variables=[],
shape_variables=["area", "eccentricity", "major_axis_length", "minor_axis_length", "orientation"],
variable_statistics=["mean", "max", "min"],
csv_path=scratch_path + "track_data_MPAS_interp_hrrr_3km_csv_refl/",
geojson_path=scratch_path + "track_data_MPAS_interp_hrrr_3km_json_refl/",
nc_path=scratch_path + "track_data_MPAS_interp_hrrr_3km_nc_refl/",
patch_radius=48,
unique_matches=True,
closest_matches=True,
match_steps=True,
train=False,
single_step=True,
label_type="gamma",
segment_full_object=True,
model_map_file="/glade/work/cbecker/hagelslag/mapfiles/mpas_interp_hrrr_map_2023.txt",
mask_file=None,
output_geojson_grid=True)
33 changes: 33 additions & 0 deletions hagelslag/data/MPASHrrrGrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .ModelGrid import ModelGrid
import numpy as np
from os.path import join
class MPASHrrrGrid(ModelGrid):
"""
Loads model output from the NCAR MMM 1 and 3 km WRF runs on Cheyenne.
"""

def __init__(self, run_date, variable, start_date, end_date, member, path):
self.path = path
self.forecast_hours = np.arange((start_date - run_date).total_seconds() / 3600,
(end_date - run_date).total_seconds() / 3600 + 1, dtype=int)
filenames = []
for hour in self.forecast_hours:
filename = join(path, run_date.strftime("%Y%m%d%H"), "post", f"mem_{member}",
f"interp_mpas_3km_{run_date.strftime('%Y%m%d%H')}_mem{member}_f{hour:03}.nc")
filenames.append(filename)
super(MPASHrrrGrid, self).__init__(filenames, run_date, start_date, end_date, variable)

def format_var_name(self, variable, var_list):

z_index = None
if variable in var_list:
var_name = variable
elif "_PL" in variable:
var_parts = variable.split("_")
var_name = "_".join(var_parts[:-1])
p_level = int(var_parts[-1])
z_index = np.where(self.pressure_levels == p_level)[0][0]
else:
raise KeyError("{0} not found in {1}".format(variable, ", ".join(var_list)))
return var_name, z_index
10 changes: 10 additions & 0 deletions hagelslag/data/ModelOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .NCARStormEventModelGrid import NCARStormEventModelGrid
from .SSEFModelGrid import SSEFModelGrid
from .VSEModelGrid import VSEModelGrid
from .MPASHrrrGrid import MPASHrrrGrid


class ModelOutput(object):
Expand Down Expand Up @@ -194,6 +195,15 @@ def load_data(self):
self.end_date,
self.path)
self.data, self.units = mg.load_data()

elif self.ensemble_name.upper() == "MPAS-INTERP":
mg = MPASHrrrGrid(self.run_date,
self.variable,
self.start_date,
self.end_date,
self.member_name,
self.path)
self.data, self.units = mg.load_data()
else:
print(self.ensemble_name + " not supported.")

Expand Down
14 changes: 14 additions & 0 deletions mapfiles/mpas_interp_hrrr_map_2023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
proj=lcc
a=6371229.0
b=6371229.0
lat_0=38.5
lon_0=262.5
lat_1=38.5
lat_2=38.5
units=m
dx=3000
dy=3000
sw_lon=-122.7195
sw_lat=21.13812
ne_lon=-60.91719
ne_lat=47.84219

0 comments on commit 2460e12

Please sign in to comment.