Skip to content

Commit c38d0d4

Browse files
authored
create-stac-items.py - COG ingest filename time (#608)
* minor change to support external input filename timestamps * cleanup
1 parent 7a04c35 commit c38d0d4

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

auxiliary/stac/create-stac-items/create-stac-items.py

+24-41
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def parse_args():
2121
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.')
2222
parser.add_argument('-u', '--upsert', help='Allow overwriting existing STAC items', action='store_true')
2323
parser.add_argument('-r', '--regex', help='If folder, only create stac items for files that match this regex')
24-
parser.add_argument('-d', '--dev', help='dev mode that does other things', action='store_true')
24+
parser.add_argument('-t', '--time_from_fn', help='time format to read from filename', type=str, default=None)
2525

2626
args = parser.parse_args()
2727
return args
2828

29-
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):
29+
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):
3030

3131
isDir = os.path.isdir(file_or_folder_path)
3232

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

62-
if dev:
63-
item = create_stac_item(
64-
file,
65-
input_datetime=datetime.fromisoformat(f"2024-11-0{(idx % 9) + 1}T00:00:00Z"),
66-
#extensions=extensions,
67-
#collection=collection,
68-
#collection_url=collection_url,
69-
#properties=property,
70-
#id=id,
71-
#asset_name=asset_name,
72-
asset_href=asset_href,
73-
#asset_media_type=asset_mediatype,
74-
with_proj=True,
75-
with_raster=True,
76-
with_eo=True,
77-
#raster_max_size=max_raster_size,
78-
#geom_densify_pts=densify_geom,
79-
#geom_precision=geom_precision,
80-
)
81-
else:
82-
item = create_stac_item(
83-
file,
84-
#input_datetime=input_datetime,
85-
#extensions=extensions,
86-
#collection=collection,
87-
#collection_url=collection_url,
88-
#properties=property,
89-
#id=id,
90-
#asset_name=asset_name,
91-
asset_href=asset_href,
92-
#asset_media_type=asset_mediatype,
93-
with_proj=True,
94-
with_raster=True,
95-
with_eo=True,
96-
#raster_max_size=max_raster_size,
97-
#geom_densify_pts=densify_geom,
98-
#geom_precision=geom_precision,
99-
)
62+
input_datetime = None
63+
if args.time_from_fn is not None:
64+
input_datetime = datetime.strptime(os.path.basename(file),args.time_from_fn)
65+
item = create_stac_item(
66+
file,
67+
input_datetime=input_datetime,
68+
#extensions=extensions,
69+
#collection=collection,
70+
#collection_url=collection_url,
71+
#properties=property,
72+
#id=id,
73+
#asset_name=asset_name,
74+
asset_href=asset_href,
75+
#asset_media_type=asset_mediatype,
76+
with_proj=True,
77+
with_raster=True,
78+
with_eo=True,
79+
#raster_max_size=max_raster_size,
80+
#geom_densify_pts=densify_geom,
81+
#geom_precision=geom_precision,
82+
)
10083
item_dict = item.to_dict()
10184

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

122105
if __name__ == '__main__':
123106
args = parse_args()
124-
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)
107+
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)
125108
exit()

0 commit comments

Comments
 (0)