yirgacheffe 1.3.2__py3-none-any.whl → 1.3.4__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.

@@ -35,7 +35,9 @@ class operators(Enum):
35
35
  CONV2D = 30
36
36
  ABS = 31
37
37
  ASTYPE = 32
38
-
38
+ FLOOR = 33
39
+ ROUND = 34
40
+ CEIL = 35
39
41
 
40
42
  class dtype(Enum):
41
43
  Float32 = gdal.GDT_Float32
@@ -45,6 +45,9 @@ allclose = mx.allclose
45
45
  remainder_op = mx.remainder
46
46
  floordiv_op = mx.array.__floordiv__
47
47
  abs_op = mx.abs
48
+ floor_op = mx.floor
49
+ round_op = mx.round
50
+ ceil_op = mx.ceil
48
51
 
49
52
  def sum_op(a):
50
53
  # There are weird issues around how MLX overflows int8, so just promote the data ahead of summing
@@ -211,4 +214,7 @@ operator_map = {
211
214
  op.CONV2D: conv2d_op,
212
215
  op.ABS: mx.abs,
213
216
  op.ASTYPE: astype_op,
217
+ op.FLOOR: mx.floor,
218
+ op.ROUND: mx.round,
219
+ op.CEIL: mx.ceil,
214
220
  }
@@ -48,6 +48,9 @@ allclose = np.allclose
48
48
  remainder_op = np.ndarray.__mod__
49
49
  floordiv_op = np.ndarray.__floordiv__
50
50
  abs_op = np.abs
51
+ floor_op = np.floor
52
+ round_op = np.round
53
+ ceil_op = np.ceil
51
54
 
52
55
  def conv2d_op(data, weights):
53
56
  # torch wants to process dimensions of channels of width of height
@@ -149,4 +152,7 @@ operator_map = {
149
152
  op.CONV2D: conv2d_op,
150
153
  op.ABS: np.abs,
151
154
  op.ASTYPE: astype_op,
155
+ op.FLOOR: np.floor,
156
+ op.ROUND: np.round,
157
+ op.CEIL: np.ceil,
152
158
  }
yirgacheffe/operators.py CHANGED
@@ -121,6 +121,27 @@ class LayerMathMixin:
121
121
  window_op=WindowOperation.NONE,
122
122
  )
123
123
 
124
+ def floor(self):
125
+ return LayerOperation(
126
+ self,
127
+ op.FLOOR,
128
+ window_op=WindowOperation.NONE,
129
+ )
130
+
131
+ def round(self):
132
+ return LayerOperation(
133
+ self,
134
+ op.ROUND,
135
+ window_op=WindowOperation.NONE,
136
+ )
137
+
138
+ def ceil(self):
139
+ return LayerOperation(
140
+ self,
141
+ op.CEIL,
142
+ window_op=WindowOperation.NONE,
143
+ )
144
+
124
145
  def log(self):
