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

Not clear how to update a tile #300

Closed
surya-narayanan opened this issue Feb 10, 2022 · 3 comments
Closed

Not clear how to update a tile #300

surya-narayanan opened this issue Feb 10, 2022 · 3 comments
Labels
question Further information is requested

Comments

@surya-narayanan
Copy link
Contributor

Following instructions in #281, I want to update tiles with outputs of a new transform.

My code is as follows.

pipeline = Pipeline([
    CollapseRunsVectra(),    
    SegmentMIF(model='mesmer', nuclear_channel=0, cytoplasm_channel=2, image_resolution=0.5, 
              postprocess_kwargs_whole_cell=None, 
              postprocess_kwrags_nuclear=None),
    QuantifyMIF('nuclear_segmentation')   
    ])


for i, h5_path in enumerate(h5s):  
  #Create slide object
  h5 = SlideData(h5_path)
  tile_keys = list(h5["tiles"].keys())
  tiles = [h5["tiles"][str(k)]["array"][:] for k in tile_keys]

  for tile in tiles:
    pipeline.apply(tile)
    h5.update(tile) #not sure if this is the right way to do things here

I am not able to follow the documentation and the code

def update(self, tile):

I am looking for an update function that takes two arguments, a key and a value, and updates the h5's tiles at the key, with the value. Now, it seems to only take a key object. I am not sure what it updates the tile with.

This would require me to make a new Tile() object before updating the h5, is that right?

If I am wrong, please tell me how to update the h5 data with the new tile.

@surya-narayanan surya-narayanan added the bug Something isn't working label Feb 10, 2022
@ryanccarelli ryanccarelli added question Further information is requested and removed bug Something isn't working labels Feb 10, 2022
@ryanccarelli
Copy link
Contributor

ryanccarelli commented Feb 10, 2022

The update function takes a Tile object https://pathml.readthedocs.io/en/latest/api_core_reference.html?highlight=Tiles#pathml.core.Tile

Internally tile.coords is the key.

You can simplify by iterating over SlideData.tiles:

pipeline = Pipeline([
    CollapseRunsVectra(),    
    SegmentMIF(model='mesmer', nuclear_channel=0, cytoplasm_channel=2, image_resolution=0.5, 
              postprocess_kwargs_whole_cell=None, 
              postprocess_kwargs_nuclear=None),
    QuantifyMIF('nuclear_segmentation')   
    ])

for h5_path in h5s:  
  #Create slide object
  h5 = SlideData(h5_path)
  for tile in h5.tiles:
    pipeline.apply(tile)
    h5.tiles.update(tile)

I agree that documentation can be improved. We should say tile (pathml.core.tile.Tiles): Updated tile. The tile with matching tile.coords will be replaced

@jacob-rosenthal
Copy link
Collaborator

Thanks Surya!
Looking at the code you posted, I wonder if this line might be causing a problem:

tiles = [h5["tiles"][str(k)]["array"][:] for k in tile_keys]

It seems like this is trying to make a list holding all tiles - which could be a problem if the tiles don't all fit in memory. Perhaps you could try turning it into a generator expression (i.e. tiles = (h5["tiles"][str(k)]["array"][:] for k in tile_keys) ) or using the for loop like Ryan suggested, both of which should retrieve tiles lazily one at a time instead of all at once

@surya-narayanan
Copy link
Contributor Author

Yes. I used Ryan's suggestion to get it working. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants