yirgacheffe 1.9.4__py3-none-any.whl → 1.9.5__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
@@ -13,7 +13,7 @@ except ModuleNotFoundError:
13
13
  __version__ = pyproject_data["project"]["version"]
14
14
 
15
15
  from .layers import YirgacheffeLayer
16
- from ._core import read_raster, read_rasters, read_shape, read_shape_like, constant, read_narrow_raster
16
+ from ._core import read_raster, read_rasters, read_shape, read_shape_like, constant, read_narrow_raster, from_array
17
17
  from .constants import WGS_84_PROJECTION
18
18
  from .window import Area, MapProjection, Window
19
19
  from ._backends.enumeration import dtype as DataType
@@ -1,5 +1,8 @@
1
+ from __future__ import annotations
2
+
1
3
  from enum import Enum
2
4
 
5
+ import numpy as np
3
6
  from osgeo import gdal
4
7
 
5
8
  class operators(Enum):
@@ -77,5 +80,31 @@ class dtype(Enum):
77
80
  return self.value
78
81
 
79
82
  @classmethod
80
- def of_gdal(cls, val):
83
+ def of_gdal(cls, val: int) -> dtype:
81
84
  return cls(val)
85
+
86
+ @classmethod
87
+ def of_array(cls, val: np.ndarray) -> dtype:
88
+ match val.dtype:
89
+ case np.float32:
90
+ return dtype.Float32
91
+ case np.float64:
92
+ return dtype.Float64
93
+ case np.int8:
94
+ return dtype.Int8
95
+ case np.int16:
96
+ return dtype.Int16
97
+ case np.int32:
98
+ return dtype.Int32
99
+ case np.int64:
100
+ return dtype.Int64
101
+ case np.uint8:
102
+ return dtype.UInt8
103
+ case np.uint16:
104
+ return dtype.UInt16
105
+ case np.uint32:
106
+ return dtype.UInt32
107
+ case np.uint64:
108
+ return dtype.UInt64
109
+ case _:
110
+ raise ValueError
yirgacheffe/_core.py CHANGED
@@ -3,13 +3,15 @@ from __future__ import annotations
3
3
  from pathlib import Path
4
4
  from typing import Sequence
5
5
 
6
+ import numpy as np
7
+
6
8
  from .layers.area import UniformAreaLayer
7
9
  from .layers.base import YirgacheffeLayer
8
10
  from .layers.constant import ConstantLayer
9
11
  from .layers.group import GroupLayer, TiledGroupLayer
10
12
  from .layers.rasters import RasterLayer
11
13
  from .layers.vectors import VectorLayer
12
- from .window import MapProjection
14
+ from .window import Area, MapProjection
13
15
  from ._backends.enumeration import dtype as DataType
14
16
 
