yirgacheffe 1.3.0__py3-none-any.whl → 1.3.2__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/constants.py CHANGED
@@ -1 +1,2 @@
1
1
  YSTEP = 512
2
+ MINIMUM_CHUNKS_PER_THREAD = 1
yirgacheffe/operators.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import math
2
3
  import multiprocessing
3
4
  import sys
4
5
  import time
@@ -529,7 +530,7 @@ class LayerOperation(LayerMathMixin):
529
530
 
530
531
  return total if and_sum else None
531
532
 
532
- def _parallel_worker(self, index, shared_mem, sem, np_dtype, width, input_queue, output_queue):
533
+ def _parallel_worker(self, index, shared_mem, sem, np_dtype, width, input_queue, output_queue, computation_window):
533
534
  arr = np.ndarray((self.ystep, width), dtype=np_dtype, buffer=shared_mem.buf)
534
535
 
535
536
  try:
@@ -549,7 +550,7 @@ class LayerOperation(LayerMathMixin):
549
550
  break
550
551
  yoffset, step = task
551
552
 
552
- result = self._eval(self.area, yoffset, step)
553
+ result = self._eval(self.area, yoffset, step, computation_window)
553
554
  backend.eval_op(result)
554
555
 
555
556
  arr[:step] = backend.demote_array(result)
@@ -578,6 +579,20 @@ class LayerOperation(LayerMathMixin):
578
579
  def _parallel_save(self, destination_layer, and_sum=False, callback=None, parallelism=None, band=1):
579
580
  assert (destination_layer is not None) or and_sum
580
581
  computation_window = self.window
582
+
583
+ worker_count = parallelism or multiprocessing.cpu_count()
584
+ work_blocks = len(range(0, computation_window.ysize, self.ystep))
585
+ adjusted_blocks = math.ceil(work_blocks / constants.MINIMUM_CHUNKS_PER_THREAD)
586
+ worker_count = min(adjusted_blocks, worker_count)
587
+
588
+ if worker_count == 1:
589
+ if destination_layer:
590
+ return self.save(destination_layer, and_sum, callback, band)
591
+ elif and_sum:
592
+ return self.sum()
593
+ else:
594
+ assert False
595
+
581
596
  if destination_layer is not None:
582
597
  try:
583
598
  band = destination_layer._dataset.GetRasterBand(band)
@@ -615,10 +630,6 @@ class LayerOperation(LayerMathMixin):
615
630
  with multiprocessing.Manager() as manager:
616
631
  with SharedMemoryManager() as smm:
617
632
 
618
- worker_count = parallelism or multiprocessing.cpu_count()
619
- work_blocks = len(range(0, computation_window.ysize, self.ystep))
620
- worker_count = min(work_blocks, worker_count)
621
-
622
633
  mem_sem_cast = []
623
634
  for i in range(worker_count):
624
635
  shared_buf = smm.SharedMemory(size=np_dtype.itemsize * self.ystep * computation_window.xsize)
@@ -650,7 +661,8 @@ class LayerOperation(LayerMathMixin):
650
661
  np_dtype,
651
662
  computation_window.xsize,
652
663
  source_queue,
653
- result_queue
664
+ result_queue,
665
+ computation_window
654
666
  )) for i in range(worker_count)]
655
667
  for worker in workers:
656
668
  worker.start()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yirgacheffe
3
- Version: 1.3.0
3
+ Version: 1.3.2
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,7 +1,7 @@
1
1
  yirgacheffe/__init__.py,sha256=U5AoPk_iWreSCexG2ID-tmSXiJz4_9Lvzbf42DMvT7k,658
2
- yirgacheffe/constants.py,sha256=9ZcFLcir4GhPBBDG2rzLhDtJ0pMzpZYuzE9f-CFeA44,12
2
+ yirgacheffe/constants.py,sha256=WccPcISG1FqL_Kw1tI72BJGjHy6RvEcGEx_I9RK776U,42
3
3
  yirgacheffe/h3layer.py,sha256=MT2hm6n64hzHSeRPvjn-CwErru937ntKXbEU7CIlPSU,91
4
- yirgacheffe/operators.py,sha256=dOzScup0rYKU2GbY3j5zFJJ0JMQomq6hN0c1nH1_igs,27198
4
+ yirgacheffe/operators.py,sha256=f72xFsH6KmmWhrbsU0V7g_jgTJQ4BAaZzDhV7i-wPio,27607
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
@@ -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.0.dist-info/licenses/LICENSE,sha256=dNSHwUCJr6axStTKDEdnJtfmDdFqlE3h1NPCveqPfnY,757
21
- yirgacheffe-1.3.0.dist-info/METADATA,sha256=jt79WCW-SqvTFkzqnHQC6VQoK0rJwo6R3uMePZD4CMc,20473
22
- yirgacheffe-1.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- yirgacheffe-1.3.0.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
24
- yirgacheffe-1.3.0.dist-info/top_level.txt,sha256=9DBFlKO2Ld3hG6TuE3qOTd3Tt8ugTiXil4AN4Wr9_y0,12
25
- yirgacheffe-1.3.0.dist-info/RECORD,,
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,,