atlasai-dstoolkit-client 0.0.15__py3-none-any.whl → 0.0.17__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.
@@ -11,3 +11,10 @@ DISABLE_SSL_VERIFICATION = 'DISABLE_SSL_VERIFICATION'
11
11
 
12
12
  TOKEN_ENV_VAR = 'VINZ_ENCRYPTED_TOKEN'
13
13
  TOKEN_TIMESTAMP_ENV_VAR = 'VINZ_ENCRYPTED_TOKEN_TIMESTAMP'
14
+
15
+ LEAFMAP_COLORMAP = [
16
+ "viridis", "plasma", "inferno", "magma", "cividis",
17
+ "Greys", "Purples", "Blues", "Greens", "Oranges", "Reds",
18
+ "YlOrBr", "YlOrRd", "OrRd", "PuRd", "RdPu", "BuPu", "GnBu", "PuBu",
19
+ "YlGnBu", "PuBuGn", "BuGn", "YlGn"
20
+ ]
@@ -12,19 +12,20 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import ast
15
+ from concurrent.futures import ThreadPoolExecutor, as_completed
16
+ from dataclasses import dataclass
17
+ from datetime import datetime
15
18
  import logging
16
19
  import os
20
+ import random
17
21
  import time
18
22
 
23
+ import leafmap
19
24
  import pandas as pd
20
- from tqdm import tqdm
21
-
22
- from concurrent.futures import ThreadPoolExecutor, as_completed
23
- from dataclasses import dataclass
24
-
25
25
  import requests
26
+ from tqdm import tqdm
26
27
 
27
- from . import api, output as o
28
+ from . import api, constants, output as o
28
29
 
29
30
  logger = logging.getLogger('atlasai.toolkit')
30
31
 
@@ -46,6 +47,7 @@ class Workflow:
46
47
  def __init__(self, id=None):
47
48
  # Allow the selection of an existing workflow and check the logs.
48
49
  self.id = id
50
+ self._run_results = []
49
51
 
50
52
  @property
51
53
  def status(self):
@@ -67,6 +69,9 @@ class Workflow:
67
69
  def _results(self, *args, **kwargs):
68
70
  raise NotImplementedError
69
71
 
72
+ def preview(self, *args, **kwargs):
73
+ raise NotImplementedError
74
+
70
75
  def get(self):
71
76
  if not self.id:
72
77
  raise Exception('No valid execution of the workflow. Please use the `run` method first.')
@@ -186,7 +191,10 @@ class Electrification(Workflow):
186
191
  if not self.aoi_path and not self.aoi:
187
192
  raise Exception('`aoi_path` or `aoi` must be specified.')
188
193
 
189
- def _results(self, save_to=None):
194
+ def _results(self, save_to=None, force=False):
195
+ if self._run_results and not force:
196
+ return self._run_results
197
+
190
198
  results = []
191
199
  if not self.id:
192
200
  raise Exception('No valid execution of the workflow. Please use the `run` method first.')
@@ -203,7 +211,7 @@ class Electrification(Workflow):
203
211
  for fut in as_completed(fut_map):
204
212
  results.append(fut.result())
205
213
  pbar.update(1)
206
-
214
+ self._run_results = results
207
215
  return results
208
216
 
209
217
  def _download_file(self, name, url, to=None):
@@ -224,6 +232,58 @@ class Electrification(Workflow):
224
232
 
225
233
  return local_path
226
234
 
235
+ def preview(self, from_=None, to_=None, selection=None, limit=None):
236
+ if not self._run_results:
237
+ raise Exception('No result to be displayed. Run the workflow first and wait for its completion.')
238
+
239
+ _results = []
240
+ if selection is None:
241
+ selection = []
242
+ if selection:
243
+ selection = ['-'.join(s.split('-')[:2]) for s in selection]
244
+ from_, to_, limit = None, None, None
245
+
246
+ if from_:
247
+ from_ = datetime.strptime(from_, "%Y-%m-%d")
248
+ if to_:
249
+ to_ = datetime.strptime(to_, "%Y-%m-%d")
250
+
251
+ for f in sorted(self._run_results):
252
+ yyyy, mm = f.split('_')[-1].replace('.tif', '').split('-')
253
+ dt = datetime(year=int(yyyy), month=int(mm), day=1)
254
+ if selection:
255
+ if f'{yyyy}-{mm}' not in selection:
256
+ continue
257
+ if from_ and from_ > dt:
258
+ continue
259
+ if to_ and to_ < dt:
260
+ continue
261
+ if limit and len(_results) >= limit:
262
+ continue
263
+ _results.append(dict(
264
+ layer_name=f'{yyyy}-{mm}',
265
+ file=f,
266
+ colormap=constants.LEAFMAP_COLORMAP[random.randint(0, len(constants.LEAFMAP_COLORMAP) - 1)]
267
+ ))
268
+ if not _results:
269
+ raise Exception('No result matches your criteria.')
270
+ m = leafmap.Map()
271
+ if len(_results) > 10:
272
+ logger.warning(f'Too many layers to display. Expect increased loading time. Layers to display: {len(_results)}')
273
+
274
+ for idx, f in enumerate(_results):
275
+ m.add_raster(
276
+ f['file'],
277
+ layer_name=f['layer_name'],
278
+ nodata=0,
279
+ colormap=f['colormap'],
280
+ opacity=0.5,
281
+ )
282
+ if hasattr(m, "add_layers_control"):
283
+ m.add_layers_control()
284
+ elif hasattr(m, "add_layer_control"):
285
+ m.add_layer_control()
286
+ return m
227
287
 