15
17
  def read_raster(
@@ -161,3 +163,50 @@ def constant(value: int | float) -> YirgacheffeLayer:
161
163
  A constant layer of the provided value.
162
164
  """
163
165
  return ConstantLayer(value)
166
+
167
+ def from_array(
168
+ values: np.ndarray,
169
+ origin: tuple[float, float],
170
+ projection: MapProjection | tuple[str, tuple[float, float]],
171
+ ) -> YirgacheffeLayer:
172
+ """Creates an in-memory layer from a numerical array.
173
+
174
+ Args:
175
+ values: a 2D array of data values, with Y on the first dimension, X on
176
+ the second dimension.
177
+ origin: the position of the top left pixel in the geospatial space
178
+ projection: the map projection and pixel scale to use.
179
+
180
+ Returns:
181
+ A geospatial layer that uses the provided data for its values.
182
+ """
183
+
184
+ if projection is None:
185
+ raise ValueError("Projection must not be none")
186
+
187
+ if not isinstance(projection, MapProjection):
188
+ projection_name, scale_tuple = projection
189
+ projection = MapProjection(projection_name, scale_tuple[0], scale_tuple[1])
190
+
191
+ dims = values.shape
192
+
193
+ area = Area(
194
+ left=origin[0],
195
+ top=origin[1],
196
+ right=origin[0] + (projection.xstep * dims[1]),
197
+ bottom=origin[1] + (projection.ystep * dims[0])
198
+ )
199
+
200
+ layer = RasterLayer.empty_raster_layer(
201
+ area,
202
+ scale=projection.scale,
203
+ datatype=DataType.of_array(values),
204
+ filename=None,
205
+ projection=projection.name,
206
+ )
207
+ assert layer._dataset
208
+ assert layer._dataset.RasterXSize == dims[1]
209
+ assert layer._dataset.RasterYSize == dims[0]
210
+ layer._dataset.GetRasterBand(1).WriteArray(values, 0, 0)
211
+
212
+ return layer
@@ -81,7 +81,7 @@ class GroupLayer(YirgacheffeLayer):
81
81
 
82
82
  @property
83
83
  def datatype(self) -> DataType:
84
- return DataType.of_gdal(self.layers[0].datatype)
84
+ return self.layers[0].datatype
85
85
 
86
86
  def set_window_for_intersection(self, new_area: Area) -> None:
87
87
  super().set_window_for_intersection(new_area)
yirgacheffe/window.py CHANGED
@@ -22,6 +22,15 @@ class MapProjection:
22
22
  name: The map projection used in WKT format.
23
23
  xstep: The number of units horizontal distance a step of one pixel makes in the map projection.
24
24
  ystep: The number of units vertical distance a step of one pixel makes in the map projection.
25
+
26
+ Examples:
27
+ Create a map projection using an EPSG code:
28
+
29
+ >>> proj_wgs84 = MapProjection("epsg:4326", 0.001, -0.001)
30
+
31
+ Create a projection using an ESRI code:
32
+
33
+ >>> proj_esri = MapProjection("esri:54030", 1000, -1000)
25
34
  """
26
35
 
27
36
  def __init__(self, projection_string: str, xstep: float, ystep: float) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yirgacheffe
3
- Version: 1.9.4
3
+ Version: 1.9.5
4
4
  Summary: Abstraction of gdal datasets for doing basic math operations
5
5
  Author-email: Michael Dales <mwd24@cam.ac.uk>
6
6
  License-Expression: ISC
@@ -1,27 +1,27 @@
1
- yirgacheffe/__init__.py,sha256=JWQOJP_RPlBmN_N3vPGH-9FByjRQKCWUSnsh4fPNtW8,915
2
- yirgacheffe/_core.py,sha256=-X6wTjAKagcjWcH14IKp75Nf-kANO_Nsd8wKm5XEQzE,5750
1
+ yirgacheffe/__init__.py,sha256=Ps6W8A1TRriVNxZEF3jW1_KOLEtji4ffyoGRmQXne8g,927
2
+ yirgacheffe/_core.py,sha256=Tr6RAiRZOO3vbtiTjLoNRjjd1DkXYZOgpDqrjs7jCBw,7231
3
3
  yirgacheffe/_operators.py,sha256=VGQ9AOOJP6cxsr_G2kxdaPaXqKi7K1csocxsudlRwVc,43440
4
4
  yirgacheffe/constants.py,sha256=bKUjOGNj19zwggV79lJgK7tiv51DH2-rgNOKswl2gvQ,293
5
5
  yirgacheffe/operators.py,sha256=Y1KkNt79N1elR4ZplQaQngx29wdf2QFF_5la4PI3EhI,412
6
6
  yirgacheffe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  yirgacheffe/rounding.py,sha256=Jzd9qlLnLpigT95GbQTByvYOo639Nfq4LBEVyvhYdoc,2289
8
- yirgacheffe/window.py,sha256=QuyBLOwKFI0XkEQ4Bd2hdELPbJSfHL7mt5KSi7CIHcE,9505
8
+ yirgacheffe/window.py,sha256=kAAsE3t49DbffrW78DLZuGwgT-MCpM3WBJQ-5MO5ciM,9755
9
9
  yirgacheffe/_backends/__init__.py,sha256=jN-2iRrHStnPI6cNL7XhwhsROtI0EaGfIrbF5c-ECV0,334
10
- yirgacheffe/_backends/enumeration.py,sha256=9bcCXz9Ssrh8Oh1iazodkx6Gm2kQBi9HQ9z9zehS4AE,1806
10
+ yirgacheffe/_backends/enumeration.py,sha256=Clb-oRha65po_dED_lECXjnih-n77CtUg18-34xX6nA,2652
11
11
  yirgacheffe/_backends/mlx.py,sha256=U1gl1lK1mZXLEET6ylF1TNs6WJ0PBEvfSk7ppn28n8w,6203
12
12
  yirgacheffe/_backends/numpy.py,sha256=Gxx49JJH79GFEkKIpV6IyjCUcdtN5-qLlzRfylzKhS4,4142
13
13
  yirgacheffe/layers/__init__.py,sha256=mYKjw5YTcMNv_hMy7a6K4yRzIuNUbR8WuBTw4WIAmSk,435
14
14
  yirgacheffe/layers/area.py,sha256=wJcMHbLJBaXS4BeFbu5rYeKfgu3gvaE9hwQ5j6aw-y4,3976
15
15
  yirgacheffe/layers/base.py,sha256=7b4WXuvnmCv8mR0iyCIuSEolnV8D3f2vtCaYlcJCIa8,13201
16
16
  yirgacheffe/layers/constant.py,sha256=gtkQ98Z01CYYDgFElswtRZY4ZG3UnS5NIAoIVue5ufk,1481
17
- yirgacheffe/layers/group.py,sha256=yaqf-ra_Vh59yrWcz7-OvJ1fBnTcBXZd18AfRDN5Ymo,16157
17
+ yirgacheffe/layers/group.py,sha256=jFJ60YcbkLNeD-2w3QOLwbcYEWdgicrXMClIo2vz97Q,16139
18
18
  yirgacheffe/layers/h3layer.py,sha256=Rq1bFo7CApIh5NdBcV7hSj3hm-DszY79nhYsTRAvJ_g,9916
19
19
  yirgacheffe/layers/rasters.py,sha256=zBE9uXm6LvAQF2_XdQzcOgJQOQWGmuPflY5JNDrUf3k,13527
20
20
  yirgacheffe/layers/rescaled.py,sha256=gEFbXeYxX1nVn7eQYmbGww90_yc5ENmgQrD_WxXxpQE,3352
21
21
  yirgacheffe/layers/vectors.py,sha256=A27kuTr0C9BZhHG0-cplNEa7aSNcse37Pm9xTjEzv-c,19990
22
- yirgacheffe-1.9.4.dist-info/licenses/LICENSE,sha256=dNSHwUCJr6axStTKDEdnJtfmDdFqlE3h1NPCveqPfnY,757
23
- yirgacheffe-1.9.4.dist-info/METADATA,sha256=cUAABIwPG9_RTO0ylH25O_7usbtQneZwTUCsfk_SLIs,7407
24
- yirgacheffe-1.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- yirgacheffe-1.9.4.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
26
- yirgacheffe-1.9.4.dist-info/top_level.txt,sha256=9DBFlKO2Ld3hG6TuE3qOTd3Tt8ugTiXil4AN4Wr9_y0,12
27
- yirgacheffe-1.9.4.dist-info/RECORD,,
22
+ yirgacheffe-1.9.5.dist-info/licenses/LICENSE,sha256=dNSHwUCJr6axStTKDEdnJtfmDdFqlE3h1NPCveqPfnY,757
23
+ yirgacheffe-1.9.5.dist-info/METADATA,sha256=TvX6Nwvdp_u80s9PXHCvSoxndvp4mjOBE1wRcn-neL0,7407
24
+ yirgacheffe-1.9.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ yirgacheffe-1.9.5.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
26
+ yirgacheffe-1.9.5.dist-info/top_level.txt,sha256=9DBFlKO2Ld3hG6TuE3qOTd3Tt8ugTiXil4AN4Wr9_y0,12
27
+ yirgacheffe-1.9.5.dist-info/RECORD,,