yirgacheffe 1.7.8__tar.gz → 1.7.9__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.

Potentially problematic release.


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

Files changed (58) hide show
  1. {yirgacheffe-1.7.8/yirgacheffe.egg-info → yirgacheffe-1.7.9}/PKG-INFO +6 -3
  2. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/pyproject.toml +14 -3
  3. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_datatypes.py +2 -2
  4. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_operators.py +17 -1
  5. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_backends/mlx.py +2 -2
  6. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_backends/numpy.py +2 -2
  7. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_operators.py +18 -3
  8. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/area.py +3 -2
  9. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/rasters.py +2 -2
  10. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9/yirgacheffe.egg-info}/PKG-INFO +6 -3
  11. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe.egg-info/requires.txt +5 -1
  12. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/LICENSE +0 -0
  13. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/MANIFEST.in +0 -0
  14. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/README.md +0 -0
  15. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/setup.cfg +0 -0
  16. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_area.py +0 -0
  17. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_auto_windowing.py +0 -0
  18. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_base.py +0 -0
  19. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_constants.py +0 -0
  20. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_group.py +0 -0
  21. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_h3layer.py +0 -0
  22. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_intersection.py +0 -0
  23. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_multiband.py +0 -0
  24. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_nodata.py +0 -0
  25. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_openers.py +0 -0
  26. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_optimisation.py +0 -0
  27. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_parallel_operators.py +0 -0
  28. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_pickle.py +0 -0
  29. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_projection.py +0 -0
  30. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_raster.py +0 -0
  31. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_rescaling.py +0 -0
  32. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_rounding.py +0 -0
  33. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_save_with_window.py +0 -0
  34. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_sum_with_window.py +0 -0
  35. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_uniform_area_layer.py +0 -0
  36. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_union.py +0 -0
  37. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_vectors.py +0 -0
  38. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/tests/test_window.py +0 -0
  39. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/__init__.py +0 -0
  40. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_backends/__init__.py +0 -0
  41. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_backends/enumeration.py +0 -0
  42. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/_core.py +0 -0
  43. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/constants.py +0 -0
  44. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/__init__.py +0 -0
  45. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/base.py +0 -0
  46. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/constant.py +0 -0
  47. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/group.py +0 -0
  48. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/h3layer.py +0 -0
  49. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/rescaled.py +0 -0
  50. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/layers/vectors.py +0 -0
  51. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/operators.py +0 -0
  52. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/py.typed +0 -0
  53. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/rounding.py +0 -0
  54. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe/window.py +0 -0
  55. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe.egg-info/SOURCES.txt +0 -0
  56. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe.egg-info/dependency_links.txt +0 -0
  57. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe.egg-info/entry_points.txt +0 -0
  58. {yirgacheffe-1.7.8 → yirgacheffe-1.7.9}/yirgacheffe.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yirgacheffe
3
- Version: 1.7.8
3
+ Version: 1.7.9
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
@@ -26,13 +26,16 @@ Requires-Dist: torch
26
26
  Requires-Dist: dill
27
27
  Requires-Dist: deprecation
28
28
  Requires-Dist: tomli
29
+ Requires-Dist: h3
30
+ Provides-Extra: mlx
31
+ Requires-Dist: mlx; extra == "mlx"
29
32
  Provides-Extra: dev
30
33
  Requires-Dist: mypy; extra == "dev"
31
34
  Requires-Dist: pylint; extra == "dev"
32
35
  Requires-Dist: pytest; extra == "dev"
33
- Requires-Dist: h3; extra == "dev"
34
36
  Requires-Dist: pytest-cov; extra == "dev"
35
- Requires-Dist: mlx; extra == "dev"
37
+ Requires-Dist: build; extra == "dev"
38
+ Requires-Dist: twine; extra == "dev"
36
39
  Dynamic: license-file
37
40
 
38
41
  # Yirgacheffe: a gdal wrapper that does the tricky bits
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "yirgacheffe"
9
- version = "1.7.8"
9
+ version = "1.7.9"
10
10
  description = "Abstraction of gdal datasets for doing basic math operations"
11
11
  readme = "README.md"
12
12
  authors = [{ name = "Michael Dales", email = "mwd24@cam.ac.uk" }]
@@ -28,12 +28,23 @@ dependencies = [
28
28
  "torch",
29
29
  "dill",
30
30
  "deprecation",
31
- "tomli"
31
+ "tomli",
32
+ "h3",
32
33
  ]
33
34
  requires-python = ">=3.10"
34
35
 
35
36
  [project.optional-dependencies]
36
- dev = ["mypy", "pylint", "pytest", "h3", "pytest-cov", "mlx"]
37
+ mlx = [
38
+ "mlx",
39
+ ]
40
+ dev = [
41
+ "mypy",
42
+ "pylint",
43
+ "pytest",
44
+ "pytest-cov",
45
+ "build",
46
+ "twine",
47
+ ]
37
48
 
38
49
  [project.urls]
39
50
  Homepage = "https://github.com/quantifyearth/yirgacheffe"
