Enable plotting of cfdm fields with cfplot

Open
#166 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python

Research direction

Start by reproducing the cfp.con examples with tas_A1.nc, comparing the working cf field with the failing cfdm field and its reported shapes. Trace the cfplot input validation around check_data; done means a cfdm field can be plotted successfully, with any required coordination between cfdm and cfplot resolved.

Written by the indexing model from the issue text.

Description

enhancement

In recent discussions relating to the CF Training course, we agreed it would be useful to be able to plot cfdm fields, and not just cf-python fields, with cfplot. Some work would probably need to be done on both the cfdm and cfplot side to make this possible.

For example, with the latest versions of all of the libraries, taking a simple example (lifted from the documentation and using one of the sample data sets) with trying to plot a field read-in via cf and cfdm separately, the cf field plots fine but the cfdm one runs into some cfplot errors due to shape:

>>> import cfplot as cfp
>>> import cf
>>> import cfdm

>>> cf.__version__
'3.11.0'
>>> cfdm.__version__
'1.9.0.1'
>>> cfp.__version__
'3.1.17'

>>> cf_f = cf.read('tas_A1.nc')[0]
>>> cfdm_f = cfdm.read('tas_A1.nc')[0]

>>> cfp.con(cf_f[0,0::])  # plots successfully
>>> cfp.con(cfdm_f[0,0::])  # errors
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfplot/cfplot.py", line 401, in con
    check_data(field, x, y)
  File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfplot/cfplot.py", line 3779, in check_data
    raise Warning(errstr)
Warning: 
Input arguments incorrectly shaped:
x has shape:(73,)
y has shape:(1,)
field has shape(1, 73, 96)

Expected x=xpts, y=ypts, field=(ypts,xpts)
x=npts, y=npts, field=npts
or x=[ypts, xpts], y=[ypts, xpts], field=[ypts, xpts]
Dominant language
Python
Stars
32
Forks
14
Avg merge
3d 20h
Merged PRs (30d)
1

Getting set up

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.

More from NCAS-CMS/cfdm

All issues in NCAS-CMS/cfdm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.