125
146
  return LayerOperation(
126
147
  self,
@@ -500,9 +521,17 @@ class LayerOperation(LayerMathMixin):
500
521
  except AttributeError as exc:
501
522
  raise ValueError("Layer must be a raster backed layer") from exc
502
523
 
503
- computation_window = self.window
504
524
  destination_window = destination_layer.window
505
525
 
526
+ # If we're calculating purely from a constant layer, then we don't have a window or area
527
+ # so we should use the destination raster details.
528
+ try:
529
+ computation_window = self.window
530
+ computation_area = self.area
531
+ except AttributeError:
532
+ computation_window = destination_window
533
+ computation_area = destination_layer.area
534
+
506
535
  if (computation_window.xsize != destination_window.xsize) \
507
536
  or (computation_window.ysize != destination_window.ysize):
508
537
  raise ValueError("Destination raster window size does not match input raster window size.")
@@ -515,7 +544,7 @@ class LayerOperation(LayerMathMixin):
515
544
  step=self.ystep
516
545
  if yoffset+step > computation_window.ysize:
517
546
  step = computation_window.ysize - yoffset
518
- chunk = self._eval(self.area, yoffset, step, computation_window)
547
+ chunk = self._eval(computation_area, yoffset, step, computation_window)
519
548
  if isinstance(chunk, (float, int)):
520
549
  chunk = backend.full((step, destination_window.xsize), chunk)
521
550
  band.WriteArray(
@@ -578,7 +607,18 @@ class LayerOperation(LayerMathMixin):
578
607
 
579
608
  def _parallel_save(self, destination_layer, and_sum=False, callback=None, parallelism=None, band=1):
580
609
  assert (destination_layer is not None) or and_sum
581
- computation_window = self.window
610
+ try:
611
+ computation_window = self.window
612
+ except AttributeError:
613
+ # This is most likely because the calculation is on a constant layer (or combination of only constant
614
+ # layers) and there's no real benefit to parallel saving then, so to keep this code from getting yet
615
+ # more complicated just fall back to the single threaded path
616
+ if destination_layer:
617
+ return self.save(destination_layer, and_sum, callback, band)
618
+ elif and_sum:
619
+ return self.sum()
620
+ else:
621
+ assert False
582
622
 
583
623
  worker_count = parallelism or multiprocessing.cpu_count()
584
624
  work_blocks = len(range(0, computation_window.ysize, self.ystep))
@@ -765,3 +805,6 @@ exp2 = LayerOperation.exp2
765
805
  nan_to_num = LayerOperation.nan_to_num
766
806
  isin = LayerOperation.isin
767
807
  abs = LayerOperation.abs # pylint: disable=W0622
808
+ floor = LayerOperation.floor
809
+ round = LayerOperation.round # pylint: disable=W0622
810
+ ceil = LayerOperation.ceil
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yirgacheffe
3
- Version: 1.3.2
3
+ Version: 1.3.4
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
@@ -304,9 +304,11 @@ with RasterLayer.layer_from_file('test1.tif') as layer1:
304
304
  The following math operators common to numpy and other libraries are currently supported:
305
305
 
306
306
  * abs
307
+ * ceil
307
308
  * clip
308
309
  * exp
309
310
  * exp2
311
+ * floor
310
312
  * isin
311
313
  * log
312
314
  * log2
@@ -314,6 +316,7 @@ The following math operators common to numpy and other libraries are currently s
314
316
  * maximum
315
317
  * minimum
316
318
  * nan_to_num
319
+ * round
317
320
 
318
321
  Typically these can be invoked either on a layer as a method:
319
322
 
@@ -1,13 +1,13 @@
1
1
  yirgacheffe/__init__.py,sha256=U5AoPk_iWreSCexG2ID-tmSXiJz4_9Lvzbf42DMvT7k,658
2
2
  yirgacheffe/constants.py,sha256=WccPcISG1FqL_Kw1tI72BJGjHy6RvEcGEx_I9RK776U,42
3
3
  yirgacheffe/h3layer.py,sha256=MT2hm6n64hzHSeRPvjn-CwErru937ntKXbEU7CIlPSU,91
4
- yirgacheffe/operators.py,sha256=f72xFsH6KmmWhrbsU0V7g_jgTJQ4BAaZzDhV7i-wPio,27607
4
+ yirgacheffe/operators.py,sha256=KIMYmRl0uJG9LYnmX_uwHhGNfCNOEZlfaXZU7kD1aL4,29081
5
5
  yirgacheffe/rounding.py,sha256=ggBG4lMyLMtHLW3dBxr3gBCcF2qhRrY5etZiFGlIoqA,2258
6
6
  yirgacheffe/window.py,sha256=0XZdwD4mz0bRU9eBhFY1Xk1hQt6FqCKp3BnUgxZup3c,5224
7
7
  yirgacheffe/backends/__init__.py,sha256=149-fg1PVXC36cgyuSZsU8SYOm65fzUmYN_MHZtEyrY,313
8
- yirgacheffe/backends/enumeration.py,sha256=v1CsWSq97LNS4QXgUc59OyaBQWF5dAG5cDrMY2NWx1o,960
9
- yirgacheffe/backends/mlx.py,sha256=Bt0Jlt96ECHZmBwI7kqJ6kSVsLDU-6rq0E7oUt7EzOg,5969
10
- yirgacheffe/backends/numpy.py,sha256=t8rPDqkghE5UfkJi8r6ZUg14f1nL2lsPp61FGqUJwCg,3887
8
+ yirgacheffe/backends/enumeration.py,sha256=pADawllxpW_hW-IVVvZpHWIKzvEMs9aaqfkZRD1zjnY,1003
9
+ yirgacheffe/backends/mlx.py,sha256=3HSKU7ZU846trdxeVhPj2OPkFWrCxfbjB65-NpnmANQ,6097
10
+ yirgacheffe/backends/numpy.py,sha256=qQYvff1oHIuGUimV04rcFyPxnwEf0acvVd3ijeom4T4,4015
11
11
  yirgacheffe/layers/__init__.py,sha256=GR_TJlhPKDK1212CG2T99X2FdBlNo_G8q2zQ6nJbiO4,1534
12
12
  yirgacheffe/layers/area.py,sha256=yIRXzeeLi3MMyuh4LG_VgZrKNWe5xwZgDGdgaoYRpP0,3805
13
13
  yirgacheffe/layers/base.py,sha256=vVxumZgFLTYXFtVxJEiBVV1QqtQWa5kwL10ckUF-ykE,11617
@@ -17,9 +17,9 @@ yirgacheffe/layers/h3layer.py,sha256=Cyrw_6nXc1a_Twsb0FfexKhHAbegKXStL3J5LLk2AX8
17
17
  yirgacheffe/layers/rasters.py,sha256=8mAbH49RtKIoA3h9mxWNbPzo8NJWDSfoRPT7fpkTJ4I,12328
18
18
  yirgacheffe/layers/rescaled.py,sha256=kWJlu7DuUB3nRDt3VtbJKiqBDQb2Ba8xzIIXTvOGdK8,2945
19
19
  yirgacheffe/layers/vectors.py,sha256=JOqM7Ym53ZdxWKpBJac-opPp2N_ynMfet1Xtsi85dpM,15087
20
- yirgacheffe-1.3.2.dist-info/licenses/LICENSE,sha256=dNSHwUCJr6axStTKDEdnJtfmDdFqlE3h1NPCveqPfnY,757
21
- yirgacheffe-1.3.2.dist-info/METADATA,sha256=Nb9n3FKLxFJXTZZqrdWZAdfYbCogEMxWrrEEw96zE3M,20473
22
- yirgacheffe-1.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- yirgacheffe-1.3.2.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
24
- yirgacheffe-1.3.2.dist-info/top_level.txt,sha256=9DBFlKO2Ld3hG6TuE3qOTd3Tt8ugTiXil4AN4Wr9_y0,12
25
- yirgacheffe-1.3.2.dist-info/RECORD,,
20
+ yirgacheffe-1.3.4.dist-info/licenses/LICENSE,sha256=dNSHwUCJr6axStTKDEdnJtfmDdFqlE3h1NPCveqPfnY,757
21
+ yirgacheffe-1.3.4.dist-info/METADATA,sha256=tKSbYq3ZonA4FTn9AeYFgAB9AcZOnMBdky7oZ_Vcz60,20496
22
+ yirgacheffe-1.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ yirgacheffe-1.3.4.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
24
+ yirgacheffe-1.3.4.dist-info/top_level.txt,sha256=9DBFlKO2Ld3hG6TuE3qOTd3Tt8ugTiXil4AN4Wr9_y0,12
25
+ yirgacheffe-1.3.4.dist-info/RECORD,,