-
Notifications
You must be signed in to change notification settings - Fork 0
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
Validation Notebook #114
Draft
botanical
wants to merge
2
commits into
main
Choose a base branch
from
jt/validation-notebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Validation Notebook #114
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pre-commit | |
pystac[validation] | ||
pytest | ||
ruff | ||
stac-validator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
transformation-scripts/validate-updated-collections.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import boto3\n", | ||
"import os\n", | ||
"import glob\n", | ||
"import shutil\n", | ||
"\n", | ||
"from stac_validator import stac_validator" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"AWS_ACCESS_KEY_ID = \"[CHANGE ME]\"\n", | ||
"AWS_SECRET_ACCESS_KEY = \"[CHANGE ME]\"\n", | ||
"AWS_SESSION_TOKEN = \"[CHANGE ME]\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"s3_client = boto3.client(\n", | ||
" \"s3\",\n", | ||
" aws_access_key_id=AWS_ACCESS_KEY_ID,\n", | ||
" aws_secret_access_key=AWS_SECRET_ACCESS_KEY,\n", | ||
" aws_session_token=AWS_SESSION_TOKEN,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define the directory path\n", | ||
"local_dir = \"./collections-to-validate\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 68, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def download_collections(bucket_name, s3_prefixes):\n", | ||
" s3 = s3_client\n", | ||
" s3_responses = []\n", | ||
" json_keys = []\n", | ||
"\n", | ||
" for s3_prefix in s3_prefixes:\n", | ||
" response = s3.list_objects_v2(Bucket=bucket_name, Prefix=s3_prefix)\n", | ||
" s3_responses.append(response)\n", | ||
"\n", | ||
" for item in s3_responses:\n", | ||
" for item in item[\"Contents\"]:\n", | ||
" if item[\"Key\"].endswith(\".json\"):\n", | ||
" json_keys.append(item[\"Key\"])\n", | ||
"\n", | ||
" # Create the directory if it doesn't exist\n", | ||
" if not os.path.exists(local_dir):\n", | ||
" os.makedirs(local_dir)\n", | ||
" print(\"Directory created successfully at\", local_dir)\n", | ||
" else:\n", | ||
" print(\"Directory already exists at\", local_dir)\n", | ||
"\n", | ||
" # Download json files to local directory\n", | ||
" for key in json_keys:\n", | ||
" local_file_path = os.path.join(local_dir, os.path.basename(key))\n", | ||
" s3.download_file(bucket_name, key, local_file_path)\n", | ||
"\n", | ||
"\n", | ||
"def validate_collections():\n", | ||
" json_files = glob.glob(os.path.join(local_dir, \"*.json\"))\n", | ||
" for json_file in json_files:\n", | ||
" print(f\"Validating file: {json_file}\")\n", | ||
" stac = stac_validator.StacValidate(json_file)\n", | ||
" stac.run()\n", | ||
" valid_stac = stac.message[0][\"valid_stac\"]\n", | ||
" print(valid_stac)\n", | ||
" if not valid_stac:\n", | ||
" print(f\"Invalid STAC. Error message {stac.message[0]['error_message']}\")\n", | ||
"\n", | ||
"\n", | ||
"def cleanup():\n", | ||
" shutil.rmtree(local_dir)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 69, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Directory created successfully at ./collections-to-validate\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"bucket_name = \"veda-data-store\"\n", | ||
"s3_prefixes = [\"hlsl30-ej-reprocessed\", \"hlss30-ej-reprocessed\"]\n", | ||
"download_collections(bucket_name, s3_prefixes)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 70, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017221T144403.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021250T163901.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021210T163901.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021200T163901.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017173T144347.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021220T163901.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017293T150709.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017205T144356.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021290T164311.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021230T163215.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017218T150721.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017333T150709.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021185T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017323T150709.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021246T163220.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021195T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021182T163159.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021270T164051.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017317T144417.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017278T150721.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021262T163223.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021295T164339.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017193T150719.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017301T144420.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021278T163229.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017285T144419.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021198T163201.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017157T144341.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021280T164201.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017318T150721.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021205T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021235T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021225T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021245T163839.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021285T164139.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021265T163909.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T15RYP.2021294T163232.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T15RYP.2021300T164411.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017333T144411.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017237T144407.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.L30.T19QHA.2017269T144414.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n", | ||
"Validating file: ./collections-to-validate/HLS.S30.T19QHA.2017233T150719.v2.0_stac-ej-reprocessed.json\n", | ||
"True\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"validate_collections()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 71, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"cleanup()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generated this file using
pip-compile requirements.in
though there are several more changes than I was expecting 🤔