Skip to content

Commit

Permalink
Configure the filename for saving the item (#129)
Browse files Browse the repository at this point in the history
* Configure the filename for saving the item
  • Loading branch information
drnextgis authored May 23, 2024
1 parent 7ee8533 commit 96a0298
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- download_item_assets and download_items_assets methods now accept a parameter `file_name` for configuring the filename to save the STAC Item as. If unset, it defaults to `item.json` and if set to `None` the filename is inferred from the ID.

## [0.5.0] - 2024-05-08

## Deprecated
### Deprecated

- Support for Python 3.8 has been removed.
- CLI flags `--skip-upload` and `--skip-validation` deprecated in favor of `--upload/--no-upload` and `--validate/no-validate`
- Task constructor arguments `skip_upload` and `skip_validation` deprecated in favor of `upload` and `validate`

## Fixed
### Fixed

- Several CLI arguments were missing `help` descriptions

## Changed
### Changed

- Replaced the use of fsspec with stac-asset for downloading Item Assets
- `--local` flag no longer turns off validation
Expand All @@ -30,7 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Collection assignment now assigns the first matching collection expression, rather
than the last.

## Added
### Added

- Property `collection_mapping` to `Task` class to retrieve the collection mappings
from upload_options
Expand Down
5 changes: 4 additions & 1 deletion stactask/asset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ async def download_item_assets(
path_template: str = "${collection}/${id}",
config: Optional[DownloadConfig] = None,
keep_non_downloaded: bool = True,
file_name: Optional[str] = "item.json",
) -> Item:
return await stac_asset.download_item(
item=item.clone(),
directory=LayoutTemplate(path_template).substitute(item),
file_name="item.json",
file_name=file_name,
config=config,
keep_non_downloaded=keep_non_downloaded,
)
Expand All @@ -36,6 +37,7 @@ async def download_items_assets(
path_template: str = "${collection}/${id}",
config: Optional[DownloadConfig] = None,
keep_non_downloaded: bool = True,
file_name: Optional[str] = "item.json",
) -> list[Item]:
return await asyncio.gather(
*[
Expand All @@ -45,6 +47,7 @@ async def download_items_assets(
path_template=path_template,
config=config,
keep_non_downloaded=keep_non_downloaded,
file_name=file_name,
)
)
for item in items
Expand Down
6 changes: 6 additions & 0 deletions stactask/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def download_item_assets(
path_template: str = "${collection}/${id}",
config: Optional[DownloadConfig] = None,
keep_non_downloaded: bool = True,
file_name: Optional[str] = "item.json",
) -> Item:
"""Download provided asset keys for the given item. Assets are
saved in workdir in a directory (as specified by path_template), and
Expand All @@ -256,13 +257,15 @@ def download_item_assets(
where to store downloaded files.
keep_original_filenames (Optional[bool]): Controls whether original
file names should be used, or asset key + extension.
file_name (Optional[str]): The name of the item file to save.
"""
return asyncio.get_event_loop().run_until_complete(
download_item_assets(
item,
path_template=str(self._workdir / path_template),
config=config,
keep_non_downloaded=keep_non_downloaded,
file_name=file_name,
)
)

Expand All @@ -272,6 +275,7 @@ def download_items_assets(
path_template: str = "${collection}/${id}",
config: Optional[DownloadConfig] = None,
keep_non_downloaded: bool = True,
file_name: Optional[str] = "item.json",
) -> list[Item]:
"""Download provided asset keys for the given items. Assets are
saved in workdir in a directory (as specified by path_template), and
Expand All @@ -286,6 +290,7 @@ def download_items_assets(
where to store downloaded files.
keep_original_filenames (Optional[bool]): Controls whether original
file names should be used, or asset key + extension.
file_name (Optional[str]): The name of the item file to save.
"""
return list(
asyncio.get_event_loop().run_until_complete(
Expand All @@ -294,6 +299,7 @@ def download_items_assets(
path_template=str(self._workdir / path_template),
config=config,
keep_non_downloaded=keep_non_downloaded,
file_name=file_name,
)
)
)
Expand Down

0 comments on commit 96a0298

Please sign in to comment.