-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utilities to decompose, store and load NWP cascades for use in bl…
…ending (#232) * First version of NWP decomposition * Added saving to netCDF * Completed functions for saving and loading decomposed NWP data * Added example files for the decomposed NWP functions * Added compatibility with numpy datetime * Use default output path_workdir for tmp files in blending/utils.py. * Update documentation of NWP decomposition functions in utils.py Co-authored-by: Wout Dewettinck <wout.dewettinck@ugent.be> Co-authored-by: wdewettin <87696913+wdewettin@users.noreply.github.com>
- Loading branch information
1 parent
4b2ca89
commit 81e88fe
Showing
5 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,6 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# example data | ||
examples/radar/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os, netCDF4 | ||
import numpy as np | ||
from pysteps import rcparams | ||
from pysteps.blending.utils import load_NWP | ||
|
||
NWP_output = rcparams.outputs["path_workdir"] + "cascade_alaro13_01_20170131110000.nc" | ||
start_time = np.datetime64("2017-01-31T11:20") | ||
|
||
print(load_NWP(NWP_output, start_time, 4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from datetime import datetime | ||
from pprint import pprint | ||
from pysteps import io, nowcasts, rcparams | ||
from pysteps.motion.lucaskanade import dense_lucaskanade | ||
from pysteps.postprocessing.ensemblestats import excprob | ||
from pysteps.utils import conversion, dimension, transformation | ||
from pysteps.visualization import plot_precip_field | ||
from pysteps.blending.utils import decompose_NWP | ||
from pysteps.cascade.bandpass_filters import filter_gaussian | ||
|
||
num_cascade_levels = 8 | ||
|
||
############################################################################### | ||
# Read precipitation field | ||
# ------------------------ | ||
# | ||
# First thing, the sequence of Swiss radar composites is imported, converted and | ||
# transformed into units of dBR. | ||
|
||
|
||
date = datetime.strptime("201701311200", "%Y%m%d%H%M") | ||
data_source = "mch" | ||
|
||
# Load data source config | ||
root_path = rcparams.data_sources[data_source]["root_path"] | ||
path_fmt = rcparams.data_sources[data_source]["path_fmt"] | ||
fn_pattern = rcparams.data_sources[data_source]["fn_pattern"] | ||
fn_ext = rcparams.data_sources[data_source]["fn_ext"] | ||
importer_name = rcparams.data_sources[data_source]["importer"] | ||
importer_kwargs = rcparams.data_sources[data_source]["importer_kwargs"] | ||
timestep = rcparams.data_sources[data_source]["timestep"] | ||
|
||
# Find the radar files in the archive | ||
fns = io.find_by_date( | ||
date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=12 | ||
) | ||
|
||
# Read the data from the archive | ||
importer = io.get_method(importer_name, "importer") | ||
R_NWP, _, metadata = io.read_timeseries(fns, importer, legacy=True, **importer_kwargs) | ||
|
||
# Convert to rain rate | ||
R_NWP, metadata = conversion.to_rainrate(R_NWP, metadata) | ||
|
||
# Log-transform the data | ||
R_NWP, metadata = transformation.dB_transform( | ||
R_NWP, metadata, threshold=0.1, zerovalue=-15.0 | ||
) | ||
|
||
# Fill in the missing data with the threshold value | ||
R_NWP[~np.isfinite(R_NWP)] = metadata["zerovalue"] | ||
|
||
# Find the location to save the NWP files | ||
NWP_output = rcparams.outputs["path_workdir"] | ||
|
||
# Define the start time of the NWP forecast | ||
analysis_time = metadata["timestamps"][0] | ||
|
||
# Decompose the NWP and save to netCDF file | ||
decompose_NWP( | ||
R_NWP, | ||
"alaro13_01", | ||
analysis_time, | ||
5, | ||
metadata["timestamps"], | ||
num_cascade_levels, | ||
NWP_output, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters