geowatch.cli.stac_to_kwcoco module¶
Convert a STAC catalog to a kwcoco file.
The following example illustrates how to start from a STAC query, resolve that into a STAC catalog and finally use this script to convert it to KWCOCO.
CommandLine
# Create a demo region file
xdoctest geowatch.demo.demo_region demo_khq_region_fpath
DATASET_SUFFIX=DemoKHQ-2022-06-10-V2
DEMO_DPATH=$HOME/.cache/geowatch/demo/datasets
REGION_FPATH="$HOME/.cache/geowatch/demo/annotations/KHQ_R001.geojson"
SITE_GLOBSTR="$HOME/.cache/geowatch/demo/annotations/KHQ_R001_sites/*.geojson"
START_DATE=$(jq -r '.features[] | select(.properties.type=="region") | .properties.start_date' "$REGION_FPATH")
END_DATE=$(jq -r '.features[] | select(.properties.type=="region") | .properties.end_date' "$REGION_FPATH")
# Shrink time window to test with less data
START_DATE=2016-12-02
END_DATE=2020-12-31
REGION_ID=$(jq -r '.features[] | select(.properties.type=="region") | .properties.region_id' "$REGION_FPATH")
SEARCH_FPATH=$DEMO_DPATH/stac_search.json
RESULT_FPATH=$DEMO_DPATH/all_sensors_kit/${REGION_ID}.input
CATALOG_FPATH=$DEMO_DPATH/all_sensors_kit/${REGION_ID}_catalog.json
KWCOCO_FPATH=$DEMO_DPATH/all_sensors_kit/${REGION_ID}.kwcoco.zip
mkdir -p "$DEMO_DPATH"
# Create the search json wrt the sensors and processing level we want
python -m geowatch.stac.stac_search_builder \
--start_date="$START_DATE" \
--end_date="$END_DATE" \
--cloud_cover=40 \
--sensors=sentinel-2-l2a \
--out_fpath "$SEARCH_FPATH"
cat "$SEARCH_FPATH"
# Delete this to prevent duplicates
rm -f "$RESULT_FPATH"
# Create the .input file
python -m geowatch.cli.stac_search \
--region_file "$REGION_FPATH" \
--search_json "$SEARCH_FPATH" \
--mode area \
--verbose 2 \
--outfile "${RESULT_FPATH}"
cat "$RESULT_FPATH"
python -m geowatch.cli.baseline_framework_ingress \
--input_path="$RESULT_FPATH" \
--catalog_fpath="${CATALOG_FPATH}" \
--virtual=True \
--jobs=avail \
--aws_profile=iarpa \
--requester_pays=0
AWS_DEFAULT_PROFILE=iarpa python -m geowatch.cli.stac_to_kwcoco \
--input_stac_catalog="${CATALOG_FPATH}" \
--outpath="$KWCOCO_FPATH" \
--jobs=8 \
--from_collated=False \
--ignore_duplicates=0
# Check that the resulting kwcoco has what you want in it
geowatch stats "$KWCOCO_FPATH"
# Use kwcoco info to dump a single image dictionary
kwcoco info "$KWCOCO_FPATH" -g 1 -i 0
- SeeAlso:
~/code/watch/geowatch/cli/stac_search.py ~/code/watch/geowatch/cli/queue_cli/prepare_ta2_dataset.py
- class geowatch.cli.stac_to_kwcoco.StacToCocoConfig(*args, **kwargs)[source]¶
Bases:
DataConfig
Convert a STAC catalog to a KWCOCO manifest
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'assume_relative': <Value(False)>, 'from_collated': <Value(False)>, 'ignore_duplicates': <Value(False)>, 'input_stac_catalog': <Value(None)>, 'jobs': <Value(0)>, 'outpath': <Value(None)>, 'populate_watch_fields': <Value(False)>, 'verbose': <Value(1)>}¶
- geowatch.cli.stac_to_kwcoco.make_coco_aux_from_stac_asset(asset_name, asset_dict, platform, name=None, force_affine=True, assume_relative=False, from_collated=False, verbose=0)[source]¶
Converts a single STAC asset into an “auxiliary” item / asset that will belong to a kwcoco image.