Skip to content

Commit 36cb712

Browse files
committed
Initial commit with the STAC for poland script.
0 parents  commit 36cb712

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# General files for the project
2+
pkg/*
3+
*.pyc
4+
bin/*
5+
.project
6+
/.bin
7+
/_test/secrets/*.json
8+
9+
# OSX leaves these everywhere on SMB shares
10+
._*
11+
12+
# OSX trash
13+
.DS_Store
14+
15+
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
16+
.idea/
17+
*.iml
18+
19+
# Vscode files
20+
.vscode
21+
22+
# Emacs save files
23+
*~
24+
\#*\#
25+
.\#*
26+
27+
# Vim-related files
28+
[._]*.s[a-w][a-z]
29+
[._]s[a-w][a-z]
30+
*.un~
31+
Session.vim
32+
.netrwhist
33+
34+
# Chart dependencies
35+
**/charts/*.tgz
36+
37+
.history
38+
.venv

stac_prepare_poland.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import json
2+
import pystac
3+
4+
def process_poland():
5+
with open("poland-data.json") as poland:
6+
lines = poland.readlines()
7+
edited_lines = []
8+
for idx, line in enumerate(lines):
9+
# if idx >= 1:
10+
# break
11+
item = json.loads(line)
12+
assets = item["assets"]
13+
for asset_name, asset in assets.items():
14+
s3_href = asset["alternate"]["s3"]["href"]
15+
s3_auth_ref = asset["alternate"]["s3"]["auth:refs"]
16+
asset["href"] = s3_href
17+
asset["auth:refs"] = s3_auth_ref
18+
asset.pop("alternate:name")
19+
asset.pop("alternate")
20+
item["assets"] = assets
21+
item["stac_extensions"].remove("https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json")
22+
item["properties"]["auth:schemes"].pop("oidc")
23+
edited_lines.append(item)
24+
# print(item["properties"])
25+
with open("poland-edited.json", "w") as poland_edited:
26+
for line in edited_lines:
27+
json.dump(line, poland_edited)
28+
poland_edited.write('\n')
29+
# with open("single-modified.json", "w") as single:
30+
# single.write(json.dumps(item, indent=2))
31+
# remove "https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json", from stac_extensions
32+
33+
def process_collection():
34+
with open("collection.json") as collection_file:
35+
collection = json.loads(collection_file.read())
36+
assets = collection["item_assets"]
37+
for asset_name, asset in assets.items():
38+
s3_auth_ref = asset["alternate"]["s3"]["auth:refs"]
39+
asset["auth:refs"] = s3_auth_ref
40+
asset.pop("alternate:name")
41+
asset.pop("alternate")
42+
collection["auth:schemes"].pop("oidc")
43+
collection["stac_extensions"].remove("https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json")
44+
with open("collection-edited.json", "w") as collection_edited:
45+
json.dump(collection, collection_edited, indent=2)
46+
47+
if __name__ == "__main__":
48+
#process_poland()
49+
process_collection()

0 commit comments

Comments
 (0)