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

Point to profile data #30

Closed
dhruvbalwada opened this issue Sep 28, 2020 · 3 comments
Closed

Point to profile data #30

dhruvbalwada opened this issue Sep 28, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@dhruvbalwada
Copy link
Member

Is your feature request related to a problem? Please describe.
It would be great to able to convert the data from point to profile type. Currently, the data is saved as a long series of variables. It is quite natural instead to sometimes refer to data in terms of dive numbers.
This can also help resolve the issue that we currently always look at the down casts in order of increasing Z and upcasts in decreasing Z, which can create visual artifacts in scatter plots.

Describe the solution you'd like
The simplest solution would be to adopt the points-profiles style that argopy is using in https://argopy.readthedocs.io/en/latest/_modules/argopy/xarray.html#ArgoAccessor.point2profile

Maybe we don't need to have data types, but a simpler (maybe more hacky) solution would be great for an initial solution.

@dhruvbalwada dhruvbalwada self-assigned this Sep 28, 2020
@dhruvbalwada dhruvbalwada added the enhancement New feature or request label Sep 28, 2020
@lukegre
Copy link
Member

lukegre commented Oct 11, 2020

Potential hack solution to create a dictionary using groupby on the dives. Might be slow though. Also, does not provide one with any functions that can be applied to each dive

import glidertools as gt

vars = ['temperature']
name = 'Git/GliderTools/tests/data/p54203*.nc'
dim = 'sg_data_point'
xds = gt.load.seaglider_basestation_netCDFs(name, vars)[dim]

grp = xds.groupby('dives')

out = {}
for k, i in grp.groups.items():
    out[k] = xds.isel(**{dim: i}).sortby('ctd_depth')

@MartinMohrmann
Copy link
Member

MartinMohrmann commented Feb 14, 2023

Hi, I am aware that this is an old issue - but I fought with it to an came up with some good solutions :). An easy and fast way to convert the point-data to profile-data is the groupby function as @lukegre mentioned. Once the data is grouped into profiles, any function can be applied with the pandas/xarray map or apply methods. If used on dask-arrays, the per-profile functions run in parallel which makes processing very fast.

ds.groupby("dives"
   ).apply(function, input_variables)

I also have a considerable speed increase if my ds-object is a pandas.Dataframe instead of a xarray.Dataset. Casting can be done by ds.to_pandas() or ds.reset_coords().to_pandas() if your dataset had multiple coordinates from the start.

edit: I just created a pull request for the computation of mixed layer depth (#169). It should be easy to adapt for e.g. profile means, BVF or other per-profile computations. :)

@MartinMohrmann
Copy link
Member

This was addressed in PR #175, have a look at the new version.
Closed, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants