Skip to content

Commit

Permalink
Merge pull request #2816 from btbest/support-projects-with-int-scale
Browse files Browse the repository at this point in the history
Multiscale: Support project files containing an integer working_scale
  • Loading branch information
btbest committed Feb 20, 2024
2 parents acb6e14 + 6f88900 commit 14e6469
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:
# Support for projects created with ilastik 1.4.1b13
saved_scale = int(data["working_scale"][()])
if saved_scale == 0: # 0 by default (in all project files).
params["working_scale"] = DEFAULT_LOWEST_SCALE_KEY
elif saved_scale > 0: # Precomputed dataset with non-default scale selected
from lazyflow.utility.io_util.RESTfulPrecomputedChunkedVolume import RESTfulPrecomputedChunkedVolume

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"]
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"]))


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

0 comments on commit 14e6469

Please sign in to comment.