annotate idr_download_by_ids.py @ 13:f92941d1a85e draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
author iuc
date Thu, 26 Sep 2024 12:32:17 +0000
parents cbd605a24336
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
1 import argparse
8
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
2 import json
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
3 import os
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
4 import sys
4
11036f6197d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents: 3
diff changeset
5 import tarfile
6
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
6 from contextlib import ExitStack
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
7 from itertools import product
6
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
8 from tempfile import TemporaryDirectory
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
9
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
10 import numpy
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
11 from omero.cli import cli_login
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
12 from omero.constants.namespaces import NSBULKANNOTATIONS
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
13 from omero.gateway import _ImageWrapper, BlitzGateway
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
14 from tifffile import imwrite
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
15
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
16
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
17 def warn(message: str, image_identifier: str, warn_skip: bool = False) -> None:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
18 """Print an error `message` to stderr and
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
19 - prefix with the `image_identifier`
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
20 - suffix with 'Skipping download!' if `warn_skip` is True
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
21
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
22 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
23 message (string): Message to print to stderr
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
24 image_identifier (string): Image identifier
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
25 warn_skip (bool, optional): Whether 'skipping download' should be suffix to the message. Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
26 """
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
27 message = message.rstrip()
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
28 if warn_skip:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
29 if message[-1] in [".", "!", "?"]:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
30 skip_msg = " Skipping download!"
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
31 else:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
32 skip_msg = ". Skipping download!"
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
33 else:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
34 skip_msg = ""
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
35 print(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
36 "ImageSpecWarning for {0}: {1}{2}".format(image_identifier, message, skip_msg),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
37 file=sys.stderr,
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
38 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
39
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
40
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
41 def find_channel_index(image: _ImageWrapper, channel_name: str) -> int:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
42 """Identify the channel index from the `image` and the `channel_name`
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
43
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
44 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
45 image (_ImageWrapper): image wrapper on which the channel should be identified
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
46 channel_name (string): name of the channel to look for
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
47
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
48 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
49 int: Index of the channel or -1 if was not found.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
50 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
51 channel_name = channel_name.lower()
2
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
52 for n, channel in enumerate(image.getChannelLabels()):
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
53 if channel_name == channel.lower():
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
54 return n
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
55 # Check map annotation for information (this is necessary for some images)
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
56 for ann in image.listAnnotations(NSBULKANNOTATIONS):
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
57 pairs = ann.getValue()
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
58 for p in pairs:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
59 if p[0] == "Channels":
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
60 channels = p[1].replace(" ", "").split(";")
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
61 for n, c in enumerate(channels):
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
62 for value in c.split(":"):
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
63 if channel_name == value.lower():
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
64 return n
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
65 return -1
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
66
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
67
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
68 def get_clipping_region(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
69 image: _ImageWrapper, x: int, y: int, w: int, h: int
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
70 ) -> list[int]:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
71 """Check `x`, `y` and adjust `w`, `h` to image size to be able to crop the `image` with these coordinates
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
72
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
73 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
74 image (_ImageWrapper): image wrapper on which region want to be cropped
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
75 x (int): left x coordinate
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
76 y (int): top y coordinate
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
77 w (int): width
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
78 h (int): height
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
79
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
80 Raises:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
81 ValueError: if the x or y coordinates are negative.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
82 ValueError: if the x or y coordinates are larger than the width or height of the image.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
83
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
84 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
85 list[int]: new [x, y, width, height] adjusted to the image
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
86 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
87 # If the (x, y) coordinate falls outside the image boundaries, we
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
88 # cannot just shift it because that would render the meaning of
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
89 # w and h undefined (should width and height be decreased or the whole
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
90 # region be shifted to keep them fixed?).
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
91 # It may be better to abort in this situation.
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
92 if x < 0 or y < 0:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
93 raise ValueError(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
94 "Too small upper left coordinate ({0}, {1}) for clipping region.".format(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
95 x, y
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
96 )
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
97 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
98 size_x = image.getSizeX()
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
99 size_y = image.getSizeY()
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
100 if x >= size_x or y >= size_y:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
101 raise ValueError(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
102 "Upper left coordinate ({0}, {1}) of clipping region lies "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
103 "outside of image.".format(x, y)
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
104 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
105 # adjust width and height to the image dimensions
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
106 if w <= 0 or x + w > size_x:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
107 w = size_x - x
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
108 if h <= 0 or y + h > size_y:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
109 h = size_y - y
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
110 return [x, y, w, h]
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
111
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
112
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
113 def confine_plane(image: _ImageWrapper, z: int) -> int:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
114 """Adjust/Confine `z` to be among the possible z for the `image`
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
115
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
116 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
117 image (_ImageWrapper): image wrapper for which the z is adjusted
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
118 z (int): plane index that need to be confined
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
119
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
120 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
121 int: confined z
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
122 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
123 if z < 0:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
124 z = 0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
125 else:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
126 max_z = image.getSizeZ() - 1
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
127 if z > max_z:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
128 z = max_z
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
129 return z
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
130
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
131
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
132 def confine_frame(image: _ImageWrapper, t: int) -> int:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
133 """Adjust/Confine `t` to be among the possible t for the `image`
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
134
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
135 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
136 image (_ImageWrapper): image wrapper for which the t is adjusted
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
137 t (int): frame index that need to be confined
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
138
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
139 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
140 int: confined t
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
141 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
142 if t < 0:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
143 t = 0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
144 else:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
145 max_t = image.getSizeT() - 1
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
146 if t > max_t:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
147 t = max_t
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
148 return t
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
149
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
150
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
151 def get_image_array(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
152 image: _ImageWrapper, tile: list[int], z: int, c: int, t: int
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
153 ) -> numpy.ndarray:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
154 """Get a 2D numpy array from an `image` wrapper for a given `tile`, `z`, `c`, `t`
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
155
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
156 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
157 image (_ImageWrapper): image wrapper from which values are taken
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
158 tile (list[int]): [x, y, width, height] where x,y is the top left coordinate of the region to crop
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
159 z (int): plane index
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
160 c (int): channel index
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
161 t (int): frame index
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
162
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
163 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
164 numpy.ndarray: image values of the selected area (2 dimensions)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
165 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
166 pixels = image.getPrimaryPixels()
2
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
167 try:
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
168 selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile)
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
169 except Exception:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
170 warning = "{0} (ID: {1})".format(image.getName(), image.getId())
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
171 warn("Could not download the requested region", warning)
2
17b1cd0f4812 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents: 1
diff changeset
172 return
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
173
4
11036f6197d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents: 3
diff changeset
174 return selection
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
175
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
176
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
177 def get_full_image_array(image: _ImageWrapper) -> numpy.ndarray:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
178 """Get a 5D numpy array with all values from an `image` wrapper
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
179
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
180 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
181 image (_ImageWrapper): image wrapper from which values are taken
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
182
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
183 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
184 numpy.ndarray: image values in the TZCYX order (5 dimensions)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
185 """
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
186 # The goal is to get the image in TZCYX order
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
187 pixels = image.getPrimaryPixels()
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
188 # Get the final tzclist in the order that will make the numpy reshape work
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
189 tzclist = list(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
190 product(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
191 range(image.getSizeT()), range(image.getSizeZ()), range(image.getSizeC())
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
192 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
193 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
194 # As getPlanes requires the indices in the zct order
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
195 # We keep the final order but switch indices
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
196 zctlist = [(z, c, t) for (t, z, c) in tzclist]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
197 try:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
198 all_planes = numpy.array(list(pixels.getPlanes(zctlist)))
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
199 all_planes_reshaped = all_planes.reshape(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
200 image.getSizeT(),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
201 image.getSizeZ(),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
202 image.getSizeC(),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
203 all_planes.shape[-2],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
204 all_planes.shape[-1],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
205 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
206 except Exception as e:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
207 warning = "{0} (ID: {1})".format(image.getName(), image.getId())
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
208 warn(f"Could not download the full image \n {e.msg}", warning)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
209 return
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
210
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
211 return all_planes_reshaped
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
212
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
213
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
214 def download_image_data(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
215 image_ids_or_dataset_id: str,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
216 dataset: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
217 download_original: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
218 download_full: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
219 channel: str = None,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
220 z_stack: int = 0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
221 frame: int = 0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
222 coord: tuple[int, int] = (0, 0),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
223 width: int = 0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
224 height: int = 0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
225 region_spec: str = "rectangle",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
226 skip_failed: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
227 download_tar: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
228 omero_host: str = "idr.openmicroscopy.org",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
229 omero_secured: bool = False,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
230 config_file: str = None,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
231 ) -> None:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
232 """Download the image data of
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
233 either a list of image ids or all images from a dataset.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
234 The image data can be:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
235 - a 2D cropped region or
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
236 - a hyperstack written in a tiff file
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
237 - the original image uploaded in omero
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
238 Optionally, the final file can be in a tar
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
239
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
240 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
241 image_ids_or_dataset_id (list[str]): Can be either a list with a single id (int) of a dataset or a list with images ids (int) or images ids prefixed by 'image-'
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
242 dataset (bool, optional): Whether the image_ids_or_dataset_id is a dataset id and all images from this dataset should be retrieved (true) or image_ids_or_dataset_id are individual image ids (false). Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
243 download_original (bool, optional): Whether the original file uploded to omero should be downloaded (ignored if `download_full` is set to True). Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
244 download_full (bool, optional): Whether the full image (hyperstack) on omero should be written to TIFF. Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
245 channel (string, optional): Channel name (ignored if `download_full` or `download_original` is set to True). Defaults to None.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
246 z_stack (int, optional): Z stack (plane) index (ignored if `download_full` or `download_original` is set to True). Defaults to 0.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
247 frame (int, optional): T frame index (ignored if `download_full` or `download_original` is set to True). Defaults to 0.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
248 coord (tuple[int, int], optional): Coordinates of the top left or center of the region to crop (ignored if `download_full` or `download_original` is set to True). Defaults to (0, 0).
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
249 width (int, optional): Width of the region to crop (ignored if `download_full` or `download_original` is set to True). Defaults to 0.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
250 height (int, optional): Height of the region to crop (ignored if `download_full` or `download_original` is set to True). Defaults to 0.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
251 region_spec (str, optional): How the region is specified ('rectangle' = coord is top left or 'center' = the region is center, ignored if `download_full` or `download_original` is set to True). Defaults to "rectangle".
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
252 skip_failed (bool, optional): Do not stop the downloads if one fails. Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
253 download_tar (bool, optional): Put all downloaded images into a tar file. Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
254 omero_host (str, optional): omero host url. Defaults to "idr.openmicroscopy.org".
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
255 omero_secured (bool, optional): Whether the omero connects with secure connection. Defaults to False.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
256 config_file (string, optional): File path with config file with credentials to connect to OMERO. Defaults to None.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
257
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
258 Raises:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
259 ValueError: If the region_spec is not 'rectangle' nor 'center' and a cropped region is wanted.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
260 ValueError: If there is no dataset with this number in OMERO
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
261 ValueError: If there is no image with this number in OMERO
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
262 Exception: If the command to download the original image fails
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
263 ValueError: If the channel name could not be identified
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
264 """
8
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
265
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
266 if config_file is None: # IDR connection
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
267 omero_username = "public"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
268 omero_password = "public"
8
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
269 else: # other omero instance
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
270 with open(config_file) as f:
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
271 cfg = json.load(f)
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
272 omero_username = cfg["username"]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
273 omero_password = cfg["password"]
8
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
274
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
275 if omero_username == "" or omero_password == "":
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
276 omero_username = "public"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
277 omero_password = "public"
8
97f70f7ed077 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents: 7
diff changeset
278
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
279 if (
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
280 not download_original
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
281 and not download_full
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
282 and region_spec not in ["rectangle", "center"]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
283 ):
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
284 raise ValueError(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
285 'Got unknown value "{0}" as region_spec argument'.format(region_spec)
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
286 )
6
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
287 with ExitStack() as exit_stack:
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
288 conn = exit_stack.enter_context(
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
289 BlitzGateway(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
290 omero_username, omero_password, host=omero_host, secure=omero_secured
6
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
291 )
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
292 )
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
293 if download_tar:
5c743356df83 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents: 5
diff changeset
294 # create an archive file to write images to
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
295 archive = exit_stack.enter_context(tarfile.open("images.tar", mode="w"))
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
296 tempdir = exit_stack.enter_context(TemporaryDirectory())
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
297
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
298 if dataset:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
299 dataset_warning_id = "Dataset-ID: {0}".format(image_ids_or_dataset_id[0])
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
300 try:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
301 dataset_id = int(image_ids_or_dataset_id[0])
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
302 except ValueError:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
303 image_ids = None
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
304 else:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
305 try:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
306 dataset = conn.getObject("Dataset", dataset_id)
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
307 except Exception as e:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
308 # respect skip_failed on unexpected errors
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
309 if skip_failed:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
310 warn(str(e), dataset_warning_id, warn_skip=True)
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
311 else:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
312 raise
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
313 else:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
314 image_ids = [image.id for image in dataset.listChildren()]
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
315
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
316 if image_ids is None:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
317 if skip_failed:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
318 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
319 "Unable to find a dataset with this ID in the " "database.",
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
320 dataset_warning_id,
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
321 warn_skip=True,
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
322 )
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
323 else:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
324 raise ValueError(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
325 "{0}: Unable to find a dataset with this ID in the "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
326 "database. Aborting!".format(dataset_warning_id)
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
327 )
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
328
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
329 else:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
330 # basic argument sanity checks and adjustments
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
331 prefix = "image-"
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
332 # normalize image ids by stripping off prefix if it exists
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
333 image_ids = [
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
334 iid[len(prefix):] if iid[:len(prefix)] == prefix else iid
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
335 for iid in image_ids_or_dataset_id
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
336 ]
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
337 for image_id in image_ids:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
338 image_warning_id = "Image-ID: {0}".format(image_id)
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
339 try:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
340 image_id = int(image_id)
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
341 except ValueError:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
342 image = None
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
343 else:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
344 try:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
345 image = conn.getObject("Image", image_id)
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
346 except Exception as e:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
347 # respect skip_failed on unexpected errors
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
348 if skip_failed:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
349 warn(str(e), image_warning_id, warn_skip=True)
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
350 continue
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
351 else:
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
352 raise
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
353
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
354 if image is None:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
355 if skip_failed:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
356 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
357 "Unable to find an image with this ID in the database.",
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
358 image_warning_id,
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
359 warn_skip=True,
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
360 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
361 continue
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
362 raise ValueError(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
363 "{0}: Unable to find an image with this ID in the "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
364 "database. Aborting!".format(image_warning_id)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
365 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
366 try:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
367 # try to extract image name
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
368 # if anything goes wrong here skip the image
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
369 # or abort.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
370 image_name = os.path.splitext(image.getName())[0]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
371 image_warning_id = "{0} (ID: {1})".format(image_name, image_id)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
372 except Exception as e:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
373 # respect skip_failed on unexpected errors
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
374 if skip_failed:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
375 warn(str(e), image_warning_id, warn_skip=True)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
376 continue
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
377 else:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
378 raise
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
379 if download_full:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
380 fname = (
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
381 "__".join([image_name.replace(" ", "_"), str(image_id), "full"])
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
382 + ".tiff"
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
383 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
384 # download and save the region as TIFF
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
385 try:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
386 im_array = get_full_image_array(image)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
387
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
388 if download_tar:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
389 fname = os.path.join(tempdir, fname)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
390
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
391 imwrite(fname, im_array, imagej=True)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
392 # move image into tarball
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
393 if download_tar:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
394 archive.add(fname, os.path.basename(fname))
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
395 os.remove(fname)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
396 except Exception as e:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
397 if skip_failed:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
398 # respect skip_failed on unexpected errors
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
399 warn(str(e), image_warning_id, warn_skip=True)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
400 continue
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
401 else:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
402 raise
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
403 elif download_original:
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
404 try:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
405 # try to extract image properties
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
406 # if anything goes wrong here skip the image
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
407 # or abort.
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
408 original_image_name = image.getFileset().listFiles()[0].getName()
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
409 fname = (
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
410 image_name
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
411 + "__"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
412 + str(image_id)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
413 + os.path.splitext(original_image_name)[1]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
414 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
415 fname = fname.replace(" ", "_")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
416 fname = fname.replace("/", "_")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
417 download_directory = "./"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
418 if download_tar:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
419 download_directory = tempdir
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
420 with cli_login(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
421 "-u", omero_username, "-s", omero_host, "-w", omero_password
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
422 ) as cli:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
423 cli.invoke(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
424 ["download", f"Image:{image_id}", download_directory]
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
425 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
426 if cli.rv != 0:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
427 raise Exception("Download failed.")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
428 # This will download to download_directory/original_image_name
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
429 os.rename(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
430 os.path.join(download_directory, original_image_name),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
431 os.path.join(download_directory, fname),
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
432 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
433 # move image into tarball
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
434 if download_tar:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
435 archive.add(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
436 os.path.join(download_directory, fname),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
437 os.path.basename(fname),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
438 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
439 os.remove(os.path.join(download_directory, fname))
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
440 except Exception as e:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
441 # respect skip_failed on unexpected errors
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
442 if skip_failed:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
443 warn(str(e), image_warning_id, warn_skip=True)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
444 continue
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
445 else:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
446 raise
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
447 else:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
448 try:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
449 # try to extract image properties
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
450 # if anything goes wrong here skip the image
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
451 # or abort.
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
452 if region_spec == "rectangle":
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
453 tile = get_clipping_region(image, *coord, width, height)
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
454 elif region_spec == "center":
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
455 tile = get_clipping_region(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
456 image, *_center_to_ul(*coord, width, height)
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
457 )
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
458
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
459 ori_z, z_stack = z_stack, confine_plane(image, z_stack)
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
460 ori_frame, frame = frame, confine_frame(image, frame)
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
461 num_channels = image.getSizeC()
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
462 if channel is None:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
463 channel_index = 0
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
464 else:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
465 channel_index = find_channel_index(image, channel)
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
466 except Exception as e:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
467 # respect skip_failed on unexpected errors
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
468 if skip_failed:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
469 warn(str(e), image_warning_id, warn_skip=True)
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
470 continue
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
471 else:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
472 raise
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
473
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
474 # region sanity checks and warnings
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
475 if tile[2] < width or tile[3] < height:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
476 # The downloaded image region will have smaller dimensions
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
477 # than the specified width x height.
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
478 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
479 "Downloaded image dimensions ({0} x {1}) will be smaller "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
480 "than the specified width and height ({2} x {3}).".format(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
481 tile[2], tile[3], width, height
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
482 ),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
483 image_warning_id,
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
484 )
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
485
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
486 # z-stack sanity checks and warnings
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
487 if z_stack != ori_z:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
488 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
489 "Specified image plane ({0}) is out of bounds. Using {1} "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
490 "instead.".format(ori_z, z_stack),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
491 image_warning_id,
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
492 )
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
493
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
494 # frame sanity checks and warnings
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
495 if frame != ori_frame:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
496 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
497 "Specified image frame ({0}) is out of bounds. Using "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
498 "frame {1} instead.".format(ori_frame, frame),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
499 image_warning_id,
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
500 )
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
501
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
502 # channel index sanity checks and warnings
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
503 if channel is None:
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
504 if num_channels > 1:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
505 warn(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
506 "No specific channel selected for multi-channel "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
507 "image. Using first of {0} channels.".format(num_channels),
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
508 image_warning_id,
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
509 )
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
510 else:
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
511 if channel_index == -1 or channel_index >= num_channels:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
512 if skip_failed:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
513 warn(
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
514 str(channel)
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
515 + " is not a known channel name for this image.",
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
516 image_warning_id,
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
517 warn_skip=True,
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
518 )
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
519 continue
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
520 else:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
521 raise ValueError(
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
522 '"{0}" is not a known channel name for image {1}. '
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
523 "Aborting!".format(channel, image_warning_id)
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
524 )
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
525
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
526 fname = "__".join([image_name, str(image_id)] + [str(x) for x in tile])
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
527 fname += ".tiff"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
528 fname = fname.replace(" ", "_")
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
529 # download and save the region as TIFF
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
530 try:
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
531 im_array = get_image_array(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
532 image, tile, z_stack, channel_index, frame
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
533 )
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
534
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
535 if download_tar:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
536 fname = os.path.join(tempdir, fname)
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
537 imwrite(fname, im_array)
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
538 # move image into tarball
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
539 if download_tar:
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
540 archive.add(fname, os.path.basename(fname))
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
541 os.remove(fname)
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
542 except Exception as e:
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
543 if skip_failed:
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
544 # respect skip_failed on unexpected errors
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
545 warn(str(e), image_warning_id, warn_skip=True)
3
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
546 continue
381f248febba "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents: 2
diff changeset
547 else:
11
cbd605a24336 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
iuc
parents: 10
diff changeset
548 raise
4
11036f6197d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents: 3
diff changeset
549
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
550
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
551 def _center_to_ul(center_x: int, center_y: int, width: int, height: int) -> list[int]:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
552 """Convert the center coordinates (`center_x`, `center_y`), `width`, `height` to upper left coordinates, width, height
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
553
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
554 Args:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
555 center_x (int): x coordinate of center
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
556 center_y (int): y coordinate of center
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
557 width (int): width
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
558 height (int): height
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
559
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
560 Returns:
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
561 list[int]: [x, y, width, height] where x,y are the upper left coordinates
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
562 """
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
563 if width > 0:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
564 ext_x = (width - 1) // 2
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
565 ul_x = max([center_x - ext_x, 0])
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
566 width = center_x + ext_x + 1 - ul_x
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
567 else:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
568 ul_x = 0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
569 if height > 0:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
570 ext_y = (height - 1) // 2
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
571 ul_y = max([center_y - ext_y, 0])
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
572 height = center_y + ext_y + 1 - ul_y
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
573 else:
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
574 ul_y = 0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
575 return ul_x, ul_y, width, height
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
576
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
577
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
578 if __name__ == "__main__":
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
579 p = argparse.ArgumentParser()
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
580 p.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
581 "image_ids_or_dataset_id",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
582 nargs="*",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
583 default=[],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
584 help="one or more IDR image ids or a single dataset id"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
585 "for which to retrieve data (default: "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
586 "read ids from stdin).",
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
587 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
588 region = p.add_mutually_exclusive_group()
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
589 region.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
590 "--rectangle",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
591 nargs=4,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
592 type=int,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
593 default=argparse.SUPPRESS,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
594 help="specify a clipping region for the image as x y width height, "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
595 "where x and y give the upper left coordinate of the rectangle "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
596 "to clip to. Set width and height to 0 to extend the rectangle "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
597 "to the actual size of the image.",
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
598 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
599 region.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
600 "--center",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
601 nargs=4,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
602 type=int,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
603 default=argparse.SUPPRESS,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
604 help="specify a clipping region for the image as x y width height, "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
605 "where x and y define the center of a width x height rectangle. "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
606 "Set either width or height to 0 to extend the region to the "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
607 "actual size of the image along the x- or y-axis.\n"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
608 "Note: Even values for width and height will be rounded down to "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
609 "the nearest odd number.",
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
610 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
611 region.add_argument(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
612 "--download-original",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
613 dest="download_original",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
614 action="store_true",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
615 help="download the original file uploaded to omero",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
616 )
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
617 region.add_argument(
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
618 "--download-full",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
619 dest="download_full",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
620 action="store_true",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
621 help="download the full image on omero",
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
622 )
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
623 p.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
624 "-c",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
625 "--channel",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
626 help="name of the channel to retrieve data for "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
627 "(note: the first channel of each image will be downloaded if "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
628 "left unspecified), ignored with `--download-original` and "
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
629 "`--download-full`",
4
11036f6197d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents: 3
diff changeset
630 )
7
f067504aa92a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents: 6
diff changeset
631 p.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
632 "-f",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
633 "--frame",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
634 type=int,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
635 default=0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
636 help="index of the frame to retrive data for (first frame is 0),"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
637 " ignored with `--download-original` and `--download-full`",
7
f067504aa92a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents: 6
diff changeset
638 )
f067504aa92a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents: 6
diff changeset
639 p.add_argument(
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
640 "-z",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
641 "--z-stack",
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
642 type=int,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
643 default=0,
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
644 help="index of the slice to retrive data for (first slice is 0),"
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
645 " ignored with `--download-original` and `--download-full`",
7
f067504aa92a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents: 6
diff changeset
646 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
647 p.add_argument("--skip-failed", action="store_true")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
648 p.add_argument("--download-tar", action="store_true")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
649 p.add_argument("-oh", "--omero-host", type=str, default="idr.openmicroscopy.org")
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
650 p.add_argument("--omero-secured", action="store_true", default=True)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
651 p.add_argument("-cf", "--config-file", dest="config_file", default=None)
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
652 p.add_argument("--dataset", action="store_true")
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
653 args = p.parse_args()
10
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
654 if not args.image_ids_or_dataset_id:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
655 args.image_ids_or_dataset_id = sys.stdin.read().split()
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
656 if args.dataset and len(args.image_ids_or_dataset_id) > 1:
4aed70472589 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents: 8
diff changeset
657 warn("Multiple dataset ids provided. Only the first one will be used.")
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
658 if "center" in args:
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
659 args.coord, args.width, args.height = (
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
660 args.center[:2],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
661 args.center[2],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
662 args.center[3],
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
663 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
664 args.region_spec = "center"
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
665 del args.center
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
666 elif "rectangle" in args:
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
667 args.coord, args.width, args.height = (
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
668 args.rectangle[:2],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
669 args.rectangle[2],
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
670 args.rectangle[3],
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
671 )
13
f92941d1a85e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
iuc
parents: 11
diff changeset
672 args.region_spec = "rectangle"
0
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
673 del args.rectangle
57aa9597cd31 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff changeset
674 download_image_data(**vars(args))