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

[Feature]: More Sophisticated Bounds Handling in Temporal Averaging Operations #594

Open
pochedls opened this issue Jan 31, 2024 · 7 comments · May be fixed by #735
Open

[Feature]: More Sophisticated Bounds Handling in Temporal Averaging Operations #594

pochedls opened this issue Jan 31, 2024 · 7 comments · May be fixed by #735
Labels
type: enhancement New enhancement request

Comments

@pochedls
Copy link
Collaborator

pochedls commented Jan 31, 2024

Is your feature request related to a problem?

xcdat temporal averaging operations currently bin data by the labelled time point with the weights derived from the difference in the time bounds. This works for most conventional climate data: a timepoint of 2020-01-16 12:00 with bounds of [2020-01-01 00:00, 2020-02-01 00:00] would be given 31 days of weight in January (e.g., in creating an annual average or climatology), which is correct.

There are reasonable instances where this wouldn't work. Imagine pentad data with a time point of 2020-02-02 12:00 with bounds of [2020-01-31 00:00, 2020-02-05 00:00]. This time point should be given one day of weight in January and four days of weight in February. The current algorithm (e.g., for monthly averaging) assigns all five days of weight in February (the labelled time point).

Describe the solution you'd like

Weights should be assigned based on the time period that they fall into. This would mean that a given time point can contribute to averages in more than one time interval

Describe alternatives you've considered

Solutions for the time being would be to update documentation to note that:

  • Weights are determined from the difference in the bounds
  • Data is grouped into the labelled time point for averaging operations
  • If one time point spans across the time intervals that you are averaging into, then weights are not properly assigned
  • get_time_bounds generally assumes data with frequencies of annual, monthly, daily, or sub-daily (I thought of this while writing this issue)
  • Perhaps other disclaimers I haven't thought of

Additional context

I'm not sure cdms / cdutil covers this case; it would be helpful to determine what cdutil does.

This seems like it could be challenging issue to address in general and might require a major refactor of the logic use for existing temporal averaging calculations.

@tomvothecoder
Copy link
Collaborator

I opened up PR #601 to implement the documentation updates suggested in your alternative solution.

@pochedls
Copy link
Collaborator Author

Just referencing this comment, which provides further discussion of this issue.

@pochedls
Copy link
Collaborator Author

FYI – @tomvothecoder – this is a pentad dataset that this issue would effect:

/p/user_pub/climate_work/pochedley1/msu/netcdf/uah_6.1-pentad_tlt_197901-202412.nc

@pochedls
Copy link
Collaborator Author

pochedls commented Feb 1, 2025

@tomvothecoder – I put together a notebook on this – maybe we could schedule a time to go over it? Or should I post it? Or just start a PR?

@tomvothecoder
Copy link
Collaborator

@tomvothecoder – I put together a notebook on this – maybe we could schedule a time to go over it? Or should I post it? Or just start a PR?

@pochedls You can start a new PR and commit it temporarily there, I'll analyze it, then we can go over it if needed. Thanks for starting work on this!

@pochedls
Copy link
Collaborator Author

pochedls commented Feb 6, 2025

@tomvothecoder - I've prototyped some new functionality in a new branch. It is not anywhere near complete – should I still do a PR (that way I could comment on it to help orient you)?

FYI: this is the prototype example of producing a monthly average from a pentad dataset with correct weights:

import xcdat as xc                                                                                                                                                    
fn = '/p/user_pub/climate_work/pochedley1/msu/netcdf/uah_6.1-pentad_tlt_197901-202412.nc'                                                                             
ds = xc.open_dataset(fn)                                                                                                                                              
ds = ds.spatial.average('tlt')                                                                                                                                        
dsa = ds.temporal.compute_monthly_average('tlt')   

@tomvothecoder
Copy link
Collaborator

@tomvothecoder - I've prototyped some new functionality in a new branch. It is not anywhere near complete – should I still do a PR (that way I could comment on it to help orient you)?

FYI: this is the prototype example of producing a monthly average from a pentad dataset with correct weights:

import xcdat as xc
fn = '/p/user_pub/climate_work/pochedley1/msu/netcdf/uah_6.1-pentad_tlt_197901-202412.nc'
ds = xc.open_dataset(fn)
ds = ds.spatial.average('tlt')
dsa = ds.temporal.compute_monthly_average('tlt')

Yes, a PR would be helpful to get things rolling. Thanks!

@pochedls pochedls linked a pull request Feb 10, 2025 that will close this issue
9 tasks
@tomvothecoder tomvothecoder moved this from Todo to In Progress in xCDAT Development Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New enhancement request
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants