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

Freezing rain events #1778

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Freezing rain events #1778

wants to merge 5 commits into from

Conversation

coxipi
Copy link
Contributor

@coxipi coxipi commented Jun 13, 2024

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • Tests for the changes have been added (for bug fixes / features)
    • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • CHANGES.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

  • New indicator freezing_rain_events computes the sequence of freezing rain event, giving a Dataset with various informations about the runs in the output (cumulative precipitation of runs, duration of runs, ...)
  • It relies on a new function in run_length that can compute the run_length of sequence determined by two conditions. A first condition determines when runs should start, and a second one determines when they stop. This is called runs_with_holes as one possibility with the addtition of the second condition is this: consider a normal run_length, but the second condition allows for holes in thoses sequences, where those holes cannot exceed a given threshold window_stop. runs_with_holes is in fact more general, so perhaps another name should be found.

Does this PR introduce a breaking change?

No

Other information:

@github-actions github-actions bot added the indicators Climate indices and indicators label Jun 13, 2024
@coxipi coxipi marked this pull request as draft June 13, 2024 01:48
Comment on lines 2722 to 2724
# Reduce time dim to event dimension
mask = (ds.run_lengths > 0).any(dim=[d for d in ds.dims if d != "time"])
ds = ds.where(mask).dropna(dim="time").rename({"time": "event"})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be different, to fix the number of events... need to change this, I have code for this somewhere, will do soon

@coxipi coxipi requested a review from aulemahal June 13, 2024 15:16
Comment on lines +2729 to +2749
# Filter events: Reduce time dimension
def _filter_events(da, rl, max_event_number):
out = np.full(max_event_number, np.NaN)
events_start = da[rl > 0]
out[: len(events_start)] = events_start
return out

max_event_number = int(np.ceil(pr.time.size / (window_start + window_stop)))
v_attrs = {v: ds[v].attrs for v in ds.data_vars}
ds = xarray.apply_ufunc(
_filter_events,
ds,
ds.run_lengths,
input_core_dims=[["time"], ["time"]],
output_core_dims=[["event"]],
kwargs=dict(max_event_number=max_event_number),
output_sizes={"event": max_event_number},
dask="parallelized",
vectorize=True,
).assign_attrs(ds.attrs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change allows to filter the events, reorder this dimension. This requires xr.apply_ufunc and contiguous time dimension though. I don't think the previous implementation would have worked for without contiguous time anyways.

However! The rest of the code uses calls to run_length and I believe this can be done with chunks over the time dimension. One other approach could to keep all time coords at first, and allow the use of yearly time chunks for instance, then save the output. Then, in a second pass, filter events using this apply_ufunc above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indicators Climate indices and indicators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant