yirgacheffe 1.7.9__py3-none-any.whl → 1.8.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.

Potentially problematic release.


This version of yirgacheffe might be problematic. Click here for more details.

yirgacheffe/__init__.py CHANGED
@@ -14,5 +14,7 @@ except ModuleNotFoundError:
14
14
 
15
15
  from ._core import read_raster, read_rasters, read_shape, read_shape_like, constant, read_narrow_raster
16
16
  from .constants import WGS_84_PROJECTION
17
+ from .window import Area, MapProjection, Window
18
+ from ._backends.enumeration import dtype as DataType
17
19
 
18
20
  gdal.UseExceptions()
@@ -41,6 +41,26 @@ class operators(Enum):
41
41
  ISNAN = 36
42
42
 
43
43
  class dtype(Enum):
44
+ """Represents the type of data returned by a layer.
45
+
46
+ This enumeration defines the valid data types supported by Yirgacheffe, and is
47
+ what is returned by calling `datatype` on a layer or expression, and can be
48
+ passed to `astype` to convert values between types.
49
+
50
+ Attributes:
51
+ Float32: 32 bit floating point value
52
+ Float64: 64 bit floating point value
53
+ Byte: Unsigned 8 bit integer value
54
+ Int8: Signed 8 bit integer value
55
+ Int16: Signed 16 bit integer value
56
+ Int32: Signed 32 bit integer value
57
+ Int64: Signed 64 bit integer value
58
+ UInt8: Unsigned 8 bit integer value
59
+ UInt16: Unsigned 16 bit integer value
60
+ UInt32: Unsigned 32 bit integer value
61
+ UInt64: Unsigned 64 bit integer value
62
+ """
63
+
44
64
  Float32 = gdal.GDT_Float32
45
65
  Float64 = gdal.GDT_Float64
46
66
  Byte = gdal.GDT_Byte
@@ -1,4 +1,6 @@
1
- from typing import Callable, Dict
1
+ from __future__ import annotations
2
+
3
+ from typing import Callable
2
4
 
3
5
  import numpy as np
4
6
  import mlx.core as mx # type: ignore
@@ -184,7 +186,7 @@ def backend_to_dtype(val):
184
186
  def astype_op(data, datatype):
185
187
  return data.astype(dtype_to_backend(datatype))
186
188
 
