Skip to content

Update plot_events script#1274

Merged
AnnaKwa merged 8 commits into
mainfrom
scripts/update-plot-events
Jul 1, 2026
Merged

Update plot_events script#1274
AnnaKwa merged 8 commits into
mainfrom
scripts/update-plot-events

Conversation

@AnnaKwa

@AnnaKwa AnnaKwa commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
  • Add option to cache the downloaded dataset instead of saving to temp directory. Currently it defaults to caching so that it's less tedious to call the script, but if desired I can change the default to not cache.
  • Fix bug where the coarse data would select the 00 hour timestep if the event filename only had YYYYMMDD in the name. Now the script checks the config in the beaker dataset to get the exact event timestamp.
  • Add TMP2m to the coarse variables to read
  • Remove coarse PRESsfc relabeling to PRMSL since we now use PRMSL for both inputs and outputs.

AnnaKwa and others added 6 commits June 11, 2026 11:51
The coarse panel was selected using a timestamp parsed from the event
filename, defaulting to 12Z when the filename had no hour suffix. Most
events are not at 12Z (e.g. the heat wave events are at 00Z), so the
coarse field showed the wrong time of day. Read each event's date from
the config.yaml saved with the beaker dataset instead, falling back to
filename parsing (now defaulting to 00Z, the evaluator convention) only
when the event is missing from the config.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
find_event_files keyed files by the event name with the date stripped,
so when a dataset contained several dates for the same event (e.g.
three Phl_tc_landfall files) only the last one alphabetically was
processed. Key by the full filename stem instead; this also makes the
keys match the event names in the evaluator config.yaml.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
"""Find netCDF files matching the event naming pattern, keyed by event name."""
"""Find netCDF files matching the event naming pattern, keyed by filename
stem (event name including date, so multiple dates of the same event are
kept)."""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, if there were files with the same name and different dates, only one was plotted.

@frodre frodre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's one leftover error from the adjusted PRMSL conditional, and I think I would prefer an opt in for the caching instead of defaulting to storage (I don't feel strongly). My reasoning being that the datasets are usually small and quick to download. At the very least if not making opt-in, I would suggest the default cache be tied to something that gets wiped with the machine reset like /tmp/beaker, but would still be persistent across script usage.

Comment thread scripts/downscaling/plot_events.py Outdated
ds_["PRMSL_coarse"].values[:] = np.nan
# For colorbar range, use only target and predicted (coarse is hidden)
arr = ds_[["PRMSL_target", "PRMSL_predicted"]].to_array()
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this else block need to be adjusted? It looks like it pairs with the if len(samples)... from above

Comment thread scripts/downscaling/plot_events.py Outdated
ds_["PRMSL_coarse"].values[:] = np.nan
# For colorbar range, use only target and predicted (coarse is hidden)
arr = ds_[["PRMSL_target", "PRMSL_predicted"]].to_array()
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this else block need to be adjusted? It looks like it pairs with the if len(samples)... from above

def fetch_beaker_dataset(
dataset_id: str,
target_dir: str,
prefix: str | None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix seems like a straightforward addition, but I didn't see it actually used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets used in L43

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant that it doesn't seem to be wired into any of the entrypoint usage, so it's effectively blocked off.

Comment thread scripts/downscaling/utils.py Outdated
dataset_id: str,
target_dir: str,
prefix: str | None = None,
cache_dir: str | None = "~/Downloads/beaker_cache",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think persistent cache would make more sense as opt-in not opt-out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the default to opt in but added a check for an env var that can be set if someone (me) uses this often and doesn't want to add the cli arg each time.

Comment thread scripts/downscaling/utils.py Outdated
"""
if cache_dir is not None:
cached = Path(cache_dir).expanduser() / dataset_id
if cached.is_dir() and any(cached.iterdir()):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing for persistent caches flagged by Claude: a partial beaker fetch that failed would still pass this check. You could add a sentinel file after the subprocess completes successfully.

@frodre frodre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cache adjustments.

@AnnaKwa AnnaKwa enabled auto-merge (squash) July 1, 2026 15:26
@AnnaKwa AnnaKwa merged commit e05e02f into main Jul 1, 2026
7 checks passed
@AnnaKwa AnnaKwa deleted the scripts/update-plot-events branch July 1, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants