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