NCAS-CMS / NCAS-CMS/cf-python

Feature request for a method which allows one to subspace something which has a structure

Open
#684 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
150
Forks
23
Avg merge
1d 11h
Merged PRs (30d)
2

Description

Feature request for a cf.Field.group() method like subspace, but which allows one to subspace something which has a structure:

E.g., Subsetting data only for the extended winter (ONDJFM) from 2018-2020:

>>> ondjfm = a.subspace(T=cf.seasons(2, 10)[0] & cf.wi(cf.dt('2018-10-1'), cf.dt('2020-03-1')))
>>> print(ondjfm.coordinate("long_name=time").dtarray)
[cftime.DatetimeGregorian(2018, 10, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2018, 11, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2018, 12, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 1, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 2, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 3, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 10, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 11, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2019, 12, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2020, 1, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2020, 2, 1, 0, 0, 0, 0, has_year_zero=False)
 cftime.DatetimeGregorian(2020, 3, 1, 0, 0, 0, 0, has_year_zero=False)]

It would also take parameters like group_span (to include groups whose actual span is not equal to a given value) and group_contiguous (to include non-contiguous groups, or any contiguous group containing overlapping cells). A similar functionality is embedded in collapse but it works only when one has to collapse axes of the field.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing subspace and collapse entry points on cf.Field, since the request describes the new cf.Field.group() method as related to both. Compare the example's seasonal and date-range selection with the requested group_span and group_contiguous parameters. Done means a documented method can select structured, non-contiguous or overlapping groups as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.