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

Feat: User defined output frequency #44

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

pgierz
Copy link
Member

@pgierz pgierz commented Oct 9, 2024

Closes #9

@chrisdane: Can you see if this does what you want, and is adequately documented?

@pgierz pgierz added documentation Improvements or additions to documentation enhancement New feature or request interface labels Oct 9, 2024
@pgierz pgierz added this to the Beta Release milestone Oct 9, 2024
@pgierz pgierz self-assigned this Oct 9, 2024
@pgierz
Copy link
Member Author

pgierz commented Oct 9, 2024

@chrisdane
Copy link

Whats the difference between YE and YS? Documentation is ok but cannot say much to the code.

@pgierz
Copy link
Member Author

pgierz commented Oct 9, 2024

As far as I am aware, it controls the timestamp sampling (beginning vs. end) that is puts into the records:

>>> import xarray as xr
>>> ds = xr.tutorial.load_dataset("air_temperature")
>>> ds.resample(time="MS").groups
{numpy.datetime64('2013-01-01T00:00:00.000000000'): slice(0, 124, None),
 numpy.datetime64('2013-02-01T00:00:00.000000000'): slice(124, 236, None),
 numpy.datetime64('2013-03-01T00:00:00.000000000'): slice(236, 360, None),
 numpy.datetime64('2013-04-01T00:00:00.000000000'): slice(360, 480, None),
 numpy.datetime64('2013-05-01T00:00:00.000000000'): slice(480, 604, None),
 numpy.datetime64('2013-06-01T00:00:00.000000000'): slice(604, 724, None),
 numpy.datetime64('2013-07-01T00:00:00.000000000'): slice(724, 848, None),
 numpy.datetime64('2013-08-01T00:00:00.000000000'): slice(848, 972, None),
 numpy.datetime64('2013-09-01T00:00:00.000000000'): slice(972, 1092, None),
 numpy.datetime64('2013-10-01T00:00:00.000000000'): slice(1092, 1216, None),
 numpy.datetime64('2013-11-01T00:00:00.000000000'): slice(1216, 1336, None),
 numpy.datetime64('2013-12-01T00:00:00.000000000'): slice(1336, 1460, None),
 numpy.datetime64('2014-01-01T00:00:00.000000000'): slice(1460, 1584, None),
 numpy.datetime64('2014-02-01T00:00:00.000000000'): slice(1584, 1696, None),
 numpy.datetime64('2014-03-01T00:00:00.000000000'): slice(1696, 1820, None),
 numpy.datetime64('2014-04-01T00:00:00.000000000'): slice(1820, 1940, None),
 numpy.datetime64('2014-05-01T00:00:00.000000000'): slice(1940, 2064, None),
 numpy.datetime64('2014-06-01T00:00:00.000000000'): slice(2064, 2184, None),
 numpy.datetime64('2014-07-01T00:00:00.000000000'): slice(2184, 2308, None),
 numpy.datetime64('2014-08-01T00:00:00.000000000'): slice(2308, 2432, None),
 numpy.datetime64('2014-09-01T00:00:00.000000000'): slice(2432, 2552, None),
 numpy.datetime64('2014-10-01T00:00:00.000000000'): slice(2552, 2676, None),
 numpy.datetime64('2014-11-01T00:00:00.000000000'): slice(2676, 2796, None),
 numpy.datetime64('2014-12-01T00:00:00.000000000'): slice(2796, None, None)}
>>> ds.resample(time="ME").groups
{numpy.datetime64('2013-01-31T00:00:00.000000000'): slice(0, 124, None),
 numpy.datetime64('2013-02-28T00:00:00.000000000'): slice(124, 236, None),
 numpy.datetime64('2013-03-31T00:00:00.000000000'): slice(236, 360, None),
 numpy.datetime64('2013-04-30T00:00:00.000000000'): slice(360, 480, None),
 numpy.datetime64('2013-05-31T00:00:00.000000000'): slice(480, 604, None),
 numpy.datetime64('2013-06-30T00:00:00.000000000'): slice(604, 724, None),
 numpy.datetime64('2013-07-31T00:00:00.000000000'): slice(724, 848, None),
 numpy.datetime64('2013-08-31T00:00:00.000000000'): slice(848, 972, None),
 numpy.datetime64('2013-09-30T00:00:00.000000000'): slice(972, 1092, None),
 numpy.datetime64('2013-10-31T00:00:00.000000000'): slice(1092, 1216, None),
 numpy.datetime64('2013-11-30T00:00:00.000000000'): slice(1216, 1336, None),
 numpy.datetime64('2013-12-31T00:00:00.000000000'): slice(1336, 1460, None),
 numpy.datetime64('2014-01-31T00:00:00.000000000'): slice(1460, 1584, None),
 numpy.datetime64('2014-02-28T00:00:00.000000000'): slice(1584, 1696, None),
 numpy.datetime64('2014-03-31T00:00:00.000000000'): slice(1696, 1820, None),
 numpy.datetime64('2014-04-30T00:00:00.000000000'): slice(1820, 1940, None),
 numpy.datetime64('2014-05-31T00:00:00.000000000'): slice(1940, 2064, None),
 numpy.datetime64('2014-06-30T00:00:00.000000000'): slice(2064, 2184, None),
 numpy.datetime64('2014-07-31T00:00:00.000000000'): slice(2184, 2308, None),
 numpy.datetime64('2014-08-31T00:00:00.000000000'): slice(2308, 2432, None),
 numpy.datetime64('2014-09-30T00:00:00.000000000'): slice(2432, 2552, None),
 numpy.datetime64('2014-10-31T00:00:00.000000000'): slice(2552, 2676, None),
 numpy.datetime64('2014-11-30T00:00:00.000000000'): slice(2676, 2796, None),
 numpy.datetime64('2014-12-31T00:00:00.000000000'): slice(2796, None, None)}

@chrisdane
Copy link

Ok. Is the middle of a time period also defined? I cannot find this in the documentation.

The middle is usually used, so e.g. yyyy-mm-15 or -16 in case of monthly output. See e.g. the documentation from cdo (e.g. cdo -h monmean):

DESCRIPTION
The time of outfile is determined by the time in the middle of all contributing timesteps of infile.
This can be change with the CDO option --timestat_date <first|middle|last>.

@pgierz
Copy link
Member Author

pgierz commented Oct 11, 2024

Is the middle of a time period also defined?

Not natively, we would need to implement that as a separate correction step. I'll see what I can do.

@pgierz
Copy link
Member Author

pgierz commented Oct 11, 2024

Alright, I have something that sort-of works:

https://pymorize.readthedocs.io/en/feat-user_frequency/api/pymorize.html#pymorize.timeaverage.custom_resample

Maybe @siligam can have a look and hook it up to the rest of his averaging functionality.

@pgierz pgierz assigned siligam and unassigned pgierz Oct 11, 2024
@pgierz pgierz changed the title Feat/user frequency Feat: User defined output frequency Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time blocking of various in --> out file numbers
3 participants