Allow equal duration_subdivision period and fidelity arguments#2322
Open
maxwhitemet wants to merge 7 commits intometoppv:masterfrom
Open
Allow equal duration_subdivision period and fidelity arguments#2322maxwhitemet wants to merge 7 commits intometoppv:masterfrom
maxwhitemet wants to merge 7 commits intometoppv:masterfrom
Conversation
gavinevans
requested changes
Mar 4, 2026
Contributor
gavinevans
left a comment
There was a problem hiding this comment.
Thanks @maxwhitemet 👍
I've added a couple of minor comments.
gavinevans
requested changes
Mar 5, 2026
Contributor
gavinevans
left a comment
There was a problem hiding this comment.
Thanks for the updates, @maxwhitemet 👍
I've added a few minor comments.
gavinevans
requested changes
Mar 6, 2026
Contributor
gavinevans
left a comment
There was a problem hiding this comment.
Thanks @maxwhitemet 👍
Just one suggestion.
Comment on lines
+2193
to
+2227
|
|
||
| new_period_cubes = iris.cube.CubeList() | ||
|
|
||
| # The cycle times are already the same. However, below we use this variable | ||
| # to recalculate the forecast periods relative to the cycletime for each of our | ||
| # extracted shorter duration cubes. | ||
| cycle_time = fidelity_period_cube.coord("forecast_reference_time").cell(0).point | ||
|
|
||
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | ||
| return new_period_cubes.merge_cube() | ||
| # If the fidelity is the same as the target period, we can skip the step of | ||
| # summing up the fidelity period cubes into target period cubes seen in the else | ||
| # statement below and just enforce the time point standard and unify cycletime | ||
| # on the fidelity period cubes. | ||
| if self.fidelity == self.target_period: | ||
| for time_slice in fidelity_period_cube.slices_over("time"): | ||
| enforce_time_point_standard(time_slice) | ||
| new_period_cubes.append(time_slice) | ||
|
|
||
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | ||
| return new_period_cubes.merge_cube() | ||
|
|
||
| else: | ||
| while start_time < end_time: | ||
| period_constraint = iris.Constraint( | ||
| time=lambda cell: start_time | ||
| <= cell.bound[0] | ||
| < start_time + interval | ||
| ) | ||
| components = fidelity_period_cube.extract(period_constraint) | ||
| component_cube = components.collapsed("time", iris.analysis.SUM) | ||
| enforce_time_point_standard(component_cube) | ||
| new_period_cubes.append(component_cube) | ||
| start_time += interval | ||
|
|
||
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | ||
| return new_period_cubes.merge_cube() |
Contributor
There was a problem hiding this comment.
I think you could save a few lines by just calling unify_cycletime once.
Suggested change
| new_period_cubes = iris.cube.CubeList() | |
| # The cycle times are already the same. However, below we use this variable | |
| # to recalculate the forecast periods relative to the cycletime for each of our | |
| # extracted shorter duration cubes. | |
| cycle_time = fidelity_period_cube.coord("forecast_reference_time").cell(0).point | |
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | |
| return new_period_cubes.merge_cube() | |
| # If the fidelity is the same as the target period, we can skip the step of | |
| # summing up the fidelity period cubes into target period cubes seen in the else | |
| # statement below and just enforce the time point standard and unify cycletime | |
| # on the fidelity period cubes. | |
| if self.fidelity == self.target_period: | |
| for time_slice in fidelity_period_cube.slices_over("time"): | |
| enforce_time_point_standard(time_slice) | |
| new_period_cubes.append(time_slice) | |
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | |
| return new_period_cubes.merge_cube() | |
| else: | |
| while start_time < end_time: | |
| period_constraint = iris.Constraint( | |
| time=lambda cell: start_time | |
| <= cell.bound[0] | |
| < start_time + interval | |
| ) | |
| components = fidelity_period_cube.extract(period_constraint) | |
| component_cube = components.collapsed("time", iris.analysis.SUM) | |
| enforce_time_point_standard(component_cube) | |
| new_period_cubes.append(component_cube) | |
| start_time += interval | |
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | |
| return new_period_cubes.merge_cube() | |
| new_period_cubes = iris.cube.CubeList() | |
| # If the fidelity is the same as the target period, we can skip the step of | |
| # summing up the fidelity period cubes into target period cubes seen in the else | |
| # statement below and just enforce the time point standard on the fidelity period | |
| # cubes. | |
| if self.fidelity == self.target_period: | |
| for time_slice in fidelity_period_cube.slices_over("time"): | |
| enforce_time_point_standard(time_slice) | |
| new_period_cubes.append(time_slice) | |
| else: | |
| while start_time < end_time: | |
| period_constraint = iris.Constraint( | |
| time=lambda cell: start_time | |
| <= cell.bound[0] | |
| < start_time + interval | |
| ) | |
| components = fidelity_period_cube.extract(period_constraint) | |
| component_cube = components.collapsed("time", iris.analysis.SUM) | |
| enforce_time_point_standard(component_cube) | |
| new_period_cubes.append(component_cube) | |
| start_time += interval | |
| # Recalculate the forecast periods relative to the cycletime for each | |
| # of the target period cubes. | |
| cycle_time = fidelity_period_cube.coord("forecast_reference_time").cell(0).point | |
| new_period_cubes = unify_cycletime(new_period_cubes, cycle_time) | |
| return new_period_cubes.merge_cube() |
Open
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #1013
Currently, a user of the DurationSubdivision plugin looking to divide an accumulation diagnostic cube (e.g. 3 hourly precip to 1 hourly) needs to specify both a target_period and fidelity argument, with the former being the time period each output will span (e.g. 1hr), and the latter the shortest increment into which the input cube is divided before being aggregated into the output periods.
This fidelity argument was designed primarily with sunshine duration in mind and is only useful when used with a night mask or day mask to help demarcate where day/night is during each fidelity period, zeroing points where the mask indicates night.
The existing implementation fails when fidelity == target_period, forcing users to set fidelity to values smaller than target_period (e.g., 1800s instead of 3600s), increasing processing time. Thus this PR makes a minor change to allow fidelity to be equal to target_period.