Skip to content

Commit

Permalink
Multiscale: Support project files containing an integer working_scale
Browse files Browse the repository at this point in the history
All project files created with ilastik1.4.1b13 break otherwise
  • Loading branch information
btbest committed Feb 20, 2024
1 parent efaee7e commit 6f88900
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ilastik/applets/dataSelection/opDataSelection.py
Expand Up @@ -206,9 +206,20 @@ def from_h5_group(cls, data: h5py.Group, params: Dict = None):
if "display_mode" in data:
params["display_mode"] = data["display_mode"][()].decode("utf-8")
if "working_scale" in data:
# This raises if working_scale is an int,
# which would be the case if anyone actually created a Precomputed project with ilastik1.4.1b13
params["working_scale"] = data["working_scale"][()].decode("utf-8")
try:
params["working_scale"] = data["working_scale"][()].decode("utf-8")
except AttributeError:

Check warning on line 211 in ilastik/applets/dataSelection/opDataSelection.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/dataSelection/opDataSelection.py#L211

Added line #L211 was not covered by tests
# Support for projects created with ilastik 1.4.1b13
saved_scale = int(data["working_scale"][()])

Check warning on line 213 in ilastik/applets/dataSelection/opDataSelection.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/dataSelection/opDataSelection.py#L213

Added line #L213 was not covered by tests
if saved_scale == 0: # 0 by default (in all project files).
params["working_scale"] = DEFAULT_LOWEST_SCALE_KEY

Check warning on line 215 in ilastik/applets/dataSelection/opDataSelection.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/dataSelection/opDataSelection.py#L215

Added line #L215 was not covered by tests
elif saved_scale > 0: # Precomputed dataset with non-default scale selected
from lazyflow.utility.io_util.RESTfulPrecomputedChunkedVolume import RESTfulPrecomputedChunkedVolume

Check warning on line 217 in ilastik/applets/dataSelection/opDataSelection.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/dataSelection/opDataSelection.py#L217

Added line #L217 was not covered by tests

url = params["url"] # Should have url in this case
remote_source = RESTfulPrecomputedChunkedVolume(url.lstrip("precomputed://"))
scales = remote_source.get_scales_list_legacy()
params["working_scale"] = scales[saved_scale]["key"]

Check warning on line 222 in ilastik/applets/dataSelection/opDataSelection.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/dataSelection/opDataSelection.py#L219-L222

Added lines #L219 - L222 were not covered by tests
if "scale_locked" in data:
params["scale_locked"] = bool(data["scale_locked"][()])
return cls(**params)
Expand Down
4 changes: 4 additions & 0 deletions lazyflow/utility/io_util/RESTfulPrecomputedChunkedVolume.py
Expand Up @@ -227,6 +227,10 @@ def generate_url(self, block_coordinates, scale=DEFAULT_LOWEST_SCALE_KEY):
url = f"{base_url}/{scale}/{min_x}-{max_x}_{min_y}-{max_y}_{min_z}-{max_z}"
return url, downloaded_block_shape

def get_scales_list_legacy(self):
"""Returns the list of scales as they were used in ilastik 1.4.1b13."""
return list(reversed(self._json_info["scales"]))

Check warning on line 232 in lazyflow/utility/io_util/RESTfulPrecomputedChunkedVolume.py

View check run for this annotation

Codecov / codecov/patch

lazyflow/utility/io_util/RESTfulPrecomputedChunkedVolume.py#L232

Added line #L232 was not covered by tests


if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
Expand Down

0 comments on commit 6f88900

Please sign in to comment.