large-image-source-rasterio 1.29.2.dev23__tar.gz → 1.29.3__tar.gz

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.
Files changed (15) hide show
  1. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/PKG-INFO +3 -3
  2. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio/__init__.py +51 -26
  3. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio.egg-info/PKG-INFO +3 -3
  4. large-image-source-rasterio-1.29.3/large_image_source_rasterio.egg-info/requires.txt +9 -0
  5. large-image-source-rasterio-1.29.2.dev23/large_image_source_rasterio.egg-info/requires.txt +0 -9
  6. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/LICENSE +0 -0
  7. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/README.rst +0 -0
  8. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio/girder_source.py +0 -0
  9. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio.egg-info/SOURCES.txt +0 -0
  10. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio.egg-info/dependency_links.txt +0 -0
  11. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio.egg-info/entry_points.txt +0 -0
  12. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/large_image_source_rasterio.egg-info/top_level.txt +0 -0
  13. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/pyproject.toml +0 -0
  14. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/setup.cfg +0 -0
  15. {large-image-source-rasterio-1.29.2.dev23 → large-image-source-rasterio-1.29.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-rasterio
3
- Version: 1.29.2.dev23
3
+ Version: 1.29.3
4
4
  Summary: A rasterio tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -17,11 +17,11 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.8
19
19
  License-File: LICENSE
20
- Requires-Dist: large-image>=1.29.2.dev23
20
+ Requires-Dist: large-image>=1.29.3
21
21
  Requires-Dist: rasterio>=1.3
22
22
  Requires-Dist: packaging
23
23
  Provides-Extra: girder
24
- Requires-Dist: girder-large-image>=1.29.2.dev23; extra == "girder"
24
+ Requires-Dist: girder-large-image>=1.29.3; extra == "girder"
25
25
  Provides-Extra: all
26
26
  Requires-Dist: rio-cogeo; extra == "all"
27
27
 
@@ -26,11 +26,6 @@ from importlib.metadata import version as _importlib_version
26
26
 
27
27
  import numpy as np
28
28
  import PIL.Image
29
- import rasterio as rio
30
- from affine import Affine
31
- from rasterio import warp
32
- from rasterio.enums import ColorInterp, Resampling
33
- from rasterio.errors import RasterioIOError
34
29
 
35
30
  import large_image
36
31
  from large_image.cache_util import LruCacheMetaclass, methodcache
@@ -51,11 +46,36 @@ except PackageNotFoundError:
51
46
  # package is not installed
52
47
  pass
53
48
 
54
- warnings.filterwarnings('ignore', category=rio.errors.NotGeoreferencedWarning, module='rasterio')
55
- rio._env.code_map.pop(1, None)
49
+ rio = None
50
+ Affine = None
51
+
52
+
53
+ def _lazyImport():
54
+ """
55
+ Import the rasterio module. This is done when needed rather than in the
56
+ module initialization because it is slow.
57
+ """
58
+ global Affine, rio
59
+
60
+ if rio is None:
61
+ try:
62
+ import affine
63
+ import rasterio as rio
64
+ import rasterio.warp
65
+
66
+ Affine = affine.Affine
67
+
68
+ warnings.filterwarnings(
69
+ 'ignore', category=rio.errors.NotGeoreferencedWarning, module='rasterio')
70
+ rio._env.code_map.pop(1, None)
71
+ except ImportError:
72
+ msg = 'rasterio module not found.'
73
+ raise TileSourceError(msg)
56
74
 
57
75
 
58
76
  def make_crs(projection):
77
+ _lazyImport()
78
+
59
79
  if isinstance(projection, str):
60
80
  return rio.CRS.from_string(projection)
61
81
  if isinstance(projection, dict):
@@ -87,6 +107,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
87
107
  """
88
108
  # init the object
89
109
  super().__init__(path, **kwargs)
110
+ _lazyImport()
90
111
  self.addKnownExtensions()
91
112
 
92
113
  # create a thread lock
@@ -109,7 +130,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
109
130
  raise TileSourceFileNotFoundError(self._largeImagePath) from None
110
131
  try:
111
132
  self.dataset = rio.open(self._largeImagePath)
112
- except RasterioIOError:
133
+ except rio.errors.RasterioIOError:
113
134
  msg = 'File cannot be opened via rasterio.'
114
135
  raise TileSourceError(msg)
115
136
  if self.dataset.driver == 'netCDF':
@@ -246,8 +267,8 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
246
267
  # If unitsPerPixel is not specified, the horizontal distance
247
268
  # between -180,0 and +180,0 is used. Some projections (such as
248
269
  # stereographic) will fail in this case; they must have a unitsPerPixel specified.
249
- east, _ = warp.transform(srcCrs, dstCrs, [-180], [0])
250
- west, _ = warp.transform(srcCrs, dstCrs, [180], [0])
270
+ east, _ = rio.warp.transform(srcCrs, dstCrs, [-180], [0])
271
+ west, _ = rio.warp.transform(srcCrs, dstCrs, [180], [0])
251
272
  self.unitsAcrossLevel0 = abs(east[0] - west[0])
252
273
  if not self.unitsAcrossLevel0:
253
274
  msg = 'unitsPerPixel must be specified for this projection'
@@ -385,7 +406,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
385
406
  # set the vertical bounds
386
407
  # some projection system don't cover the poles so we need to adapt
387
408
  # the values of ybounds accordingly
388
- has_poles = warp.transform(4326, dstCrs, [0], [90])[1][0] != float('inf')
409
+ has_poles = rio.warp.transform(4326, dstCrs, [0], [90])[1][0] != float('inf')
389
410
  yBounds = 90 if has_poles else 89.999999
390
411
 
391
412
  # for each corner fix the latitude within -yBounds yBounds
@@ -409,7 +430,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
409
430
  needProjection = dstCrs and dstCrs != srcCrs
410
431
  if needProjection:
411
432
  for pt in bounds.values():
412
- [pt['x']], [pt['y']] = warp.transform(srcCrs, dstCrs, [pt['x']], [pt['y']])
433
+ [pt['x']], [pt['y']] = rio.warp.transform(srcCrs, dstCrs, [pt['x']], [pt['y']])
413
434
 
414
435
  # extract min max coordinates from the corners
415
436
  ll = bounds['ll']['x'], bounds['ll']['y']
@@ -573,7 +594,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
573
594
  tile = self.dataset.read(
574
595
  window=window,
575
596
  out_shape=(count, h, w),
576
- resampling=Resampling.nearest,
597
+ resampling=rio.enums.Resampling.nearest,
577
598
  )
578
599
 
579
600
  else:
@@ -600,7 +621,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
600
621
  # It will result in surprisingly unmasked data.
601
622
  src_alpha_band = 0
602
623
  for i, interp in enumerate(self.dataset.colorinterp):
603
- if interp == ColorInterp.alpha:
624
+ if interp == rio.enums.ColorInterp.alpha:
604
625
  src_alpha_band = i
605
626
  add_alpha = not src_alpha_band
606
627
 
@@ -608,14 +629,14 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
608
629
  with self._getDatasetLock:
609
630
  with rio.vrt.WarpedVRT(
610
631
  self.dataset,
611
- resampling=Resampling.nearest,
632
+ resampling=rio.enums.Resampling.nearest,
612
633
  crs=self.projection,
613
634
  transform=dst_transform,
614
635
  height=self.tileHeight,
615
636
  width=self.tileWidth,
616
637
  add_alpha=add_alpha,
617
638
  ) as vrt:
618
- tile = vrt.read(resampling=Resampling.nearest)
639
+ tile = vrt.read(resampling=rio.enums.Resampling.nearest)
619
640
 
620
641
  # necessary for multispectral images:
621
642
  # set the coordinates first and the bands at the end
@@ -686,12 +707,14 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
686
707
  units = units.split(':', 1)[1]
687
708
  srcCrs = make_crs(units)
688
709
  dstCrs = self.projection # instance projection -- do not use the CRS native to the file
689
- [pleft], [ptop] = warp.transform(srcCrs, dstCrs,
690
- [right if left is None else left],
691
- [bottom if top is None else top])
692
- [pright], [pbottom] = warp.transform(srcCrs, dstCrs,
693
- [left if right is None else right],
694
- [top if bottom is None else bottom])
710
+ [pleft], [ptop] = rio.warp.transform(
711
+ srcCrs, dstCrs,
712
+ [right if left is None else left],
713
+ [bottom if top is None else top])
714
+ [pright], [pbottom] = rio.warp.transform(
715
+ srcCrs, dstCrs,
716
+ [left if right is None else right],
717
+ [top if bottom is None else bottom])
695
718
  units = 'projection'
696
719
 
697
720
  # set the corner value in pixel coordinates if the coordinate was initially
@@ -837,7 +860,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
837
860
 
838
861
  # convert to the native projection
839
862
  dstCrs = make_crs(self.getCrs())
840
- [px], [py] = warp.transform(srcCrs, dstCrs, [x], [y])
863
+ [px], [py] = rio.warp.transform(srcCrs, dstCrs, [x], [y])
841
864
 
842
865
  # convert to native pixel coordinates
843
866
  af = self._getAffine()
@@ -884,7 +907,7 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
884
907
  window = rio.windows.Window(int(x), int(y), 1, 1)
885
908
  try:
886
909
  value = self.dataset.read(
887
- i, window=window, resampling=Resampling.nearest,
910
+ i, window=window, resampling=rio.enums.Resampling.nearest,
888
911
  )
889
912
  value = value[0][0] # there should be 1 single pixel
890
913
  pixel.setdefault('bands', {})[i] = value.item()
@@ -950,13 +973,13 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
950
973
 
951
974
  with rio.vrt.WarpedVRT(
952
975
  self.dataset,
953
- resampling=Resampling.nearest,
976
+ resampling=rio.enums.Resampling.nearest,
954
977
  crs=self.projection,
955
978
  transform=dst_transform,
956
979
  height=height,
957
980
  width=width,
958
981
  ) as vrt:
959
- data = vrt.read(resampling=Resampling.nearest)
982
+ data = vrt.read(resampling=rio.enums.Resampling.nearest)
960
983
 
961
984
  profile = self.dataset.meta.copy()
962
985
  profile.update(
@@ -1019,6 +1042,8 @@ class RasterioFileTileSource(GDALBaseFileTileSource, metaclass=LruCacheMetaclass
1019
1042
  :param path: The path to the file
1020
1043
  :returns: True if geospatial.
1021
1044
  """
1045
+ _lazyImport()
1046
+
1022
1047
  if isinstance(path, rio.io.DatasetReaderBase):
1023
1048
  ds = path
1024
1049
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-rasterio
3
- Version: 1.29.2.dev23
3
+ Version: 1.29.3
4
4
  Summary: A rasterio tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -17,11 +17,11 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.8
19
19
  License-File: LICENSE
20
- Requires-Dist: large-image>=1.29.2.dev23
20
+ Requires-Dist: large-image>=1.29.3
21
21
  Requires-Dist: rasterio>=1.3
22
22
  Requires-Dist: packaging
23
23
  Provides-Extra: girder
24
- Requires-Dist: girder-large-image>=1.29.2.dev23; extra == "girder"
24
+ Requires-Dist: girder-large-image>=1.29.3; extra == "girder"
25
25
  Provides-Extra: all
26
26
  Requires-Dist: rio-cogeo; extra == "all"
27
27
 
@@ -0,0 +1,9 @@
1
+ large-image>=1.29.3
2
+ rasterio>=1.3
3
+ packaging
4
+
5
+ [all]
6
+ rio-cogeo
7
+
8
+ [girder]
9
+ girder-large-image>=1.29.3
@@ -1,9 +0,0 @@
1
- large-image>=1.29.2.dev23
2
- rasterio>=1.3
3
- packaging
4
-
5
- [all]
6
- rio-cogeo
7
-
8
- [girder]
9
- girder-large-image>=1.29.2.dev23