@@ -22,7 +22,7 @@ from tests.helpers import gdal_dataset_with_data
22
22
  ])
23
23
  def test_round_trip(gtype) -> None:
24
24
  ytype = DataType.of_gdal(gtype)
25
- backend_type = backend.dtype_to_backed(ytype)
25
+ backend_type = backend.dtype_to_backend(ytype)
26
26
  assert backend.backend_to_dtype(backend_type) == ytype
27
27
 
28
28
  @pytest.mark.parametrize("ytype", [
@@ -42,7 +42,7 @@ def test_round_trip_from_gdal(ytype) -> None:
42
42
  assert DataType.of_gdal(gtype) == ytype
43
43
 
44
44
  def test_round_trip_float64() -> None:
45
- backend_type = backend.dtype_to_backed(DataType.Float64)
45
+ backend_type = backend.dtype_to_backend(DataType.Float64)
46
46
  ytype = backend.backend_to_dtype(backend_type)
47
47
  match BACKEND:
48
48
  case "NUMPY":
@@ -1428,18 +1428,34 @@ def test_ceil_module() -> None:
1428
1428
  actual = result.read_array(0, 0, 4, 2)
1429
1429
  assert (expected == actual).all()
1430
1430
 
1431
- def test_to_geotiff_on_layer() -> None:
1431
+ def test_to_geotiff_on_int_layer() -> None:
1432
1432
  data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
1433
1433
  layer1 = RasterLayer(gdal_dataset_with_data((0.0, 0.0), 0.02, data1))
1434
+ assert layer1.datatype == DataType.Int64
1434
1435
 
1435
1436
  with tempfile.TemporaryDirectory() as tempdir:
1436
1437
  filename = os.path.join(tempdir, "test.tif")
1437
1438
  layer1.to_geotiff(filename)
1438
1439
 
1439
1440
  with RasterLayer.layer_from_file(filename) as result:
1441
+ assert result.datatype == DataType.Int64
1440
1442
  actual = result.read_array(0, 0, 4, 2)
1441
1443
  assert (data1 == actual).all()
1442
1444
 
1445
+ def test_to_geotiff_on_float_layer() -> None:
1446
+ data1 = np.array([[1.1, 2.1, 3.1, 4.1], [5.1, 6.1, 7.1, 8.1]])
1447
+ layer1 = RasterLayer(gdal_dataset_with_data((0.0, 0.0), 0.02, data1))
1448
+ assert layer1.datatype == DataType.Float64
1449
+
1450
+ with tempfile.TemporaryDirectory() as tempdir:
1451
+ filename = os.path.join(tempdir, "test.tif")
1452
+ layer1.to_geotiff(filename)
1453
+
1454
+ with RasterLayer.layer_from_file(filename) as result:
1455
+ assert result.datatype == DataType.Float64
1456
+ actual = result.read_array(0, 0, 4, 2)
1457
+ assert np.isclose(data1, actual).all()
1458
+
1443
1459
  def test_to_geotiff_single_thread() -> None:
1444
1460
  data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
1445
1461
  layer1 = RasterLayer(gdal_dataset_with_data((0.0, 0.0), 0.02, data1))
@@ -131,7 +131,7 @@ def conv2d_op(data, weights):
131
131
  return res[0]
132
132
 
133
133
 
134
- def dtype_to_backed(dt):
134
+ def dtype_to_backend(dt):
135
135
  match dt:
136
136
  case dtype.Float32:
137
137
  return mx.float32
@@ -182,7 +182,7 @@ def backend_to_dtype(val):
182
182
  raise ValueError
183
183
 
184
184
  def astype_op(data, datatype):
185
- return data.astype(dtype_to_backed(datatype))
185
+ return data.astype(dtype_to_backend(datatype))
186
186
 
187
187
  operator_map : Dict[op,Callable] = {
188
188
  op.ADD: mx.array.__add__,
@@ -67,7 +67,7 @@ def conv2d_op(data, weights):
67
67
  res = conv(preped_data)
68
68
  return res.detach().numpy()[0][0]
69
69
 
70
- def dtype_to_backed(dt):
70
+ def dtype_to_backend(dt):
71
71
  match dt:
72
72
  case dtype.Float32:
73
73
  return np.float32
@@ -120,7 +120,7 @@ def backend_to_dtype(val):
120
120
  raise ValueError
121
121
 
122
122
  def astype_op(data, datatype):
123
- return data.astype(dtype_to_backed(datatype))
123
+ return data.astype(dtype_to_backend(datatype))
124
124
 
125
125
  operator_map : Dict[op,Callable] = {
126
126
  op.ADD: np.ndarray.__add__,
@@ -12,7 +12,7 @@ from enum import Enum
12
12
  from multiprocessing import Semaphore, Process
13
13
  from multiprocessing.managers import SharedMemoryManager
14
14
  from pathlib import Path
15
- from typing import Callable, Dict, Optional, Union
15
+ from typing import Callable, Dict, List, Optional, Union
16
16
 
17
17
  import deprecation
18
18
  import numpy as np
@@ -26,6 +26,8 @@ from .window import Area, PixelScale, MapProjection, Window
26
26
  from ._backends import backend
27
27
  from ._backends.enumeration import operators as op
28
28
  from ._backends.enumeration import dtype as DataType
29
+ from ._backends.numpy import dtype_to_backend as dtype_to_numpy
30
+ from ._backends.numpy import backend_to_dtype as numpy_to_dtype
29
31
 
30
32
  logger = logging.getLogger(__name__)
31
33
  logger.setLevel(logging.WARNING)
@@ -47,6 +49,11 @@ class LayerConstant:
47
49
  def _eval(self, _area, _projection, _index, _step, _target_window):
48
50
  return self.val
49
51
 
52
+ @property
53
+ def datatype(self) -> DataType:
54
+ numpy_type = np.result_type(self.val)
55
+ return numpy_to_dtype(numpy_type)
56
+
50
57
  @property
51
58
  def area(self) -> Area:
52
59
  return Area.world()
@@ -475,8 +482,16 @@ class LayerOperation(LayerMathMixin):
475
482
 
476
483
  @property
477
484
  def datatype(self) -> DataType:
478
- # TODO: Work out how to indicate type promotion via numpy
479
- return self.lhs.datatype
485
+ internal_types: List[DataType] = [
486
+ self.lhs.datatype
487
+ ]
488
+ if self.rhs is not None:
489
+ internal_types.append(self.rhs.datatype)
490
+ if self.other is not None:
491
+ internal_types.append(self.other.datatype)
492
+ internal_types_as_numpy_types = [dtype_to_numpy(x) for x in internal_types]
493
+ coerced_type = np.result_type(*internal_types_as_numpy_types)
494
+ return numpy_to_dtype(coerced_type)
480
495
 
481
496
  @property
482
497
  @deprecation.deprecated(
@@ -1,5 +1,6 @@
1
1
  from math import ceil, floor
2
- from typing import Any, Optional
2
+ from pathlib import Path
3
+ from typing import Any, Optional, Union
3
4
 
4
5
  import numpy
5
6
  from osgeo import gdal
@@ -18,7 +19,7 @@ class UniformAreaLayer(RasterLayer):
18
19
  """
19
20
 
20
21
  @staticmethod
21
- def generate_narrow_area_projection(source_filename: str, target_filename: str) -> None:
22
+ def generate_narrow_area_projection(source_filename: Union[Path,str], target_filename: Union[Path,str]) -> None:
22
23
  source = gdal.Open(source_filename, gdal.GA_ReadOnly)
23
24
  if source is None:
24
25
  raise FileNotFoundError(source_filename)
@@ -27,7 +27,7 @@ class RasterLayer(YirgacheffeLayer):
27
27
  area: Area,
28
28
  scale: PixelScale,
29
29
  datatype: Union[int, DataType],
30
- filename: Optional[str]=None,
30
+ filename: Optional[Union[Path,str]]=None,
31
31
  projection: str=WGS_84_PROJECTION,
32
32
  name: Optional[str]=None,
33
33
  compress: bool=True,
@@ -165,7 +165,7 @@ class RasterLayer(YirgacheffeLayer):
165
165
  cls,
166
166
  source: RasterLayer,
167
167
  new_pixel_scale: PixelScale,
168
- filename: Optional[str]=None,
168
+ filename: Optional[Union[Path,str]]=None,
169
169
  compress: bool=True,
170
170
  algorithm: int=gdal.GRA_NearestNeighbour,
171
171
  ) -> RasterLayer:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yirgacheffe
3
- Version: 1.7.8
3
+ Version: 1.7.9
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
@@ -26,13 +26,16 @@ Requires-Dist: torch
26
26
  Requires-Dist: dill
27
27
  Requires-Dist: deprecation
28
28
  Requires-Dist: tomli
29
+ Requires-Dist: h3
30
+ Provides-Extra: mlx
31
+ Requires-Dist: mlx; extra == "mlx"
29
32
  Provides-Extra: dev
30
33
  Requires-Dist: mypy; extra == "dev"
31
34
  Requires-Dist: pylint; extra == "dev"
32
35
  Requires-Dist: pytest; extra == "dev"
33
- Requires-Dist: h3; extra == "dev"
34
36
  Requires-Dist: pytest-cov; extra == "dev"
35
- Requires-Dist: mlx; extra == "dev"
37
+ Requires-Dist: build; extra == "dev"
38
+ Requires-Dist: twine; extra == "dev"
36
39
  Dynamic: license-file
37
40
 
38
41
  # Yirgacheffe: a gdal wrapper that does the tricky bits
@@ -5,11 +5,15 @@ torch
5
5
  dill
6
6
  deprecation
7
7
  tomli
8
+ h3
8
9
 
9
10
  [dev]
10
11
  mypy
11
12
  pylint
12
13
  pytest
13
- h3
14
14
  pytest-cov
15
+ build
16
+ twine
17
+
18
+ [mlx]
15
19
  mlx
File without changes
File without changes
File without changes
File without changes