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 new tutorial video #6353

Merged
merged 4 commits into from
Mar 16, 2022
Merged

Add new tutorial video #6353

merged 4 commits into from
Mar 16, 2022

Conversation

dcherian
Copy link
Contributor

No description provided.

@mathause
Copy link
Collaborator

Nice! I did not know about coarsen(...).construct(...) - interesting. I usually use set_index for that - could be interesting to test which approach is faster.

def _to_seasonal(ds):

    year = ds.time.dt.year.data
    season = ds.time.dt.season.data

    # assign new coords
    ds = ds.assign_coords(year=("time", year), season=("time", season))

    # reshape the array to (..., "season", "year")
    return ds.set_index(time=("year", "season")).unstack("time")

@max-sixty
Copy link
Collaborator

Very good video @dcherian !

@dcherian dcherian merged commit 95bb9ae into pydata:main Mar 16, 2022
@dcherian dcherian deleted the add-video branch March 16, 2022 03:49
@dcherian
Copy link
Contributor Author

@mathause I suspect coarsen.construct is faster because it's a simple reshape (ignoring the copies associated with handling the boundary condition):

return variable.data.reshape(shape), tuple(axes)

Unstacking allocates a new array and then assigns all values. It is definitely the more general solution though.

We should discuss this in the proposed cookbook (#1790)

@dcherian dcherian added this to To Do in Cookbook via automation Mar 16, 2022
dcherian added a commit to bzah/xarray that referenced this pull request Mar 18, 2022
* main: (34 commits)
  Explicit indexes (pydata#5692)
  Remove test_rasterio_vrt_network (pydata#6371)
  Allow write_empty_chunks to be set in Zarr encoding (pydata#6348)
  Add new tutorial video (pydata#6353)
  Revert "explicitly install `ipython_genutils` (pydata#6350)" (pydata#6361)
  [pre-commit.ci] pre-commit autoupdate (pydata#6357)
  Run pyupgrade on core/groupby (pydata#6351)
  Generate reductions for DataArray, Dataset, GroupBy and Resample (pydata#5950)
  explicitly install `ipython_genutils` (pydata#6350)
  Bump actions/setup-python from 2 to 3 (pydata#6338)
  Bump actions/checkout from 2 to 3 (pydata#6337)
  In documentation on adding a new backend, add missing import and tweak headings (pydata#6330)
  Lengthen underline, correct spelling, and reword (pydata#6326)
  quantile: use skipna=None (pydata#6303)
  New whatsnew section
  v2022.03.0 release notes (pydata#6319)
  fix typos (using codespell) (pydata#6316)
  Add General issue template (pydata#6314)
  Disable CI runs on forks (pydata#6315)
  Enable running sphinx-build on Windows (pydata#6237)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants