mobie / mobie-utils-python

Python tools for MoBIE
MIT License
9 stars 5 forks source link

`get_view` und transformed sources #104

Closed martinschorb closed 1 year ago

martinschorb commented 1 year ago

Hi,

I have a convoluted view where I have specific imageDisplay sets for differently transformed versions of a single source (through sourceNamesAfterTransform). Something like shifting a single source multiple times while gradually reducing opacity and still displaying all of these derived sources in a single view. I think this scenario should be possible (different displays for different sourceNamesAfterTransform from one source).

It seems get_view needs all sources to be specified in the parameters https://github.com/mobie/mobie-utils-python/blob/d9449ec268a60b2e9a78a1a7ca14b3fd649ad54b/mobie/metadata/view_metadata.py#L335

so I run into an error here. Is there a way to create such a view in mobie-python, or do I need to hack it into the JSON manually?

martinschorb commented 1 year ago

The code that I like to implement this into is here: https://github.com/mobie/mobie-utils-python/blob/a6f0db9807fb303deb2b025d61f80feeddb180a1/mobie/metadata/timepoint_view_metadata.py#L57

constantinpape commented 1 year ago

Can you write a simplified example for one of these views? (I.e. writing how it would look in json with just a few sources). That would help to understand what you want to do.

One comment regarding the check in https://github.com/mobie/mobie-utils-python/blob/d9449ec268a60b2e9a78a1a7ca14b3fd649ad54b/mobie/metadata/view_metadata.py#L335

This may indeed currently clash with the sourceNamesAfterTransform logic and it may be necessary to extend _sources for that case.

martinschorb commented 1 year ago

Hi, here's the data for two derived sources:

sourceDisplays

[
  {
    "imageDisplay": {
      "color": "255-255-255-255",
      "contrastLimits": [
        0.0,
        143.0
      ],
      "name": "C1-Live4_smallerView_tp_98-to-99",
      "opacity": "0.2000",
      "sources": [
        "C1-Live4_smallerView_tp_98-to-99"
      ],
      "showImagesIn3d": false,
      "visible": true
    }
  },
  {
    "imageDisplay": {
      "color": "255-255-255-255",
      "contrastLimits": [
        0.0,
        143.0
      ],
      "name": "C1-Live4_smallerView_tp_99-to-99",
      "opacity": "1.0000",
      "showImagesIn3d": false,
      "sources": [
        "C1-Live4_smallerView_tp_99-to-99"
      ],
      "visible": true
    }
  }
]

transformations

[
  {
    "timepoints": {
      "sources": [
        "C1-Live4_smallerView"
      ],
      "keep": false,
      "name": "C1-Live4_smallerView_timepoints",
      "parameters": [
        [
          99,
          98
        ]
      ]
    },
    "sourceNamesAfterTransform": "C1-Live4_smallerView_tp_98-to-99"
  },
  {
    "timepoints": {
      "sources": [
        "C1-Live4_smallerView"
      ],
      "keep": false,
      "name": "C1-Live4_smallerView_timepoints",
      "parameters": [
        [
          99,
          99
        ]
      ]
    },
    "sourceNamesAfterTransform": "C1-Live4_smallerView_tp_99-to-99"
  }
]

I tried running add_view with both the source names after transform as well as with the original source name and get:

AssertionError: The settings for C1-Live4_smallerView_tp_98-to-99 contain invalid sources: {'C1-Live4_smallerView_tp_98-to-99'} not in C1-Live4_smallerView

or

AssertionError: The settings for C1-Live4_smallerView_tp_98-to-99 contain invalid sources: {'C1-Live4_smallerView_tp_98-to-99'} not in C1-Live4_smallerView_tp_98-to-99

martinschorb commented 1 year ago

I tried again modifying one of the centrioles and its crop. Displayed both views (from same original source but different sourceDisplays) in the viewer and saved that combined view.

https://github.com/mobie/centriole-tomo-datasets/blob/6122a06134ee1b0a747c20dcbf48ca2de996f694/data/tomo/dataset.json#L147

This opens fine in MoBIE.

Again when trying to recreate that view in python, I get that strange error:

 line 336, in get_view
    assert len(invalid_sources) == 0,\
AssertionError: The settings for B-ALL_00_grid5_c0008 contain invalid sources: {'B-ALL_00_grid5_c0008'} not in B-ALL_00_grid5_c0008
constantinpape commented 1 year ago

Is your change in https://github.com/mobie/mobie-utils-python/commit/cd622e07dceaf68f9954746a4d03c69f9e29266b related to this @martinschorb? (And I don't have much time to look into any of this right now, I can take another look next week).

martinschorb commented 1 year ago

Is your change in cd622e0 related to this @martinschorb?

Yes, I stumbled across this little bug when investigating the get_view. It seems to work now. I will look into the parameter checks again and then create a PR from the timepoints branch that I am working on now for adding timepoint functionality.

(And I don't have much time to look into any of this right now, I can take another look next week).

Probably the timepoint stuff will be fully operational by then and you can check it out.

martinschorb commented 1 year ago

Ahhh.... same, same, over and over again...

Checked it again and of course, it is the list of sources going into get_view that has to be list of lists...