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

Can we get some examples of how WebMapManager interfaces with the MapManagerCoreAPI #4

Open
cudmore opened this issue Apr 29, 2024 · 1 comment
Assignees
Labels
help wanted Extra attention is needed

Comments

@cudmore
Copy link
Member

cudmore commented Apr 29, 2024

Hi @Suhayb-A, Can you push a recent dev branch of WebMapManager? It is ok if some things are broken.

Can you post (here) some code examples of how you query the MapManagerCore API? And @jtle00, I know you worked on this within PyMapManager so any feedback is super welcome.

For example, when the viewer sets a new image slice, what is your code to request the point and line data to display?

Are you calling something like this in AnnotationsLayers

getAnnotations(self, options: AnnotationsOptions) -> list[Layer]:

With that as an example, can you give us some samples of the key/value pairs in options and the type of data it returns. Not sure getAnnotations() is a good example, please give better or more recent examples as needed.

Even just a code block of what options and list[Layers looks like would be great.

@cudmore cudmore added the help wanted Extra attention is needed label Apr 29, 2024
@cudmore
Copy link
Member Author

cudmore commented Apr 29, 2024

With a loaded map, I tried something like the following and get loads of key errors depending on my selection of options.

from mapmanagercore.annotations.layers import AnnotationsOptions, ImageViewSelection, AnnotationsSelection

options = AnnotationsOptions(
    selection=ImageViewSelection(z=(0,50)),
    annotationSelections=AnnotationsSelection(spineID=10, segmentID=0, segmentIDEditing=0),
    showSpines=True,
    showLineSegments=True,
    showAnchors=True,
    showLabels=False,
    showLineSegmentsRadius=False
)

layerList = map.getAnnotations(options)

With showSpines=False I get an empty list of layers. With showSPines=True I get the following error.

Please ignore if this is fixed in a more recent version.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[19], line 15
      3 from mapmanagercore.annotations.layers import AnnotationsOptions, ImageViewSelection, AnnotationsSelection
      5 options = AnnotationsOptions(
      6     selection=ImageViewSelection(z=(0,50)),
      7     annotationSelections=AnnotationsSelection(spineID=10, segmentID=0, segmentIDEditing=0),
   (...)
     12     showLineSegmentsRadius=False
     13 )
---> 15 layerList = map.getAnnotations(options)

File ~/Sites/MapManagerCore/mapmanagercore/annotations/layers.py:100, in AnnotationsLayers.getAnnotations(self, options)
     96     layers.extend(self._getSegments(
     97         zRange, selections["segmentIDEditing"], selections["segmentID"], options["showLineSegmentsRadius"]))
     99 if options["showSpines"]:
--> 100     layers.extend(self._getSpines(options))
    102 layers = [layer for layer in layers if not layer.empty()]
    104 return layers

File ~/Sites/MapManagerCore/mapmanagercore/annotations/layers.py:185, in AnnotationsLayers._getSpines(self, options)
    181     layers.extend(labels.splitGhost(
    182         visiblePoints, opacity=CONFIG["ghostOpacity"]))
    184 if selectedSpine in self._points.index:
--> 185     self._appendRois(
    186         self._points.loc[[selectedSpine]], editing, layers)
    188 return layers

File ~/Sites/MapManagerCore/mapmanagercore/annotations/layers.py:193, in AnnotationsLayers._appendRois(self, spineDf, editing, layers)
    190 @timer
    191 def _appendRois(self, spineDf: gp.GeoDataFrame, editing: bool, layers: List[Layer]):
    192     boarderWidth = CONFIG["roiStrokeWidth"]
--> 193     segments = spineDf[["anchor", "segmentID"]].join(
    194         self._lineSegments[["segment", "radius"]], on="segmentID",)
    196     def radius(id):
    197         return segments.loc[id, "radius"]

File ~/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/frame.py:10744, in DataFrame.join(self, other, on, how, lsuffix, rsuffix, sort, validate)
  10734     if how == "cross":
  10735         return merge(
  10736             self,
  10737             other,
   (...)
  10742             validate=validate,
  10743         )
> 10744     return merge(
  10745         self,
  10746         other,
  10747         left_on=on,
  10748         how=how,
  10749         left_index=on is None,
  10750         right_index=True,
  10751         suffixes=(lsuffix, rsuffix),
  10752         sort=sort,
  10753         validate=validate,
  10754     )
  10755 else:
  10756     if on is not None:

File ~/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/reshape/merge.py:170, in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
    155     return _cross_merge(
    156         left_df,
    157         right_df,
   (...)
    167         copy=copy,
    168     )
    169 else:
--> 170     op = _MergeOperation(
    171         left_df,
    172         right_df,
    173         how=how,
    174         on=on,
    175         left_on=left_on,
    176         right_on=right_on,
    177         left_index=left_index,
    178         right_index=right_index,
    179         sort=sort,
    180         suffixes=suffixes,
    181         indicator=indicator,
    182         validate=validate,
    183     )
    184     return op.get_result(copy=copy)

File ~/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/reshape/merge.py:786, in _MergeOperation.__init__(self, left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, indicator, validate)
    779     msg = (
    780         "Not allowed to merge between different levels. "
    781         f"({_left.columns.nlevels} levels on the left, "
    782         f"{_right.columns.nlevels} on the right)"
    783     )
    784     raise MergeError(msg)
--> 786 self.left_on, self.right_on = self._validate_left_right_on(left_on, right_on)
    788 (
    789     self.left_join_keys,
    790     self.right_join_keys,
   (...)
    793     right_drop,
    794 ) = self._get_merge_keys()
    796 if left_drop:

File ~/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/reshape/merge.py:1607, in _MergeOperation._validate_left_right_on(self, left_on, right_on)
   1605     if self.right_index:
   1606         if len(left_on) != self.right.index.nlevels:
-> 1607             raise ValueError(
   1608                 "len(left_on) must equal the number "
   1609                 'of levels in the index of "right"'
   1610             )
   1611         right_on = [None] * n
   1612 elif right_on is not None:

ValueError: len(left_on) must equal the number of levels in the index of "right"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants