Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle naming convention change for RRFS files #360

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading