From 77d8bbf7c7a180b54f6ddde1aebf93ffcee4ddf2 Mon Sep 17 00:00:00 2001 From: timothydonohue Date: Mon, 12 Aug 2024 09:39:38 -0400 Subject: [PATCH] simplified to avoid changes to core.py --- herbie/models/rrfs.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/herbie/models/rrfs.py b/herbie/models/rrfs.py index bf0b0992..ddb8b563 100644 --- a/herbie/models/rrfs.py +++ b/herbie/models/rrfs.py @@ -43,19 +43,40 @@ def template(self): # Format the domain parameter if self.domain == "conus": - self.domain = ".conus" + self.domain = "conus" # We'll handle the "_3km" part in the URL generation elif self.domain == "alaska": - self.domain = ".ak" + self.domain = "ak" elif self.domain == "hawaii": - self.domain = ".hi" + self.domain = "hi" elif self.domain == "puerto rico": - self.domain = ".pr" + self.domain = "pr" elif self.domain is None: self.domain = "" - self.SOURCES = { - "aws": f"https://noaa-rrfs-pds.s3.amazonaws.com/rrfs_a/rrfs_a.{self.date:%Y%m%d/%H}/{self.member}/rrfs.t{self.date:%H}z.{self.product}.f{self.fxx:03d}{self.domain}.grib2", - } + def generate_url(domain_suffix, member_prefix=""): + return f"https://noaa-rrfs-pds.s3.amazonaws.com/rrfs_a/rrfs_a.{self.date:%Y%m%d/%H}/{self.member}/rrfs.t{self.date:%H}z{member_prefix}.{self.product}.f{self.fxx:03d}.{domain_suffix}.grib2" + + urls = [] + + # Handle different domain formats + domain_suffixes = [self.domain] + if self.domain == "conus": + domain_suffixes = ["conus", "conus_3km"] # Prioritize newer format + + # Handle different member formats + member_prefixes = [""] + if self.member.startswith("mem"): + member_num = int(self.member[3:]) + member_prefixes = [f".m{member_num:02d}", ""] # Prioritize newer format + + # Generate all possible URL combinations + for member_prefix in member_prefixes: + for domain_suffix in domain_suffixes: + urls.append(generate_url(domain_suffix, member_prefix)) + + # Create separate sources for each URL + self.SOURCES = {f"aws_{i}": url for i, url in enumerate(urls)} + self.LOCALFILE = f"{self.member}/{self.get_remoteFileName}"