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

add custom season method #411

Merged
merged 29 commits into from
Jul 7, 2023
Merged

Conversation

jukent
Copy link
Contributor

@jukent jukent commented May 11, 2023

PR Summary

Adds custom season list as kwarg for climatology_average
Closes #198

PR Checklist

General

  • Make an issue if one doesn't already exist
  • Link the issue this PR resolves by adding closes #XXX to the PR description where XXX is the number of the issue.
  • Add a brief summary of changes to docs/release-notes.rst
  • Add appropriate labels to this PR
  • Make your changes in a forked repository rather than directly in this repo
  • Open this PR as a draft if it is not ready for review
  • Convert this PR from a draft to a full PR before requesting reviewers
  • Request @NCAR/geocat for reviews
  • Passes precommit. To set up on your local, run pre-commit install from the top level of the repository. To manually run pre-commits, use pre-commit run --all-files and re-add any changed files before committing again and pushing.

Functionality

  • Function is in appropriate module file
  • New function(s) intended for public API added to src/geocat/comp/__init__.py file

Testing

  • Tests for function exists in associated module test file
  • Tests cover all possible logical paths in your function

Documentation

  • Docstrings have been added to all new functions (Documentation Standards)
  • Docstrings have updated with any function changes
  • Internal functions have a preceding underscore (_) and have been added to docs/internal_api/index.rst
  • User facing functions have been added to docs/user_api/index.rst under their module

@jukent jukent added the feature a new feature that is going to be developed label May 11, 2023
@jukent
Copy link
Contributor Author

jukent commented May 11, 2023

Target final dataset:
Screen Shot 2023-05-11 at 3 50 57 PM

vs what we currently have:
Screen Shot 2023-05-11 at 3 50 37 PM

I have the values matching up, and am still wrestling with the Xarray dimension(?) name where it says SON instead of season. (it says dimensions are (`SON1,) but when I go to rename the dimension it says SON isn't a dimension so idk)

Also I'm not sure if we want to add a pandas season index/ if that means something specific to the typical seasons (will research this).

And one issue is that in order to get this values. I have to comment out this block of code borrowed from month_to_season:

# For this season, the last "mean" will be the value for Dec so we drop the last month
if season == 'DJF':
    data_filter = data_filter.isel(
        {time_dim: slice(None, -1)})
# For this season, the first "mean" will be the value for Jan so we drop the first month
elif season == 'NDJ':
    data_filter = data_filter.isel(
        {time_dim: slice(1, None)})

or else that values are off in DJF. I need to look at this math more and know if this is right to not implement (as in are we doing it correctly in the non-custom season version). Any thoughts on that @anissa111

I want to answer these questions and solve the dimension thing before I add tests, so I know whether to say identical objects or identical values and dimensions.

@jukent
Copy link
Contributor Author

jukent commented May 11, 2023

Didn't expect this to fail tests in test_climate_anomaly as well as test_climate_average. Will look into this tomorrow hopefully.

@jukent jukent self-assigned this May 11, 2023
@anissa111
Copy link
Member

@jukent I'm not sure I know enough about that to have any valuable thoughts right now. I think it could make sense that the two implementations are different enough that this version wouldn't need that block, but I'd want to understand the underlying reason why, does that make sense?

@jukent
Copy link
Contributor Author

jukent commented May 11, 2023

Yeah that makes sense. I think when we want winter from one year, we have to deal with it being over the year break. But when we want winter from all years, it doesn't matter if January is in this winter or the next. Like the grouping of December 22 of January 23 together.

There is still the very first and very last year that could be affected? And that causes the small discrepancy. My hunch is that since we're going through months first it isn't needed or wanted but I'll lay it out better tomorrow.

@jukent jukent marked this pull request as ready for review May 12, 2023 18:25
@jukent jukent requested a review from a team May 12, 2023 18:25
@jukent
Copy link
Contributor Author

jukent commented May 16, 2023

Related to #313

@jukent jukent requested a review from anissa111 May 16, 2023 14:44
Copy link
Member

@anissa111 anissa111 left a comment

Choose a reason for hiding this comment

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

I'm a bit concerned with the logic flow as written as mentioned in a few of my comments below for a few reasons, some of which predate this PR

  1. I am a little uncozy with the logic structure of
if <this setting>:
    do all analysis
    return

if <next setting>:
    do all analysis
    return
  1. This introduces some edge cases such as what happens if the user specifies custom seasons, but a frequency of anything other than 'season'
  2. Apart from the general uncozy mentioned in (1), I think we could be making better use of the custom_seasons optional argument here. What if we used a default of custom_seasons = ['DJF', 'MAM', 'JJA', 'SON'] and then performed the calculation for seasons in the same way instead of separating the season calculation into a "custom" or "default" section? I would think, ideally, the same calculations for custom season should also work for the standard, correct?
  3. Seeing the code in this PR, I'm again not totally sure why you've changed some of the inputs to kwargs instead of just arguments.

Anyway, sorry for the late review, let me know if you'd like a dedicated time for me to explain some of my questions/thinking on suggestions!

src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
src/geocat/comp/climatologies.py Outdated Show resolved Hide resolved
@jukent
Copy link
Contributor Author

jukent commented May 19, 2023

  1. If the user specifies custom seasons but daily climatoloty, currently the frequency trumps it and the user would get daily climatology. You're right to point that out though. I think that is the behavior we want, but maybe raise a warning to say that their custom seasons will be ignored.
  2. Good points. We could do some analysis to see if Xarray's method is faster at all -- but that would work and sounds cleaner for sure.

I'll address your other points and make some edits on Monday.

@jukent jukent requested a review from anissa111 June 29, 2023 20:22
@jukent
Copy link
Contributor Author

jukent commented Jun 29, 2023

Passing local tests!

Copy link
Member

@anissa111 anissa111 left a comment

Choose a reason for hiding this comment

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

Mostly just comments from this morning's meeting. I did manage to write something that might be a little more readable for that one section I said I'd take a stab at.

geocat/comp/climatologies.py Show resolved Hide resolved
geocat/comp/climatologies.py Outdated Show resolved Hide resolved
geocat/comp/climatologies.py Outdated Show resolved Hide resolved
geocat/comp/climatologies.py Outdated Show resolved Hide resolved
geocat/comp/climatologies.py Outdated Show resolved Hide resolved
test/test_climatologies.py Show resolved Hide resolved
@jukent jukent requested a review from anissa111 July 7, 2023 20:20
@jukent jukent requested a review from anissa111 July 7, 2023 20:36
Copy link
Member

@anissa111 anissa111 left a comment

Choose a reason for hiding this comment

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

This should be good to go when the tests finish! Good job!!

@jukent jukent merged commit 2e7c1f5 into NCAR:main Jul 7, 2023
8 checks passed
@jukent jukent deleted the custom_season_climatology branch July 7, 2023 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a new feature that is going to be developed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow user to define seasonal boundaries for climatology_average
2 participants