terrakio-core 0.4.98.1b6__py3-none-any.whl → 0.4.98.1b8__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.
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import os
3
3
  import time
4
- from typing import Dict, Any, Optional, List
4
+ from typing import Dict, Any, Optional, List, Union
5
5
 
6
6
  import aiohttp
7
7
  import typer
@@ -985,4 +985,146 @@ class MassStats:
985
985
  'collection': collection,
986
986
  'downloaded_files': downloaded_files,
987
987
  'total': len(downloaded_files)
988
- }
988
+ }
989
+
990
+ @require_api_key
991
+ async def gen_and_process(
992
+ self,
993
+ collection: str,
994
+ requests_file: Union[str, Any],
995
+ output: str,
996
+ folder: str,
997
+ consumer: Union[str, Any],
998
+ extra: Optional[Dict[str, Any]] = None,
999
+ force_loc: Optional[bool] = False,
1000
+ skip_existing: Optional[bool] = True,
1001
+ server: Optional[str] = None
1002
+ ) -> Dict[str, Any]:
1003
+ """
1004
+ Generate data and run post-processing in a single task.
1005
+
1006
+ Args:
1007
+ collection: Name of collection
1008
+ requests_file: Path to JSON file or file object containing request configurations
1009
+ output: Output type (str)
1010
+ folder: Folder to store output
1011
+ consumer: Path to post processing script or file object
1012
+ extra: Additional configuration parameters (optional)
1013
+ force_loc: Write data directly to the cloud under this folder (optional, defaults to False)
1014
+ skip_existing: Skip existing data (optional, defaults to True)
1015
+ server: Server to use (optional)
1016
+
1017
+ Returns:
1018
+ API response as a dictionary containing task information
1019
+
1020
+ Raises:
1021
+ CollectionNotFoundError: If the collection is not found
1022
+ GetTaskError: If the API request fails due to unknown reasons
1023
+ """
1024
+ await self.create_collection(collection=collection)
1025
+
1026
+ upload_urls = await self._upload_requests(collection=collection)
1027
+ url = upload_urls['url']
1028
+
1029
+ # Handle requests_file - either file path (str) or file object
1030
+ if isinstance(requests_file, str):
1031
+ await self._upload_file(requests_file, url)
1032
+ else:
1033
+ # File object - read JSON and upload directly
1034
+ json_data = json.load(requests_file)
1035
+ await self._upload_json_data(json_data, url)
1036
+
1037
+ # Handle consumer - either file path (str) or file object
1038
+ if isinstance(consumer, str):
1039
+ with open(consumer, 'rb') as f:
1040
+ consumer_content = f.read()
1041
+ else:
1042
+ # Assume it's a file object
1043
+ consumer_content = consumer.read()
1044
+
1045
+ form = aiohttp.FormData()
1046
+ form.add_field('output', output)
1047
+ form.add_field('force_loc', str(force_loc).lower())
1048
+ form.add_field('skip_existing', str(skip_existing).lower())
1049
+
1050
+ if server is not None:
1051
+ form.add_field('server', server)
1052
+
1053
+ form.add_field('extra', json.dumps(extra or {}))
1054
+ form.add_field('folder', folder)
1055
+ form.add_field(
1056
+ 'consumer',
1057
+ consumer_content,
1058
+ filename='consumer.py',
1059
+ content_type='text/x-python'
1060
+ )
1061
+
1062
+ response, status = await self._client._terrakio_request(
1063
+ "POST",
1064
+ f"collections/{collection}/gen_and_process",
1065
+ data=form
1066
+ )
1067
+
1068
+ if status != 200:
1069
+ if status == 404:
1070
+ raise CollectionNotFoundError(f"Collection {collection} not found", status_code=status)
1071
+ raise GetTaskError(f"Gen and process failed with status {status}", status_code=status)
1072
+
1073
+ return response
1074
+
1075
+ @require_api_key
1076
+ async def create_pyramids(
1077
+ self,
1078
+ name: str,
1079
+ levels: int,
1080
+ config: Dict[str, Any]
1081
+ ) -> Dict[str, Any]:
1082
+ """
1083
+ Create pyramid tiles for a dataset.
1084
+
1085
+ Args:
1086
+ name: Dataset name
1087
+ levels: Maximum zoom level for pyramid (e.g., 8)
1088
+ config: Full pyramid configuration dictionary containing:
1089
+ - name: Dataset name (will override the name parameter)
1090
+ - bucket: GCS bucket name (e.g., "terrakio")
1091
+ - products: List of product names (e.g., ["air_temp", "prec"])
1092
+ - path: Path pattern (e.g., "pyramids/%s_%s_%03d_%03d_%02d.snp")
1093
+ - data_type: Data type (e.g., "float32")
1094
+ - i_max: Maximum i index
1095
+ - j_max: Maximum j index
1096
+ - x_size: Tile size in x (e.g., 400)
1097
+ - y_size: Tile size in y (e.g., 400)
1098
+ - dates_iso8601: List of ISO8601 date strings
1099
+ - no_data: No data value (e.g., -9999.0)
1100
+
1101
+ Returns:
1102
+ API response with task_id
1103
+
1104
+ Raises:
1105
+ GetTaskError: If the API request fails
1106
+ """
1107
+ await self.create_collection(collection = name)
1108
+
1109
+ pyramid_request = {
1110
+ 'name': name,
1111
+ 'max_zoom': levels,
1112
+ **config
1113
+ }
1114
+
1115
+ response, status = await self._client._terrakio_request(
1116
+ "POST",
1117
+ "tasks/pyramids",
1118
+ json=pyramid_request
1119
+ )
1120
+
1121
+ if status != 200:
1122
+ raise GetTaskError(
1123
+ f"Pyramid creation failed with status {status}: {response}",
1124
+ status_code=status
1125
+ )
1126
+
1127
+ task_id = response["task_id"]
1128
+ await self.track_progress(task_id)
1129
+
1130
+ return {"task_id": task_id}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: terrakio-core
3
- Version: 0.4.98.1b6
3
+ Version: 0.4.98.1b8
4
4
  Summary: Core package for the terrakio-python-api
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: aiofiles>=24.1.0
@@ -11,13 +11,13 @@ terrakio_core/convenience_functions/zonal_stats.py,sha256=7PI--RI0hiF1pzZ7_7hqty
11
11
  terrakio_core/endpoints/auth.py,sha256=5WvAO39aLsbJAVtxISwiOZseKr3B9I5tHjamPRehDBQ,8327