228
288
  def List(search=None, offset=0, limit=100):
229
289
  pd.set_option("display.max_colwidth", None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atlasai-dstoolkit-client
3
- Version: 0.0.15
3
+ Version: 0.0.17
4
4
  Summary: UNKNOWN
5
5
  Home-page: UNKNOWN
6
6
  Author: AtlasAI SWE
@@ -13,6 +13,8 @@ Requires-Dist: arrow (<2.0.0,>=1.3.0)
13
13
  Requires-Dist: atlasai-mlhub-client
14
14
  Requires-Dist: furl (<3.0.0,>=2.1.2)
15
15
  Requires-Dist: geopandas (~=1.1.1)
16
+ Requires-Dist: leafmap (~=0.52.0)
17
+ Requires-Dist: localtileserver (~=0.10.6)
16
18
  Requires-Dist: pandas (<3.0.0,>=2.2.3)
17
19
  Requires-Dist: pyarrow (>=19.0.1)
18
20
  Requires-Dist: python-dotenv (<2.0.0,>=1.0.1)
@@ -1,6 +1,6 @@
1
1
  atlasai/toolkit/__init__.py,sha256=0d2EYTgFf-RH2z1M83gGfZdrt_PBXbJk6o5ZVAKCPtA,1013
2
2
  atlasai/toolkit/api.py,sha256=BvO-gLRmbmkKduwbbADjcLlIkS9blzfM_cbMR4DhQmU,5269
3
- atlasai/toolkit/constants.py,sha256=Jxozn9tKOvAxyOYOZ6bzFtI9m1YETJF1GURzTl9NNC8,422
3
+ atlasai/toolkit/constants.py,sha256=fCVI3Q6g28uCQJsY10BUsb301TO9_W0OqWdd9QwZrfg,675
4
4
  atlasai/toolkit/dataset.py,sha256=fhzhxF9YMzIwEpaJZEPOK2SuLMJhVGI75eahxnH_T2c,3254
5
5
  atlasai/toolkit/fabric.py,sha256=6aFR2PGQc9P3Qa07WdBg9eKoUzU8n2y_-gGjYcyMrWY,1921
6
6
  atlasai/toolkit/feature.py,sha256=Q5M9zOGafynYuKaELL1kZemYPfKAZh84TgH7jw9J3ZU,2949
@@ -10,9 +10,9 @@ atlasai/toolkit/model.py,sha256=RUe0HbDpzvHOV9A4rzG3PgN9boMWDHQ2tR7IKHXzbx8,4126
10
10
  atlasai/toolkit/output.py,sha256=FyDjrpVlbrEyfHfwOpxp8H57jx_qXahDjO1qpHIeuYM,473
11
11
  atlasai/toolkit/requests.py,sha256=X86nIo07hAjUlilZcZ1lV8RB7KOsTKbTGtcY_SpFEXY,1223
12
12
  atlasai/toolkit/utils.py,sha256=lYh3P2XOshRgHCjFeXJ0FOJWQW64sddgx8c2kL6Wqwc,1566
13
- atlasai/toolkit/workflows.py,sha256=9NTqPZqoT46tdjMuFApYsGUpbNNDP_Gp2gYMXgVLo_s,7158
14
- atlasai_dstoolkit_client-0.0.15.dist-info/LICENSE.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
15
- atlasai_dstoolkit_client-0.0.15.dist-info/METADATA,sha256=Ada-4ks6hKHOq1GmPEJJKnO9TlATP2XVRyAat70spbo,1471
16
- atlasai_dstoolkit_client-0.0.15.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
17
- atlasai_dstoolkit_client-0.0.15.dist-info/top_level.txt,sha256=HRTbErU8nmHFDaJJ5R_XYbwpt21dqdjDpSva8xyy_0k,8
18
- atlasai_dstoolkit_client-0.0.15.dist-info/RECORD,,
13
+ atlasai/toolkit/workflows.py,sha256=j91nsVTLzv689EE-aBOZyuOV0a7xlZh4DEkgWIzBFiU,9450
14
+ atlasai_dstoolkit_client-0.0.17.dist-info/LICENSE.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
15
+ atlasai_dstoolkit_client-0.0.17.dist-info/METADATA,sha256=hiDgJIBsJ4WO47gGKD0FdUM-oekVgXZn704V7W08lds,1547
16
+ atlasai_dstoolkit_client-0.0.17.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
17
+ atlasai_dstoolkit_client-0.0.17.dist-info/top_level.txt,sha256=HRTbErU8nmHFDaJJ5R_XYbwpt21dqdjDpSva8xyy_0k,8
18
+ atlasai_dstoolkit_client-0.0.17.dist-info/RECORD,,