distancerasters 0.3.2__tar.gz → 0.3.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: distancerasters
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Generate distance raster using arbitrary sets of spatial features
5
5
  Home-page: https://github.com/sgoodm/python-distance-rasters
6
6
  Author: Seth Goodman
@@ -11,6 +11,13 @@ Keywords: raster,distance,spatial
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.txt
14
+ Requires-Dist: numpy
15
+ Requires-Dist: rasterio
16
+ Requires-Dist: fiona
17
+ Requires-Dist: affine
18
+ Requires-Dist: scipy>=1.6.0
19
+ Requires-Dist: rasterstats
20
+ Requires-Dist: tqdm
14
21
 
15
22
  # distance-rasters
16
23
 
@@ -135,7 +142,7 @@ You can run tests and coverage checks locally, or you can fork the repository an
135
142
 
136
143
  To run tests and coverage checks locally, you can use the following commands:
137
144
  ```sh
138
- pip install pytest coverage shapely geopandas
145
+ pip install pytest coverage
139
146
  coverage run -m pytest ./
140
147
  coverage html
141
148
  ```
@@ -121,7 +121,7 @@ You can run tests and coverage checks locally, or you can fork the repository an
121
121
 
122
122
  To run tests and coverage checks locally, you can use the following commands:
123
123
  ```sh
124
- pip install pytest coverage shapely geopandas
124
+ pip install pytest coverage
125
125
  coverage run -m pytest ./
126
126
  coverage html
127
127
  ```
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = distancerasters
3
- version = 0.3.2
3
+ version = 0.3.3
4
4
  description = Generate distance raster using arbitrary sets of spatial features
5
5
  long_description = file:README.md
6
6
  long_description_content_type = text/markdown
@@ -25,6 +25,7 @@ install_requires =
25
25
  affine
26
26
  scipy>=1.6.0
27
27
  rasterstats
28
+ tqdm
28
29
 
29
30
  [options.packages.find]
30
31
  where = src
@@ -1,13 +1,18 @@
1
1
  import time
2
+ from itertools import product
3
+
2
4
  import numpy as np
3
5
  from affine import Affine
4
6
  from scipy.spatial import KDTree
5
- from .utils import export_raster, convert_index_to_coords, calc_haversine_distance
7
+ from tqdm import tqdm
8
+
9
+ from .utils import (calc_haversine_distance, convert_index_to_coords,
10
+ export_raster)
6
11
 
7
12
 
8
13
  class DistanceRaster(object):
9
14
 
10
- def __init__(self, raster_array, affine=None, conditional=None, output_path=None):
15
+ def __init__(self, raster_array, affine=None, conditional=None, output_path=None, progress_bar=False):
11
16
  """build distance array from raster array
12
17
 
13
18
  Args
@@ -46,6 +51,7 @@ class DistanceRaster(object):
46
51
  self.raster_array = raster_array
47
52
  self.pixel_size = pixel_size
48
53
  self.affine = affine
54
+ self.progress_bar = progress_bar
49
55
 
50
56
  self.tree = None
51
57
  self.dist_array = None
@@ -77,34 +83,33 @@ class DistanceRaster(object):
77
83
 
78
84
  t_start = time.time()
79
85
 
80
- for r in range(nrows):
81
-
82
- for c in range(ncols):
86
+ row_col_iterable = product(range(nrows), range(ncols))
83
87
 
84
- cur_index = (r, c)
85
- min_dist, min_index = self.tree.query([cur_index])
86
- min_dist = min_dist[0]
87
- min_index = self.tree.data[min_index[0]]
88
+ for r, c in tqdm(row_col_iterable, total=nrows*ncols, disable=(not self.progress_bar)):
89
+ cur_index = (r, c)
90
+ min_dist, min_index = self.tree.query([cur_index])
91
+ min_dist = min_dist[0]
92
+ min_index = self.tree.data[min_index[0]]
88
93
 
89
- if self.affine is not None:
90
- if cur_index[1] == min_index[1]:
91
- # columns are same meaning nearest is either vertical or self.
92
- # no correction needed, just convert to km
93
- dd_min_dist = min_dist * self.pixel_size
94
- km_min_dist = dd_min_dist * 111.321
94
+ if self.affine is not None:
95
+ if cur_index[1] == min_index[1]:
96
+ # columns are same meaning nearest is either vertical or self.
97
+ # no correction needed, just convert to km
98
+ dd_min_dist = min_dist * self.pixel_size
99
+ km_min_dist = dd_min_dist * 111.321
95
100
 
96
- else:
97
- km_min_dist = calc_haversine_distance(
98
- convert_index_to_coords(cur_index, self.affine),
99
- convert_index_to_coords(min_index, self.affine),
100
- )
101
+ else:
102
+ km_min_dist = calc_haversine_distance(
103
+ convert_index_to_coords(cur_index, self.affine),
104
+ convert_index_to_coords(min_index, self.affine),
105
+ )
101
106
 
102
- val = km_min_dist * 1000
107
+ val = km_min_dist * 1000
103
108
 
104
- else:
105
- val = min_dist
109
+ else:
110
+ val = min_dist
106
111
 
107
- self.dist_array[r][c] = val
112
+ self.dist_array[r][c] = val
108
113
 
109
114
  print("Distance calc run time: {0} seconds".format(round(time.time() - t_start, 4)))
110
115
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: distancerasters
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Generate distance raster using arbitrary sets of spatial features
5
5
  Home-page: https://github.com/sgoodm/python-distance-rasters
6
6
  Author: Seth Goodman
@@ -11,6 +11,13 @@ Keywords: raster,distance,spatial
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.txt
14
+ Requires-Dist: numpy
15
+ Requires-Dist: rasterio
16
+ Requires-Dist: fiona
17
+ Requires-Dist: affine
18
+ Requires-Dist: scipy>=1.6.0
19
+ Requires-Dist: rasterstats
20
+ Requires-Dist: tqdm
14
21
 
15
22
  # distance-rasters
16
23
 
@@ -135,7 +142,7 @@ You can run tests and coverage checks locally, or you can fork the repository an
135
142
 
136
143
  To run tests and coverage checks locally, you can use the following commands:
137
144
  ```sh
138
- pip install pytest coverage shapely geopandas
145
+ pip install pytest coverage
139
146
  coverage run -m pytest ./
140
147
  coverage html
141
148
  ```
@@ -4,3 +4,4 @@ fiona
4
4
  affine
5
5
  scipy>=1.6.0
6
6
  rasterstats
7
+ tqdm