hainegroup / oceanspy

A Python package to facilitate ocean model data analysis and visualization.
https://oceanspy.readthedocs.io
MIT License
96 stars 32 forks source link

update viewer_to_range to extract time range #405

Closed Mikejmnez closed 5 months ago

Mikejmnez commented 6 months ago

Description

The poseidon viewer can now extract time range, but because ospy.utils.viewer_to_range() was written before that, it needs a little extra lines of code to accomplish that.

The following example illustrates how to extract time range, taken from work - in -progress tutorial for Poseidon viewer interface:

from poseidon_viewer import get_shapes
import json, jmespath

# From the Poseidon-viewer save to disk function:
shapes = json.loads(get_shapes())
ps = jmespath.search('features[?geometry.type==\'Point\'].{type:geometry.type, coordinates:geometry.coordinates,timeFrom:properties.timeFrom,timeTo:properties.timeTo}', shapes)
this_time = ps[0]['timeFrom'][:-1]

lons, lats = ospy.utils.viewer_to_range(ps)

Proposed new feature:

timeRange, lons, lats =   ospy.utils.viewer_to_range(json.loads(get_shapes()))

this requires a minimal change to viewer_to_range... i will work on this early next week...

Mikejmnez commented 5 months ago

closed by #408