hainegroup / oceanspy

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

poseidon viewer integration #285

Closed Mikejmnez closed 1 year ago

Mikejmnez commented 1 year ago

Description

We need to integrate the Poseidon viewer with oceanspy. There remain unresolved issues with the poseidon viewer since Sept 4th , see here: https://github.com/sciserver/poseidon-viewer/issues/4

Nonetheless, Mitya pointed out that we can still extract the coordinates from the poseidon viewerapp. To do this, we first need to:

  1. Create the polygon or line on the app.
  2. Select the "shape" with the little hand on the toolbar. A successful selection of the shape changes its color from orange into blue.
  3. Select "extract" or "copy onto clipboard" (second option from right to left on the toolbar atop the viewer). A message should display at the bottom of the viewer that states: "Data copied to clipboard".
  4. On a cell in a jupyter notebook, just paste the data exported. This is done simply withctrl+c (or command+c). It is best to assigned first a variable. For now lets call it (by convention, the way Mytia first called it) p

There are three types of data selection from the Poseidon Viewer. These are:

Polygon.

See example below:

Polygon

A LineString

See example below:

LineString

A Point

Point

One a notebook, the data looks like:

Screen Shot 2022-12-07 at 6 45 03 PM

The above snapshot is for the first example. You can tell because the extracted data contains information about the nature of the shape ('type':'Polygon').

What I Did

To integrate the poseidon viewer with oceanspy, we need to extract the coordinates from the variable p. There are two ways I can think of:

  1. create a function poseidon_to_range() that returns the desired data in the right format for oceanspy. This is:

    lon, lat = _poseidon_to_range(p)

    Then lon and lat are passed as arguments into oceanspy.

  2. Modify each function within oceanspy.subsample (e.g. cutout, mooring, survey) so that p can be used as an argument. That is, the above function _poseidon_to_range(p) is called internally by oceanspy.subsample.fn. This has the advantange that there is minimal difference from the user point of view.

I decided to follow 1, the simplest way. We can always do 2 later. Expect a PR soon enough

Mikejmnez commented 1 year ago

I created a function on PR #286 that takes the extracted data from the poseidon viewer. The PR is already merged and works is as follows:

lon, lat = viewer_to_range(p)

where the variable p contains the data extracted directly from the poseidon viewer.

This approach follows item # 1 above. Meaning, the variable p is not passed as an argument into oceanspy. Instead the user must extract longitude and latitudes from variable p via viewer_to_range

I am leaving this issue open, so people can comment, particularly on whether the approach # 2 detailed above is of interest. It will take some work but should be pretty easy. For now, oceanspy + poseidon viewer already work together.

I am uploading a working notebook into shared notebooks. The notebook is called Ospy_PoseidonViewer.ipynb. I also added three png files (Polygon.png, LineString.png and Point.png) that illustrate the way I extracted the three different objects / Data/section from the poseidon viewer.

Mikejmnez commented 1 year ago

With the poseidon issues resolved (see https://github.com/sciserver/poseidon-viewer/issues/4 for a description of the previous errors), we can now import the data from a jupyter notebook cell as follows:

from poseidon_viewer import get_shapes
p = get_shapes()

This approach is different from the way I described originally the integration of poseidon_viewer with oceanspy (see above), which relies on using keyboard shortcuts (ctrl+c or command+c) to paste the data copied from the poseidon viewer into a cell. Moreover, while the two approaches yield the same data, the types are different...

  1. Using keyboard shortcut (see above). The data looks like:
    >> p1 = [{"type":"Polygon","coordinates":[[[-44.93392070484584,3.829744170820163],[-44.93392070484584,-44.89627001277938],[10.83700440528633,-45.45524212082172],[8.458149779735672,4.093429555257572],[-44.93392070484584,3.829744170820163]]]}]
    >> type(p1)
    list
  2. Using get_shapes():
    >> p2 = get_shapes()
    >> type(p2)
    str

The problem:

When I wrote (and tested) the function viewer_to_range(p), which takes the data from the poseidon viewer and extracts lat and lon arrays, I wrote this function so that it takes a list as argument. The issue ( https://github.com/sciserver/poseidon-viewer/issues/4) was either unfixed or I didn't know it was fixed. As a result, viewer_to_range(p) is NOT compatible with get_shapes().

Solution

Solution is super simple, a single line. But it will require also a test.

Expect a PR soon!

Mikejmnez commented 1 year ago

closed by #300