187
- operator_map : Dict[op,Callable] = {
189
+ operator_map: dict[op, Callable] = {
188
190
  op.ADD: mx.array.__add__,
189
191
  op.SUB: mx.array.__sub__,
190
192
  op.MUL: mul_op,
@@ -1,4 +1,6 @@
1
- from typing import Callable, Dict
1
+ from __future__ import annotations
2
+
3
+ from typing import Callable
2
4
 
3
5
  import numpy as np
4
6
  import torch
@@ -122,7 +124,7 @@ def backend_to_dtype(val):
122
124
  def astype_op(data, datatype):
123
125
  return data.astype(dtype_to_backend(datatype))
124
126
 
125
- operator_map : Dict[op,Callable] = {
127
+ operator_map: dict[op, Callable] = {
126
128
  op.ADD: np.ndarray.__add__,
127
129
  op.SUB: np.ndarray.__sub__,
128
130
  op.MUL: np.ndarray.__mul__,
yirgacheffe/_core.py CHANGED
@@ -1,5 +1,7 @@
1
+ from __future__ import annotations
2
+
1
3
  from pathlib import Path
2
- from typing import Optional, Sequence, Tuple, Union
4
+ from typing import Sequence
3
5
 
4
6
  from .layers.area import UniformAreaLayer
5
7
  from .layers.base import YirgacheffeLayer
@@ -11,30 +13,29 @@ from .window import MapProjection
11
13
  from ._backends.enumeration import dtype as DataType
12
14
 
13
15
  def read_raster(
14
- filename: Union[Path,str],
16
+ filename: Path | str,
15
17
  band: int = 1,
16
18
  ignore_nodata: bool = False,
17
19
  ) -> RasterLayer:
18
20
  """Open a raster file (e.g., GeoTIFF).
19
21
 
20
- Parameters
21
- ----------
22
- filename : Path
23
- Path of raster file to open.
24
- band : int, default=1
25
- For multi-band rasters, which band to use (defaults to first if not specified)
26
- ignore_nodata : bool, default=False
27
- If the GeoTIFF has a NODATA value, don't subsitute that value for NaN
28
-
29
- Returns
30
- -------
31
- RasterLayer
32
- Returns an layer representing the raster data.
22
+ Args:
23
+ filename: Path of raster file to open.
24
+ band: For multi-band rasters, which band to use (defaults to first if not specified).
25
+ ignore_nodata: If the GeoTIFF has a NODATA value, don't substitute that value for NaN.
26
+
27
+ Returns:
28
+ An layer representing the raster data.
29
+
30
+ Examples:
31
+ >>> import yirgacheffe as yg
32
+ >>> with yg.read_raster('test.tif') as layer:
33
+ ... total = layer.sum()
33
34
  """
34
35
  return RasterLayer.layer_from_file(filename, band, ignore_nodata)
35
36
 
36
37
  def read_narrow_raster(
37
- filename: Union[Path,str],
38
+ filename: Path | str,
38
39
  band: int = 1,
39
40
  ignore_nodata: bool = False,
40
41
  ) -> RasterLayer:
@@ -44,41 +45,35 @@ def read_narrow_raster(
44
45
  (e.g., a WGS84 map projection). For that case you can use this to load a raster that is 1 pixel wide and have
45
46
  it automatically expanded to act like a global raster in calculations.
46
47
 
47
- Parameters
48
- ----------
49
- filename : Path
50
- Path of raster file to open.
51
- band : int, default=1
52
- For multi-band rasters, which band to use (defaults to first if not specified)
53
- ignore_nodata : bool, default=False
54
- If the GeoTIFF has a NODATA value, don't subsitute that value for NaN
55
-
56
- Returns
57
- -------
58
- RasterLayer
59
- Returns an layer representing the raster data.
48
+ Args:
49
+ filename: Path of raster file to open.
50
+ band: For multi-band rasters, which band to use (defaults to first if not specified).
51
+ ignore_nodata: If the GeoTIFF has a NODATA value, don't substitute that value for NaN.
52
+
53
+ Returns:
54
+ An layer representing the raster data.
60
55
  """
61
56
  return UniformAreaLayer.layer_from_file(filename, band, ignore_nodata)
62
57
 
63
58
  def read_rasters(
64
- filenames : Sequence[Union[Path,str]],
59
+ filenames : Sequence[Path | str],
65
60
  tiled: bool=False
66
61
  ) -> GroupLayer:
67
62
  """Open a set of raster files (e.g., GeoTIFFs) as a single layer.
68
63
 
69
- Parameters
70
- ----------
71
- filenames : List[Path]
72
- List of paths of raster files to open.
73
- tiled : bool, default=False
74
- If you know that the rasters for a regular tileset, then setting this flag allows
75
- Yirgacheffe to perform certain optimisations that significantly improve performance for
76
- this use case.
77
-
78
- Returns
79
- -------
80
- GroupLayer
81
- Returns an layer representing the raster data.
64
+ Args:
65
+ filenames: List of paths of raster files to open.
66
+ tiled: If you know that the rasters for a regular tileset, then setting this flag allows
67
+ Yirgacheffe to perform certain optimisations that significantly improve performance for
68
+ this use case.
69
+
70
+ Returns:
71
+ An layer representing the raster data.
72
+
73
+ Examples:
74
+ >>> import yirgacheffe as yg
75
+ >>> with yg.read_rasters(['tile_N10_E10.tif', 'tile_N20_E10.tif']) as all_tiles:
76
+ ... ...
82
77
  """
83
78
  if not tiled:
84
79
  return GroupLayer.layer_from_files(filenames)
@@ -86,31 +81,28 @@ def read_rasters(
86
81
  return TiledGroupLayer.layer_from_files(filenames)
87
82
 
88
83
  def read_shape(
89
- filename: Union[Path,str],
90
- projection: Union[Optional[MapProjection],Optional[Tuple[str,Tuple[float,float]]]]=None,
91
- where_filter: Optional[str] = None,
92
- datatype: Optional[DataType] = None,
93
- burn_value: Union[int,float,str] = 1,
84
+ filename: Path | str,
85
+ projection: MapProjection | tuple[str, tuple[float, float]] | None = None,
86
+ where_filter: str | None = None,
87
+ datatype: DataType | None = None,
88
+ burn_value: int | float | str = 1,
94
89
  ) -> VectorLayer:
95
90
  """Open a polygon file (e.g., GeoJSON, GPKG, or ESRI Shape File).
96
91
 
97
- Parameters
98
- ----------
99
- filename : Path
100
- Path of raster file to open.
101
- projection: MapProjection or tuple, optional
102
- The map projection to use,
103
- where_filter : str, optional
104
- For use with files with many entries (e.g., GPKG), applies this filter to the data.
105
- datatype: DataType, default=DataType.Byte
106
- Specify the data type of the raster data generated.
107
- burn_value: int or float or str, default=1
108
- The value of each pixel in the polygon.
109
-
110
- Returns
111
- -------
112
- VectorLayer
113
- Returns an layer representing the vector data.
92
+ Args:
93
+ filename: Path of vector file to open.
94
+ projection: The map projection to use.
95
+ where_filter: For use with files with many entries (e.g., GPKG), applies this filter to the data.
96
+ datatype: Specify the data type of the raster data generated.
97
+ burn_value: The value of each pixel in the polygon.
98
+
99
+ Returns:
100
+ An layer representing the vector data.
101
+
102
+ Examples:
103
+ >>> import yirgacheffe as yg
104
+ >>> with yg.read_shape('range.gpkg') as layer:
105
+ ... ...
114
106
  """
115
107
 
116
108
  if projection is not None:
@@ -127,32 +119,24 @@ def read_shape(
127
119
  )
128
120
 
129
121
  def read_shape_like(
130
- filename: Union[Path,str],
122
+ filename: Path | str,
131
123
  like: YirgacheffeLayer,
132
- where_filter: Optional[str] = None,
133
- datatype: Optional[DataType] = None,
134
- burn_value: Union[int,float,str] = 1,
124
+ where_filter: str | None = None,
125
+ datatype: DataType | None = None,
126
+ burn_value: int | float | str = 1,
135
127
  ) -> VectorLayer:
136
128
  """Open a polygon file (e.g., GeoJSON, GPKG, or ESRI Shape File).
137
129
 
138
- Parameters
139
- ----------
140
- filename : Path
141
- Path of raster file to open.
142
- like: YirgacheffeLayer
143
- Another layer that has a projection and pixel scale set. This layer will
144
- use the same projection and pixel scale as that one.
145
- where_filter : str, optional
146
- For use with files with many entries (e.g., GPKG), applies this filter to the data.
147
- datatype: DataType, default=DataType.Byte
148
- Specify the data type of the raster data generated.
149
- burn_value: int or float or str, default=1
150
- The value of each pixel in the polygon.
151
-
152
- Returns
153
- -------
154
- VectorLayer
155
- Returns an layer representing the vector data.
130
+ Args:
131
+ filename: Path of vector file to open.
132
+ like: Another layer that has a projection and pixel scale set. This layer will
133
+ use the same projection and pixel scale as that one.
134
+ where_filter: For use with files with many entries (e.g., GPKG), applies this filter to the data.
135
+ datatype: Specify the data type of the raster data generated.
136
+ burn_value: The value of each pixel in the polygon.
137
+
138
+ Returns:
139
+ An layer representing the vector data.
156
140
  """
157
141
  return VectorLayer.layer_from_file_like(
158
142
  filename,
@@ -162,7 +146,7 @@ def read_shape_like(
162
146
  burn_value,
163
147
  )
164
148
 
165
- def constant(value: Union[int,float]) -> ConstantLayer:
149
+ def constant(value: int | float) -> ConstantLayer:
166
150
  """Generate a layer that has the same value in all pixels regardless of scale, projection, and area.
167
151
 
168
152
  Generally this should not be necessary unless you must have the constant as the first term in an
@@ -170,14 +154,10 @@ def constant(value: Union[int,float]) -> ConstantLayer:
170
154
  constant is the first term in the expression it must be wrapped by this call otherwise Python will
171
155
  not know that it should be part of the Yirgacheffe expression.
172
156
 
173
- Parameters
174
- ----------
175
- value : int or float
176
- The value to be in each pixel of the expression term.
157
+ Args:
158
+ value: The value to be in each pixel of the expression term.
177
159
 
178
- Returns
179
- -------
180
- ConstantLayer
181
- Returns a constant layer of the provided value.
160
+ Returns:
161
+ A constant layer of the provided value.
182
162
  """
183
163
  return ConstantLayer(value)
yirgacheffe/_operators.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import logging
2
4
  import math
3
5
  import multiprocessing
@@ -12,7 +14,7 @@ from enum import Enum
12
14
  from multiprocessing import Semaphore, Process
13
15
  from multiprocessing.managers import SharedMemoryManager
14
16
  from pathlib import Path
15
- from typing import Callable, Dict, List, Optional, Union
17
+ from typing import Callable
16
18
 
17
19
  import deprecation
18
20
  import numpy as np
@@ -265,10 +267,10 @@ class LayerMathMixin:
265
267
 
266
268
  def to_geotiff(
267
269
  self,
268
- filename: Union[Path,str],
270
+ filename: Path | str,
269
271
  and_sum: bool = False,
270
- parallelism:Optional[Union[int,bool]]=None
271
- ) -> Optional[float]:
272
+ parallelism: int | bool | None = None
273
+ ) -> float | None:
272
274
  return LayerOperation(self).to_geotiff(filename, and_sum, parallelism)
273
275
 
274
276
  def sum(self):
@@ -398,7 +400,7 @@ class LayerOperation(LayerMathMixin):
398
400
  def area(self) -> Area:
399
401
  return self._get_operation_area(self.map_projection)
400
402
 
401
- def _get_operation_area(self, projection: Optional[MapProjection]) -> Area:
403
+ def _get_operation_area(self, projection: MapProjection | None) -> Area:
402
404
  lhs_area = self.lhs._get_operation_area(projection)
403
405
  try:
404
406
  rhs_area = self.rhs._get_operation_area(projection)
@@ -482,7 +484,7 @@ class LayerOperation(LayerMathMixin):
482
484
 
483
485
  @property
484
486
  def datatype(self) -> DataType:
485
- internal_types: List[DataType] = [
487
+ internal_types: list[DataType] = [
486
488
  self.lhs.datatype
487
489
  ]
488
490
  if self.rhs is not None:
@@ -511,7 +513,7 @@ class LayerOperation(LayerMathMixin):
511
513
  return projection
512
514
 
513
515
  @property
514
- def map_projection(self) -> Optional[MapProjection]:
516
+ def map_projection(self) -> MapProjection | None:
515
517
  try:
516
518
  projection = self.lhs.map_projection
517
519
  except AttributeError:
@@ -530,7 +532,7 @@ class LayerOperation(LayerMathMixin):
530
532
  projection: MapProjection,
531
533
  index: int,
532
534
  step: int,
533
- target_window:Optional[Window]=None
535
+ target_window: Window | None = None
534
536
  ):
535
537
 
536
538
  if self.buffer_padding:
@@ -607,7 +609,7 @@ class LayerOperation(LayerMathMixin):
607
609
  res = chunk_max
608
610
  return res
609
611
 
610
- def save(self, destination_layer, and_sum=False, callback=None, band=1) -> Optional[float]:
612
+ def save(self, destination_layer, and_sum=False, callback=None, band=1) -> float | None:
611
613
  """
612
614
  Calling save will write the output of the operation to the provied layer.
613
615
  If you provide sum as true it will additionall compute the sum and return that.
@@ -723,7 +725,7 @@ class LayerOperation(LayerMathMixin):
723
725
  callback=None,
724
726
  parallelism=None,
725
727
  band=1
726
- ) -> Optional[float]:
728
+ ) -> float | None:
727
729
  assert (destination_layer is not None) or and_sum
728
730
  try:
729
731
  computation_window = self.window
@@ -763,7 +765,7 @@ class LayerOperation(LayerMathMixin):
763
765
  or (computation_window.ysize != destination_window.ysize):
764
766
  raise ValueError("Destination raster window size does not match input raster window size.")
765
767
 
766
- np_type_map : Dict[int, np.dtype] = {
768
+ np_type_map: dict[int, np.dtype] = {
767
769
  gdal.GDT_Byte: np.dtype('byte'),
768
770
  gdal.GDT_Float32: np.dtype('float32'),
769
771
  gdal.GDT_Float64: np.dtype('float64'),
@@ -882,7 +884,7 @@ class LayerOperation(LayerMathMixin):
882
884
  callback=None,
883
885
  parallelism=None,
884
886
  band=1
885
- ) -> Optional[float]:
887
+ ) -> float | None:
886
888
  if destination_layer is None:
887
889
  raise ValueError("Layer is required")
888
890
  return self._parallel_save(destination_layer, and_sum, callback, parallelism, band)
@@ -892,25 +894,20 @@ class LayerOperation(LayerMathMixin):
892
894
 
893
895
  def to_geotiff(
894
896
  self,
895
- filename: Union[Path,str],
897
+ filename: Path | str,
896
898
  and_sum: bool = False,
897
- parallelism:Optional[Union[int,bool]] = None
898
- ) -> Optional[float]:
899
+ parallelism: int | bool | None = None
900
+ ) -> float | None:
899
901
  """Saves a calculation to a raster file, optionally also returning the sum of pixels.
900
902
 
901
- Parameters
902
- ----------
903
- filename : Path
904
- Path of the raster to save the result to.
905
- and_sum : bool, default=False
906
- If true then the function will also calculate the sum of the raster as it goes and return that value.
907
- parallelism : int or bool, optional, default=None
908
- If passed, attempt to use multiple CPU cores up to the number provided, or if set to True, yirgacheffe
909
- will pick a sensible value.
910
-
911
- Returns
912
- -------
913
- float, optional
903
+ Args:
904
+ filename: Path of the raster to save the result to.
905
+ and_sum: If true then the function will also calculate the sum of the raster as it goes and return
906
+ that value.
907
+ parallelism: If passed, attempt to use multiple CPU cores up to the number provided, or if set to True,
908
+ yirgacheffe will pick a sensible value.
909
+
910
+ Returns:
914
911
  Either returns None, or the sum of the pixels in the resulting raster if `and_sum` was specified.
915
912
  """
916
913
 
@@ -1,6 +1,8 @@
1
+ from __future__ import annotations
2
+
1
3
  from math import ceil, floor
2
4
  from pathlib import Path
3
- from typing import Any, Optional, Union
5
+ from typing import Any
4
6
 
5
7
  import numpy
6
8
  from osgeo import gdal
@@ -19,7 +21,7 @@ class UniformAreaLayer(RasterLayer):
19
21
  """
20
22
 
21
23
  @staticmethod
22
- def generate_narrow_area_projection(source_filename: Union[Path,str], target_filename: Union[Path,str]) -> None:
24
+ def generate_narrow_area_projection(source_filename: Path | str, target_filename: Path | str) -> None:
23
25
  source = gdal.Open(source_filename, gdal.GA_ReadOnly)
24
26
  if source is None:
25
27
  raise FileNotFoundError(source_filename)
@@ -57,7 +59,7 @@ class UniformAreaLayer(RasterLayer):
57
59
  return False
58
60
  return True
59
61
 
60
- def __init__(self, dataset, name: Optional[str] = None, band: int = 1, ignore_nodata: bool = False):
62
+ def __init__(self, dataset, name: str | None = None, band: int = 1, ignore_nodata: bool = False):
61
63
  if dataset.RasterXSize > 1:
62
64
  raise ValueError("Expected a shrunk dataset")
63
65
  self.databand = dataset.GetRasterBand(1).ReadAsArray(0, 0, 1, dataset.RasterYSize)
@@ -1,5 +1,5 @@
1
1
  from __future__ import annotations
2
- from typing import Any, Optional, Sequence, Tuple
2
+ from typing import Any, Sequence
3
3
 
4
4
  import deprecation
5
5
 
@@ -17,17 +17,17 @@ class YirgacheffeLayer(LayerMathMixin):
17
17
 
18
18
  def __init__(self,
19
19
  area: Area,
20
- projection: Optional[MapProjection],
21
- name: Optional[str] = None
20
+ projection: MapProjection | None,
21
+ name: str | None = None
22
22
  ):
23
23
  # This is just to catch code that uses the old private API
24
24
  if projection is not None and not isinstance(projection, MapProjection):
25
25
  raise TypeError("projection value of wrong type")
26
26
 
27
27
  self._underlying_area = area
28
- self._active_area: Optional[Area] = None
28
+ self._active_area: Area | None = None
29
29
  self._projection = projection
30
- self._window: Optional[Window] = None
30
+ self._window: Window | None = None
31
31
  self.name = name
32
32
 
33
33
  self.reset_window()
@@ -48,7 +48,7 @@ class YirgacheffeLayer(LayerMathMixin):
48
48
  pass
49
49
 
50
50
  @property
51
- def _raster_dimensions(self) -> Tuple[int,int]:
51
+ def _raster_dimensions(self) -> tuple[int, int]:
52
52
  raise AttributeError("Does not have raster")
53
53
 
54
54
  @property
@@ -62,7 +62,7 @@ class YirgacheffeLayer(LayerMathMixin):
62
62
  current_version=__version__,
63
63
  details="Use `map_projection` instead."
64
64
  )
65
- def projection(self) -> Optional[str]:
65
+ def projection(self) -> str | None:
66
66
  if self._projection:
67
67
  return self._projection.name
68
68
  else:
@@ -75,14 +75,14 @@ class YirgacheffeLayer(LayerMathMixin):
75
75
  current_version=__version__,
76
76
  details="Use `map_projection` instead."
77
77
  )
78
- def pixel_scale(self) -> Optional[PixelScale]:
78
+ def pixel_scale(self) -> PixelScale | None:
79
79
  if self._projection:
80
80
  return PixelScale(self._projection.xstep, self._projection.ystep)
81
81
  else:
82
82
  return None
83
83
 
84
84
  @property
85
- def map_projection(self) -> Optional[MapProjection]:
85
+ def map_projection(self) -> MapProjection | None:
86
86
  return self._projection
87
87
 
88
88
  @property
@@ -92,7 +92,7 @@ class YirgacheffeLayer(LayerMathMixin):
92
92
  else:
93
93
  return self._underlying_area
94
94
 
95
- def _get_operation_area(self, projection: Optional[MapProjection]=None) -> Area:
95
+ def _get_operation_area(self, projection: MapProjection | None = None) -> Area:
96
96
  if self._projection is not None and projection is not None and self._projection != projection:
97
97
  raise ValueError("Calculation projection does not match layer projection")
98
98
  return self.area
@@ -153,7 +153,7 @@ class YirgacheffeLayer(LayerMathMixin):
153
153
  )
154
154
 
155
155
  @property
156
- def geo_transform(self) -> Tuple[float, float, float, float, float, float]:
156
+ def geo_transform(self) -> tuple[float, float, float, float, float, float]:
157
157
  if self._projection is None:
158
158
  raise AttributeError("No geo transform for layers without explicit pixel scale")
159
159
  return (
@@ -320,26 +320,19 @@ class YirgacheffeLayer(LayerMathMixin):
320
320
  def read_array(self, x: int, y: int, width: int, height: int) -> Any:
321
321
  """Reads data from the layer based on the current reference window.
322
322
 
323
- Arguments
324
- ---------
325
- x : int
326
- X axis offset for reading
327
- y : int
328
- Y axis offset for reading
329
- width : int
330
- Width of data to read
331
- height : int
332
- Height of data to read
333
-
334
- Results
335
- -------
336
- Any
323
+ Args:
324
+ x: X axis offset for reading
325
+ y: Y axis offset for reading
326
+ width: Width of data to read
327
+ height: Height of data to read
328
+
329
+ Returns:
337
330
  An array of values from the layer.
338
331
  """
339
332
  res = self._read_array(x, y, width, height)
340
333
  return backend.demote_array(res)
341
334
 
342
- def latlng_for_pixel(self, x_coord: int, y_coord: int) -> Tuple[float,float]:
335
+ def latlng_for_pixel(self, x_coord: int, y_coord: int) -> tuple[float, float]:
343
336
  """Get geo coords for pixel. This is relative to the set view window."""
344
337
  if self._projection is None or "WGS 84" not in self._projection.name:
345
338
  raise NotImplementedError("Not yet supported for other projections")
@@ -348,7 +341,7 @@ class YirgacheffeLayer(LayerMathMixin):
348
341
  (x_coord * self._projection.xstep) + self.area.left
349
342
  )
350
343
 
351
- def pixel_for_latlng(self, lat: float, lng: float) -> Tuple[int,int]:
344
+ def pixel_for_latlng(self, lat: float, lng: float) -> tuple[int, int]:
352
345
  """Get pixel for geo coords. This is relative to the set view window.
353
346
  Result is rounded down to nearest pixel."""
354
347
  if self._projection is None or "WGS 84" not in self._projection.name:
@@ -1,4 +1,6 @@
1
- from typing import Any, Union
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
2
4
 
3
5
  from ..window import Area, MapProjection, PixelScale, Window
4
6
  from .base import YirgacheffeLayer
@@ -8,7 +10,7 @@ from .._backends.enumeration import dtype as DataType
8
10
  class ConstantLayer(YirgacheffeLayer):
9
11
  """This is a layer that will return the identity value - can be used when an input layer is
10
12
  missing (e.g., area) without having the calculation full of branches."""
11
- def __init__(self, value: Union[int,float]): # pylint: disable=W0231
13
+ def __init__(self, value: int | float): # pylint: disable=W0231
12
14
  area = Area.world()
13
15
  super().__init__(area, None)
14
16
  self.value = float(value)