Closed VanessaBotha closed 4 days ago
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
Describe the bug
grid_order
changes fromC
toF
,grid_local_coordinates
do not change accordingly.grid_local_coordinates
do not match the order of the samplecoordinates
To Reproduce
TCGA/images/gdc_manifest.2021-11-01_diagnostic_breast.txt/fffb83a0-dab6-41be-9d8b-f4fb6c2584ab/TCGA-BH-A0HW-01Z-00-DX1.44DCCE00-133F-4469-A4DA-5057C011B4AC.svs
Expected behavior The
grid_local_coordinates
should always match the order of thecoordinates
, example: coordinates: (0, 0) grid_local_coordinates: (0, 0) coordinates: (224, 0) grid_local_coordinates: (1, 0) coordinates: (448, 0) grid_local_coordinates: (2, 0) etc.Environment dlup version: current main branch at commit c1f58b8, but also earlier versions like dlup==0.3.38 How installed: pip install -e ".[dev]" Python version: 3.10 Operating System: Ubuntu 22.04.4 LTS
Proposed solution
replace
grid_local_coordinates = np.unravel_index(grid_index, self.grids[starting_index][0].size)
by:grid_local_coordinates = np.unravel_index(grid_index, self.grids[starting_index][0].size[::-1], order=self.grids[starting_index][0].order)[::-1]
Explanation
Problem 1 is solved by passing the grid order to
np.unravel_index
(default of this function inorder="C"
) indef _process_tile_sample
: So:grid_local_coordinates = np.unravel_index(grid_index, self.grids[starting_index][0].size, order=self.grids[starting_index][0].order)
Now the order ofgrid_local_coordinates
changes, when thegrid_order
changesProblem 2: However,
grid_local_coordinates
is still not matching the order ofcoordinates
.numpy.unravel_index(indices, shape, order)
where shape is (h, w). In dlup Grid.size is (w, h). To verify: grid_size of this image is (9, 7) and the image looks like:so width should be 9 (longer) and height 7 (shorter)
So the Grid size needs to be reversed:
grid_local_coordinates = np.unravel_index(grid_index, self.grids[starting_index][0].size[::-1], order=self.grids[starting_index][0].order)
The output of
np.unravel_index
is also (h, w), so need to reverse these again to obtain the matchinggrid_local_coordinates
grid_local_coordinates = np.unravel_index(grid_index, self.grids[starting_index][0].size[::-1], order=self.grids[starting_index][0].order)[::-1]
`