@@ -3,14 +3,19 @@ module RapidRefreshData
33using Dates, Scratch
44
55const rap_base_url = " https://noaa-rap-pds.s3.amazonaws.com/rap."
6- const gfs_base_url = " https://noaa-gfs-bdp-pds.s3.amazonaws.com/"
6+ const gfs_base_url = " https://noaa-gfs-bdp-pds.s3.amazonaws.com/gfs"
7+ const hrrr_base_url = " https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr"
78
89
910# -----------------------------------------------------------------------------# __init__
10- dir:: String = " "
11+ rap_dir:: String = " "
12+ gfs_dir:: String = " "
13+ hrrr_dir:: String = " "
1114
1215function __init__ ()
13- global dir = Scratch. @get_scratch! (" datasets" )
16+ global rap_dir = Scratch. @get_scratch! (" rap" )
17+ global gfs_dir = Scratch. @get_scratch! (" gfs" )
18+ global hrrr_dir = Scratch. @get_scratch! (" hrrr" )
1419end
1520
1621# -----------------------------------------------------------------------------# RAPDataset
6570Get local cache path for the RAP dataset.
6671"""
6772function local_path (dset:: RAPDataset )
68- joinpath (dir , " rap_$(Dates. format (dset. date, " yyyymmdd" )) _$(dset. cycle_time) _$(dset. grid) _$(dset. forecast) .grib2" )
73+ joinpath (rap_dir , " rap_$(Dates. format (dset. date, " yyyymmdd" )) _$(dset. cycle_time) _$(dset. grid) _$(dset. forecast) .grib2" )
6974end
7075
7176"""
8388List all cached RAP datasets.
8489"""
8590function local_datasets (:: Type{RAPDataset} )
86- files = filter (f -> startswith (f, " rap_" ) && endswith (f, " .grib2" ), readdir (dir))
87- read .(RAPDataset, files)
91+ read .(RAPDataset, readdir (rap_dir))
8892end
8993
9094"""
140144Generate AWS S3 URL for the GFS dataset.
141145"""
142146function url (dset:: GFSDataset )
143- " $(gfs_base_url) gfs .$(Dates. format (dset. date, " yyyymmdd" )) /$(dset. cycle) /$(dset. product) /gfs.t$(dset. cycle) z.pgrb2.$(dset. resolution) .$(dset. forecast) "
147+ " $(gfs_base_url) .$(Dates. format (dset. date, " yyyymmdd" )) /$(dset. cycle) /$(dset. product) /gfs.t$(dset. cycle) z.pgrb2.$(dset. resolution) .$(dset. forecast) "
144148end
145149
146150"""
149153Get local cache path for the GFS dataset.
150154"""
151155function local_path (dset:: GFSDataset )
152- joinpath (dir , " gfs_$(Dates. format (dset. date, " yyyymmdd" )) _$(dset. cycle) _$(dset. resolution) _$(dset. product) _$(dset. forecast) .grib2" )
156+ joinpath (gfs_dir , " gfs_$(Dates. format (dset. date, " yyyymmdd" )) _$(dset. cycle) _$(dset. resolution) _$(dset. product) _$(dset. forecast) .grib2" )
153157end
154158
155159"""
167171List all cached GFS datasets.
168172"""
169173function local_datasets (:: Type{GFSDataset} )
170- files = filter (f -> startswith (f, " gfs_" ), readdir (dir))
171- read .(GFSDataset, files)
174+ read .(GFSDataset, readdir (gfs_dir))
172175end
173176
174177"""
@@ -180,5 +183,88 @@ function clear_local_dataset!(dset::GFSDataset)
180183 isfile (local_path (dset)) && rm (local_path (dset))
181184end
182185
186+ # -----------------------------------------------------------------------------# HRRRDataset
187+ """
188+ HRRRDataset(; date, cycle, region, product, forecast)
189+
190+ NOAA High-Resolution Rapid Refresh (HRRR) dataset descriptor.
191+
192+ # Fields
193+ - `date::Date`: Forecast initialization date (default: today)
194+ - `cycle::String`: Model run hour - "00" to "23" (default: "00")
195+ - `region::String`: Geographic region - "conus" (Continental US) or "alaska" (default: "conus")
196+ - `product::String`: Product type - "wrfsfc" (surface), "wrfprs" (pressure), "wrfnat" (native), or "wrfsub" (subhourly) (default: "wrfsfc")
197+ - `forecast::String`: Forecast hour - "f00" to "f48" (default: "f00")
198+ """
199+ @kwdef struct HRRRDataset
200+ date:: Date = today ()
201+ cycle:: String = " 00" # "00" to "23"
202+ region:: String = " conus" # "conus", "alaska"
203+ product:: String = " wrfsfc" # "wrfsfc", "wrfprs", "wrfnat", "wrfsub"
204+ forecast:: String = " f00" # "f00" to "f48"
205+ end
206+
207+ function Base. show (io:: IO , dset:: HRRRDataset )
208+ (;date, cycle, region, product, forecast) = dset
209+ print (io, " HRRRDataset" , (; date= string (date), cycle, region, product, forecast))
210+ end
211+
212+ function Base. read (:: Type{HRRRDataset} , local_path:: String )
213+ filename = split (basename (local_path), " ." )[1 ]
214+ parts = split (filename, " _" )
215+ # Skip "hrrr" prefix (parts[1]) and parse remaining parts
216+ date = Date (parts[2 ], " yyyymmdd" )
217+ cycle = parts[3 ]
218+ region = parts[4 ]
219+ product = parts[5 ]
220+ forecast = parts[6 ]
221+ return HRRRDataset (; date, cycle, region, product, forecast)
222+ end
223+
224+ """
225+ url(dset::HRRRDataset) -> String
226+
227+ Generate AWS S3 URL for the HRRR dataset.
228+ """
229+ function url (dset:: HRRRDataset )
230+ " $(hrrr_base_url) .$(Dates. format (dset. date, " yyyymmdd" )) /$(dset. region) /hrrr.t$(dset. cycle) z.$(dset. product)$(dset. forecast) .grib2"
231+ end
232+
233+ """
234+ local_path(dset::HRRRDataset) -> String
235+
236+ Get local cache path for the HRRR dataset.
237+ """
238+ function local_path (dset:: HRRRDataset )
239+ joinpath (hrrr_dir, " hrrr_$(Dates. format (dset. date, " yyyymmdd" )) _$(dset. cycle) _$(dset. region) _$(dset. product) _$(dset. forecast) .grib2" )
240+ end
241+
242+ """
243+ get(dset::HRRRDataset) -> String
244+
245+ Download HRRR dataset to cache (if needed) and return filepath.
246+ """
247+ function Base. get (dset:: HRRRDataset )
248+ isfile (local_path (dset)) ? local_path (dset) : Base. download (url (dset), local_path (dset))
249+ end
250+
251+ """
252+ local_datasets(HRRRDataset) -> Vector{HRRRDataset}
253+
254+ List all cached HRRR datasets.
255+ """
256+ function local_datasets (:: Type{HRRRDataset} )
257+ read .(HRRRDataset, readdir (hrrr_dir))
258+ end
259+
260+ """
261+ clear_local_dataset!(dset::HRRRDataset)
262+
263+ Remove HRRR dataset from local cache.
264+ """
265+ function clear_local_dataset! (dset:: HRRRDataset )
266+ isfile (local_path (dset)) && rm (local_path (dset))
267+ end
268+
183269
184270end
0 commit comments