Skip to content

Commit 271ed6c

Browse files
committed
Add output directory argument for write_results_to_file function
1 parent eee18c3 commit 271ed6c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

geospatial_tools/planetary_computer/sentinel_2.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ def select_best_products_per_feature(self) -> GeoDataFrame:
193193
self.vector_features_with_products = spatial_join_results
194194
return self.vector_features_with_products
195195

196-
def to_file(self):
196+
def to_file(self, output_dir: Union[str, pathlib.Path]) -> None:
197197
write_results_to_file(
198198
cloud_cover=self.max_cloud_cover,
199199
successful_results=self.successful_results,
200200
incomplete_results=self.incomplete_results,
201201
error_results=self.error_results,
202+
output_dir=output_dir,
202203
)
203204

204205

@@ -322,25 +323,26 @@ def write_results_to_file(
322323
successful_results: dict,
323324
incomplete_results: Optional[list] = None,
324325
error_results: Optional[list] = None,
326+
output_dir: Union[str, pathlib.Path] = DATA_DIR,
325327
logger: logging.Logger = LOGGER,
326328
) -> dict:
327-
tile_filename = DATA_DIR / f"data_lt{cloud_cover}cc.json"
329+
tile_filename = output_dir / f"data_lt{cloud_cover}cc.json"
328330
with open(tile_filename, "w", encoding="utf-8") as json_file:
329331
json.dump(successful_results, json_file, indent=4)
330332
logger.info(f"Results have been written to {tile_filename}")
331333

332334
incomplete_filename = "None"
333335
if incomplete_results:
334336
incomplete_dict = {"incomplete": incomplete_results}
335-
incomplete_filename = DATA_DIR / f"incomplete_lt{cloud_cover}cc.json"
337+
incomplete_filename = output_dir / f"incomplete_lt{cloud_cover}cc.json"
336338
with open(incomplete_filename, "w", encoding="utf-8") as json_file:
337339
json.dump(incomplete_dict, json_file, indent=4)
338340
logger.info(f"Incomplete results have been written to {incomplete_filename}")
339341

340342
error_filename = "None"
341343
if error_results:
342344
error_dict = {"errors": error_results}
343-
error_filename = DATA_DIR / f"errors_lt{cloud_cover}cc.json"
345+
error_filename = output_dir / f"errors_lt{cloud_cover}cc.json"
344346
with open(error_filename, "w", encoding="utf-8") as json_file:
345347
json.dump(error_dict, json_file, indent=4)
346348
logger.info(f"Errors results have been written to {error_filename}")

scripts/sentinel_2_search_and_process/product_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def product_search(
171171

172172
best_products_client.create_date_ranges(START_YEAR, END_YEAR, START_MONTH, END_MONTH)
173173
best_products_client.find_best_complete_products()
174-
best_products_client.to_file()
174+
best_products_client.to_file(output_dir=S2_SCRIPT_DIR)
175175

176176
# Selecting the best products for each vector tile
177177
#

0 commit comments

Comments
 (0)