12
12
  terrakio_core/endpoints/dataset_management.py,sha256=jpwftiKOI59NhXXypqm6wtILIkfyjy9NfYifRIvhZS0,16791
13
13
  terrakio_core/endpoints/group_management.py,sha256=V0KOGTXwmePBFeym55G_m3ONR-jVj2IU4OVLiL5UKz4,15869
14
- terrakio_core/endpoints/mass_stats.py,sha256=Bvke7gmZpNCsbEDyskqV7ZlkztkoBWxxFUPP0DCXz7Y,36970
14
+ terrakio_core/endpoints/mass_stats.py,sha256=6RFKR2qjz8uawA1Hb10yIX6bbr-D5dnhSN6uW8Ak8gI,42032
15
15
  terrakio_core/endpoints/model_management.py,sha256=tvJ4BOBsyXKKH430byGH25CkLIzXWgxaPaL0CvL8_0Y,51341
16
16
  terrakio_core/endpoints/space_management.py,sha256=YWb55nkJnFJGlALJ520DvurxDqVqwYtsvqQPWzxzhDs,2266
17
17
  terrakio_core/endpoints/user_management.py,sha256=L_g4ysrh2xyz_JbObUU_tCxgHxisrDUPntWgQOs15GE,7709
18
18
  terrakio_core/helper/bounded_taskgroup.py,sha256=wiTH10jhKZgrsgrFUNG6gig8bFkUEPHkGRT2XY7Rgmo,677
19
19
  terrakio_core/helper/decorators.py,sha256=L6om7wmWNgCei3Wy5U0aZ-70OzsCwclkjIf7SfQuhCg,2289
20
20
  terrakio_core/helper/tiles.py,sha256=lcLCO6KiP05lCI9vngo3zCZJ6Z9C0pUxHSQS4H58EHc,2699
21
- terrakio_core-0.4.98.1b6.dist-info/METADATA,sha256=zlli64p2DlufJj4q_xoIYbyuDPra2thNi5r2CtovLJA,1184
22
- terrakio_core-0.4.98.1b6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- terrakio_core-0.4.98.1b6.dist-info/RECORD,,
21
+ terrakio_core-0.4.98.1b8.dist-info/METADATA,sha256=Akksg8XAe3QgpcEBKsMCAK2wLw10Q3ds7XNWq3lWIEY,1184
22
+ terrakio_core-0.4.98.1b8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ terrakio_core-0.4.98.1b8.dist-info/RECORD,,