yirgacheffe 1.7.5__py3-none-any.whl → 1.7.7__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
@@ -12,7 +12,7 @@ except ModuleNotFoundError:
12
12
  pyproject_data = tomllib.load(f)
13
13
  __version__ = pyproject_data["project"]["version"]
14
14
 
15
- from ._core import read_raster, read_rasters, read_shape, read_shape_like
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
17
 
18
18
  gdal.UseExceptions()
yirgacheffe/_core.py CHANGED
@@ -1,12 +1,14 @@
1
1
  from pathlib import Path
2
2
  from typing import Optional, Sequence, Tuple, Union
3
3
 
4
+ from .layers.area import UniformAreaLayer
4
5
  from .layers.base import YirgacheffeLayer
6
+ from .layers.constant import ConstantLayer
5
7
  from .layers.group import GroupLayer, TiledGroupLayer
6
8
  from .layers.rasters import RasterLayer
7
9
  from .layers.vectors import VectorLayer
8
10
  from .window import MapProjection
9
- from .operators import DataType
11
+ from ._backends.enumeration import dtype as DataType
10
12
 
11
13
  def read_raster(
12
14
  filename: Union[Path,str],
@@ -31,6 +33,33 @@ def read_raster(
31
33
  """
32
34
  return RasterLayer.layer_from_file(filename, band, ignore_nodata)
33
35
 
36
+ def read_narrow_raster(
37
+ filename: Union[Path,str],
38
+ band: int = 1,
39
+ ignore_nodata: bool = False,
40
+ ) -> RasterLayer:
41
+ """Open a 1 pixel wide raster file as a global raster.
42
+
43
+ This exists for the special use case where an area per pixel raster would have the same value per horizontal row
44
+ (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
+ it automatically expanded to act like a global raster in calculations.
46
+
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.
60
+ """
61
+ return UniformAreaLayer.layer_from_file(filename, band, ignore_nodata)
62
+
34
63
  def read_rasters(
35
64
  filenames : Sequence[Union[Path,str]],
36
65
  tiled: bool=False
@@ -132,3 +161,23 @@ def read_shape_like(
132
161
  datatype,
133
162
  burn_value,
134
163
  )
164
+
165
+ def constant(value: Union[int,float]) -> ConstantLayer:
166
+ """Generate a layer that has the same value in all pixels regardless of scale, projection, and area.
167
+
168
+ Generally this should not be necessary unless you must have the constant as the first term in an
169
+ expression, as Yirgacheffe will automatically convert numbers into constant layers. However if the
170
+ constant is the first term in the expression it must be wrapped by this call otherwise Python will
171
+ not know that it should be part of the Yirgacheffe expression.
172
+
173
+ Parameters
174
+ ----------
175
+ value : int or float
176
+ The value to be in each pixel of the expression term.
177
+
178
+ Returns
179
+ -------
180
+ ConstantLayer
181
+ Returns a constant layer of the provided value.
182
+ """
183
+ return ConstantLayer(value)