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

Generalise traj for discrete sampling geometry trajectories #84

Open
sadielbartholomew opened this issue Jan 30, 2025 · 0 comments
Open

Comments

@sadielbartholomew
Copy link
Member

sadielbartholomew commented Jan 30, 2025

The cfp.traj method presently works to make a horizontal-coordinate planar (projected) plot* for specific formats of trajectories, documented here as for "data stored in contiguous ragged array format" but possibly more general than that. From my limited empirical use and a skim read of the code, it seems to be written to work for paths encoded as 2D arrays only. However, a glaring deficiency is for DSG features, which store the path in a lower dimension than that of the spacetime region it samples - therefore potentially in 1D for 2D or 3D path, or 2D for a 3D path, etc. So, we want to add support for paths encoded as a CF-compliant DSG form with featureType = 'trajectory' by catering for reduced dimensionality.

I have already solved this deficiency on a branch for VISION-project related work but was using that branch standalone as a temporary solution - it is about time I tidied it, tested it, and included it in the main branch, since I am due to do a new release and it will be very useful to have this included. PR to follow.

* see Issue TBC where I am also proposing adding support for plots against the vertical coordinate for trajectories. For example, at the moment one can use traj to plot (if the data is in suitable format, as per this Issue) a flight path to see where it goes in X-Y across the Earth's surface, but not its rise and fall in the vertical coordinate.

Current error when attempting to read a DSG trajectory dataset

With the following attempting traj call on such a DSG dataset:

import cfplot as cfp
import cf


DATA_PATH = "/home/slb93/git-repos/cf-python/cf/test/dsg_trajectory.nc"

f = cf.read(DATA_PATH)[0]
print(f)

cfp.traj(f)
print("Success - check plot for a plotted trajectory")

upon attempting to plot you get, on the current main branch:

Field: mole_fraction_of_ozone_in_air (ncvar%O3_TECO)
----------------------------------------------------
Data            : mole_fraction_of_ozone_in_air(ncdim%obs(258)) ppb
Cell methods    : time: point
Auxiliary coords: time(ncdim%obs(258)) = [2017-07-03 11:15:00, ..., 2017-07-03 11:31:52]
                : altitude(ncdim%obs(258)) = [2577.927001953125, ..., 176.66555786132812] m
                : air_pressure(ncdim%obs(258)) = [751.6758422851562, ..., 1003.8636474609375] hPa
                : latitude(ncdim%obs(258)) = [52.56147766113281, ..., 52.82619094848633] degrees_north
                : longitude(ncdim%obs(258)) = [3.317183256149292, ..., 4.942849636077881] degrees_east
                : cf_role=trajectory_id(cf_role=trajectory_id(1)) = [FLIGHT]
Traceback (most recent call last):
  File "/home/slb93/git-repos/cf-plot/cfplot/test/traj-mwe.py", line 10, in <module>
    cfp.traj(f)
  File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 9321, in traj
    data2 = data[track, :]
            ~~~~^^^^^^^^^^
  File "/home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/numpy/ma/core.py", line 3228, in __getitem__
    dout = self.data[indx]
           ~~~~~~~~~^^^^^^
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
@sadielbartholomew sadielbartholomew self-assigned this Jan 30, 2025
@sadielbartholomew sadielbartholomew changed the title Generalise traj to work for discrete sampling geometry trajectories Generalise traj for discrete sampling geometry trajectories Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant