worldarray 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
worldarray/__init__.py CHANGED
@@ -28,7 +28,7 @@ from .write import (
28
28
  parse_chunk_key,
29
29
  )
30
30
 
31
- __version__ = "0.3.0"
31
+ __version__ = "0.3.1"
32
32
 
33
33
  __all__ = [
34
34
  "ArrayMeta",
worldarray/array.py CHANGED
@@ -139,6 +139,8 @@ class WorldArray:
139
139
  self._meta = self._rescaled_to_base(base_voxel_size, base_units)
140
140
  space, time = _unit_targets(units)
141
141
  self._grid = self._meta.in_units(space=space, time=time, strict=strict_units)
142
+ # the stored level's spatial voxel size, before any relabel renames the grid
143
+ self._stored_voxel_size = tuple(self._grid.voxel_size[i] for i in self._grid.spatial)
142
144
 
143
145
  self._target: tuple[float, ...] | None = None
144
146
  if voxel_size is not None:
@@ -299,8 +301,9 @@ class WorldArray:
299
301
 
300
302
  @property
301
303
  def source_voxel_size(self) -> tuple[float, ...]:
302
- """The stored level's voxel size on the spatial axes, in ``units``."""
303
- return self._source_voxel_size()
304
+ """The stored level's voxel size on the spatial axes, in ``units``: what the level
305
+ is, whether reads resample it or ``on_mismatch="relabel"`` renames its grid."""
306
+ return self._stored_voxel_size
304
307
 
305
308
  @property
306
309
  def resampled(self) -> bool:
@@ -337,8 +340,22 @@ class WorldArray:
337
340
  def box(self) -> Box:
338
341
  """The array's extent on the spatial axes as a world box, ``[corner, corner + shape *
339
342
  voxel_size)``: what funlib calls the array's roi. ``Box.from_index`` gives the same
340
- over every axis."""
343
+ over every axis. With a resample target it is the extent of the target voxels that
344
+ ``shape`` counts, which may reach past the stored data by less than one target voxel,
345
+ so ``read(box)`` returns ``shape``."""
341
346
  sp = self._grid.spatial
347
+ if self._target is not None:
348
+ begin, end = [], []
349
+ for k, axis in enumerate(sp):
350
+ first, last = _resample.target_range(
351
+ self._grid.shape[axis],
352
+ self._grid.voxel_size[axis],
353
+ self._target[k],
354
+ self._origins()[k],
355
+ )
356
+ begin.append(self.anchor[k] + first * self._target[k])
357
+ end.append(self.anchor[k] + last * self._target[k])
358
+ return Box(tuple(begin), tuple(end))
342
359
  return Box.from_index(
343
360
  (0,) * len(sp),
344
361
  tuple(self._grid.shape[i] for i in sp),
worldarray/resample.py CHANGED
@@ -153,14 +153,22 @@ def apply_axis(block: np.ndarray, axis: int, plan: AxisPlan) -> np.ndarray:
153
153
  raise ValueError(plan.kind)
154
154
 
155
155
 
156
+ def target_range(n: int, s: float, t: float, origin: float = 0.0) -> tuple[int, int]:
157
+ """``[first, last)``: the target voxels of size ``t`` that overlap ``n`` source voxels of
158
+ size ``s``, indexed on a target grid whose voxel 0 corner sits ``origin`` source voxels
159
+ from the source corner."""
160
+ ratio = t / s
161
+ first = int(np.floor(snap_integral(-origin / ratio)))
162
+ last = int(np.ceil(snap_integral((n - origin) / ratio)))
163
+ return first, max(last, first)
164
+
165
+
156
166
  def target_shape(n: int, s: float, t: float, origin: float = 0.0) -> int:
157
167
  """How many target voxels of size ``t`` cover ``n`` source voxels of size ``s``, counting
158
168
  from a target grid whose voxel 0 corner sits ``origin`` source voxels from the source
159
169
  corner: the first and last target voxels that overlap the data, inclusive."""
160
- ratio = t / s
161
- first = np.floor(snap_integral(-origin / ratio))
162
- last = np.ceil(snap_integral((n - origin) / ratio))
163
- return int(max(last - first, 0))
170
+ first, last = target_range(n, s, t, origin)
171
+ return last - first
164
172
 
165
173
 
166
174
  def resample(
worldarray/units.py CHANGED
@@ -19,6 +19,7 @@ LENGTH_M = {
19
19
  "millimeter": 1e-3, "millimetre": 1e-3, "mm": 1e-3,
20
20
  "centimeter": 1e-2, "centimetre": 1e-2, "cm": 1e-2,
21
21
  "meter": 1.0, "metre": 1.0, "m": 1.0,
22
+ "kilometer": 1e3, "kilometre": 1e3, "km": 1e3,
22
23
  } # fmt: skip
23
24
  TIME_S = {
24
25
  "nanosecond": 1e-9, "ns": 1e-9,
@@ -81,7 +82,7 @@ def factor(
81
82
  # entry through the table above, so "nanometre", "nm" and "Nanometers" agree.
82
83
  _SHORT = {
83
84
  "picometer": "pm", "angstrom": "Å", "nanometer": "nm", "micrometer": "µm",
84
- "millimeter": "mm", "centimeter": "cm", "meter": "m",
85
+ "millimeter": "mm", "centimeter": "cm", "meter": "m", "kilometer": "km",
85
86
  "nanosecond": "ns", "microsecond": "µs", "millisecond": "ms", "second": "s",
86
87
  "minute": "min", "hour": "h", "day": "d",
87
88
  } # fmt: skip
@@ -103,6 +104,7 @@ def abbreviation(unit: str) -> str:
103
104
  # The American spelling is OME's.
104
105
  _OME_NAMES = (
105
106
  "picometer", "angstrom", "nanometer", "micrometer", "millimeter", "centimeter", "meter",
107
+ "kilometer",
106
108
  "nanosecond", "microsecond", "millisecond", "second", "minute", "hour", "day",
107
109
  ) # fmt: skip
108
110
  _OME_BY_SIZE = {_lookup(name): name for name in _OME_NAMES}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: worldarray
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Read zarr, N5 and Neuroglancer precomputed volumes in world coordinates through tensorstore: correct voxel placement, pyramid levels, padded region reads, resampling. numpy + tensorstore only.
5
5
  Project-URL: Homepage, https://janeliascicomp.github.io/worldarray/
6
6
  Project-URL: Documentation, https://janeliascicomp.github.io/worldarray/
@@ -165,9 +165,18 @@ s1 = wa.open_pyramid("out.zarr", mode="r+").add_level("s1", factors=2) # place
165
165
  ## The placement rule
166
166
 
167
167
  A translation is where the centre of voxel 0 is. Index `i` sits at
168
- `translation + i * voxel_size`; voxel `i` covers half a voxel either side. That is how
169
- OME-NGFF defines it and how Neuroglancer draws it. Dialects that store the corner are
170
- moved half a voxel on reading:
168
+ `translation + i * voxel_size` and covers half a voxel either side, so the array's corner
169
+ is `corner = translation - voxel_size / 2`. With 8 nm voxels and the corner at 0, the
170
+ translation is 4: voxel 0 covers 0 to 8 nm around its centre at 4, voxel 1 covers 8 to
171
+ 16 nm around 12. That is how OME-NGFF defines it and how Neuroglancer draws it.
172
+
173
+ The centre is the model because a voxel is a sample taken at a point. Everything that
174
+ compares or resamples grids (picking a level, reading one volume onto another's grid,
175
+ interpolating) works on those points, and the box a voxel covers follows from its point.
176
+ The read rule follows too: a voxel is read iff its centre lies in the box, so boxes that
177
+ adjoin never share a voxel or drop one.
178
+
179
+ Dialects that store the corner are moved half a voxel on reading:
171
180
 
172
181
  | Stored | Means | Read as `translation` |
173
182
  |---|---|---|
@@ -1,16 +1,16 @@
1
- worldarray/__init__.py,sha256=_g8gaopTTDUXz_vfEqaWzSEXSf3hflzNW6zjCLpiX-A,1828
2
- worldarray/array.py,sha256=1lmdq-Mi5Nu4wWJ3d6Ek5ZeA0-QmJJ6JgHdsQG7ud3k,56051
1
+ worldarray/__init__.py,sha256=BOPB6VfL8LEEEOFaoLKccTDHwOltJwodB3p6e5WGQaQ,1828
2
+ worldarray/array.py,sha256=vuqSl-y018R3czluw1DPQ14VmQf9kyUHJq_CBmu3vBM,57073
3
3
  worldarray/context.py,sha256=MZQoHLyir1xNYCHtQPGTIQXaFzFr3oAcyfddrE_UWIA,3284
4
4
  worldarray/geometry.py,sha256=ByQu8WrcUydKU2eDsugKwvx1LpQbETmhutfy5mv9inI,7449
5
5
  worldarray/grid.py,sha256=ATa6rcWygQ9Pigvqftz1tV_0U6enA6xF4WA_Y2ubD6Y,22313
6
6
  worldarray/levels.py,sha256=ICtax6A5Qi7DDlZI2S5UPg-S8Ze-AZoMxXyRykcs36A,6414
7
7
  worldarray/placement.py,sha256=l7kPkS6GatjoD_Eb7pJqkkxsHLKLUr5gA9JrxeMsnxo,34140
8
- worldarray/resample.py,sha256=nAls-m0vchrsua0q_1yx1K9-djlAnWtkgokCfXqbpIQ,10411
8
+ worldarray/resample.py,sha256=S6J6SSp6wK4KRzp7tSA94tFRDaPhee8GS-gPKEcOTRU,10796
9
9
  worldarray/retry.py,sha256=Uw4YP-tPwtg0tgpBzY0ux4F5vehdTZTp0385QH_vvrk,2766
10
10
  worldarray/store.py,sha256=432iIX35ak_cHhibHcZd80ehH0MgN35rtxOtYU35LYg,19154
11
- worldarray/units.py,sha256=02i7kpkPjB3HJ2-7ZAvEXLjv6j0mmfiYZjpUNwFDvz4,5238
11
+ worldarray/units.py,sha256=hng7Q8J71jsacPsnmtYyag8ufR0S6xhaL6R38wepvTA,5325
12
12
  worldarray/write.py,sha256=IjV2jtwSBBAcWKHfms9KPUALX5GDs7v-2FRpTMO2Gfo,33442
13
- worldarray-0.3.0.dist-info/METADATA,sha256=lhY78UeT83ZZLyshx6u-DwSWFo-1aWqhXmaXYaKARXk,15280
14
- worldarray-0.3.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
15
- worldarray-0.3.0.dist-info/licenses/LICENSE,sha256=NsviVkqc3M7YUSeSNmisDSg3e3L8S4ofeIjthWm8pvk,1518
16
- worldarray-0.3.0.dist-info/RECORD,,
13
+ worldarray-0.3.1.dist-info/METADATA,sha256=huGv6XXY72NQxhEpPrce1L3hihzBgJGMJySWp8BTcak,15877
14
+ worldarray-0.3.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
15
+ worldarray-0.3.1.dist-info/licenses/LICENSE,sha256=NsviVkqc3M7YUSeSNmisDSg3e3L8S4ofeIjthWm8pvk,1518
16
+ worldarray-0.3.1.dist-info/RECORD,,