Skip to content

COG ingest filename time #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 24 additions & 41 deletions auxiliary/stac/create-stac-items/create-stac-items.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def parse_args():
parser.add_argument('-rp', '--path_replace_with', help='If --path_remove, instead of setting that portion of the internal path to "", replaces it with this value.')
parser.add_argument('-u', '--upsert', help='Allow overwriting existing STAC items', action='store_true')
parser.add_argument('-r', '--regex', help='If folder, only create stac items for files that match this regex')
parser.add_argument('-d', '--dev', help='dev mode that does other things', action='store_true')
parser.add_argument('-t', '--time_from_fn', help='time format to read from filename', type=str, default=None)

args = parser.parse_args()
return args

def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path, path_remove, path_replace_with, upsert=False, regex=None, dev=False):
def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path, path_remove, path_replace_with, upsert=False, regex=None, time_from_fn=False):

isDir = os.path.isdir(file_or_folder_path)

Expand Down Expand Up @@ -59,44 +59,27 @@ def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path
else:
asset_href = file.replace(path_remove, "")

if dev:
item = create_stac_item(
file,
input_datetime=datetime.fromisoformat(f"2024-11-0{(idx % 9) + 1}T00:00:00Z"),
#extensions=extensions,
#collection=collection,
#collection_url=collection_url,
#properties=property,
#id=id,
#asset_name=asset_name,
asset_href=asset_href,
#asset_media_type=asset_mediatype,
with_proj=True,
with_raster=True,
with_eo=True,
#raster_max_size=max_raster_size,
#geom_densify_pts=densify_geom,
#geom_precision=geom_precision,
)
else:
item = create_stac_item(
file,
#input_datetime=input_datetime,
#extensions=extensions,
#collection=collection,
#collection_url=collection_url,
#properties=property,
#id=id,
#asset_name=asset_name,
asset_href=asset_href,
#asset_media_type=asset_mediatype,
with_proj=True,
with_raster=True,
with_eo=True,
#raster_max_size=max_raster_size,
#geom_densify_pts=densify_geom,
#geom_precision=geom_precision,
)
input_datetime = None
if args.time_from_fn is not None:
input_datetime = datetime.strptime(os.path.basename(file),args.time_from_fn)
item = create_stac_item(
file,
input_datetime=input_datetime,
#extensions=extensions,
#collection=collection,
#collection_url=collection_url,
#properties=property,
#id=id,
#asset_name=asset_name,
asset_href=asset_href,
#asset_media_type=asset_mediatype,
with_proj=True,
with_raster=True,
with_eo=True,
#raster_max_size=max_raster_size,
#geom_densify_pts=densify_geom,
#geom_precision=geom_precision,
)
item_dict = item.to_dict()

items[item_dict.get('id')] = item_dict
Expand All @@ -121,5 +104,5 @@ def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path

if __name__ == '__main__':
args = parse_args()
create_stac_items(args.mmgis_url, args.mmgis_token, args.collection_id, args.file_or_folder_path, args.path_remove, args.path_replace_with, args.upsert, args.regex, args.dev)
create_stac_items(args.mmgis_url, args.mmgis_token, args.collection_id, args.file_or_folder_path, args.path_remove, args.path_replace_with, args.upsert, args.regex, args.time_from_fn)
exit()