Skip to content

Commit

Permalink
Merge pull request #360 from aerology-ai/main
Browse files Browse the repository at this point in the history
Handle naming convention change for RRFS files
  • Loading branch information
blaylockbk authored Aug 16, 2024
2 parents b3f58ec + 77d8bbf commit 283fee8
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions herbie/models/rrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


Expand Down

0 comments on commit 283fee8

Please sign in to comment.