NCAS-CMS / NCAS-CMS/cf-python

Provide numbered view of a `FieldList`

Open
#790 3 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

A user has requested that we provide a representation of a FieldList that includes numbering of the fields. I can see that this would be really useful, because when you want to pick a specific one out you might well (especially if unaware of our filtering or reduction methods), in the absence of such numbers, count up from the first and/or back from the last to get the give field you want to pick out and particularly when it contains a lot of fields this can involve a lot of counting and possibly inaccuracy.

For instance, imagine you want the field <CF Field: long_name=O3 MASS MIXING RATIO AFTER TIMESTEP(ncdim%obs(13150)) 1> from this:

>>> f
[<CF Field: air_pressure(ncdim%obs(155419)) hPa>,
 <CF Field: air_pressure(ncdim%obs(155419)) hPa>,
 <CF Field: air_pressure(ncdim%obs(155419)) hPa>,
 <CF Field: altitude(ncdim%obs(155419)) m>,
 <CF Field: altitude(ncdim%obs(155419)) m>,
 <CF Field: altitude(ncdim%obs(155419)) m>,
 <CF Field: latitude(ncdim%obs(155419)) degree_north>,
 <CF Field: latitude(ncdim%obs(13150)) degrees north>,
 <CF Field: latitude(ncdim%obs(155419)) degree_north>,
 <CF Field: latitude(ncdim%obs(155419)) degree_north>,
 <CF Field: longitude(ncdim%obs(155419)) degree_east>,
 <CF Field: longitude(ncdim%obs(13150)) unknown>,
 <CF Field: longitude(ncdim%obs(155419)) degree_east>,
 <CF Field: longitude(ncdim%obs(155419)) degree_east>,
 <CF Field: long_name=O3 MASS MIXING RATIO AFTER TIMESTEP(ncdim%obs(13150)) 1>,
 <CF Field: long_name=O3 MASS MIXING RATIO AFTER TIMESTEP(ncdim%obs(155419)) 1>,
 <CF Field: long_name=O3 MASS MIXING RATIO ON PRESS LEVS(ncdim%obs(155419)) 1>,
 <CF Field: long_name=CO MASS MIX RATIO ON PRESS LEVS(ncdim%obs(155419)) 1>,
 <CF Field: region(ncdim%obs(155419)) 1>,
 <CF Field: region(ncdim%obs(13150)) unknown>,
 <CF Field: region(ncdim%obs(155419)) 1>,
 <CF Field: region(ncdim%obs(155419)) 1>,
 <CF Field: time(ncdim%obs(155419)) days since 1900-01-01 standard>,
 <CF Field: time(ncdim%obs(13150)) days since 1900-01-01 standard>,
 <CF Field: time(ncdim%obs(155419)) days since 1900-01-01 standard>,
 <CF Field: time(ncdim%obs(155419)) days since 1900-01-01 standard>]

I suggest we have the repr as above and have the str representation which includes the numbered view like this or similar:

>>> print(f)
0| [<CF Field: air_pressure(ncdim%obs(155419)) hPa>,
1|  <CF Field: air_pressure(ncdim%obs(155419)) hPa>,
2|  <CF Field: air_pressure(ncdim%obs(155419)) hPa>,
3|  <CF Field: altitude(ncdim%obs(155419)) m>,
...

(Suggesting a line-numbering type view format for the numbering to make it clear it is not a dictionary with index keys.).
Or we can include a keyword to str() that can be passed to print(), but I doubt that would get much use unless really well-advertised.

Probably easiest to implement along with #772, which also suggests improvement upon the representation of a FieldList.

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 locating the FieldList implementation and its existing repr and str behavior, then review issue #772 for related representation changes. Confirm the current output before designing the numbered view. Done means printing a FieldList shows each field with a clear numeric prefix while repr remains as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.