This repository is no longer maintained.
Semi-Automatic Crop Field Extraction from Imagery
- Earth Engine Python API
- SACFEI can be used as a stand-alone Python library, but also has scripts for extracting edges from Sentinel-2 10m and Landsat 7/8 15m pan from Google Cloud storage
On Linux, the installation steps for the GEE Python package consist of:
> pip3.6 install --user earthengine-api
> python3.6 -c "import ee; ee.Initialize()"
...and then following the on-screen and browser steps.
> git clone https://github.com/jgrss/sacfei.git
> cd sacfei/
> python3.6 setup.py build && pip3.6 install --user --upgrade . && rm -rf build/
>>> import sacfei
>>> # Here, `ts_array` is a multi-dimensional
>>> # time-series array
>>> saf = sacfei.SACFEI(ts_array)
>>>
>>> # Extract edges
>>> saf.extract_egm()
>>>
>>> # Edge gradient magnitude
>>> print(saf.egm)
>>>
>>> # Segment edges
>>> saf.segment_egm()
>>>
>>> print(saf.objects)
- The Google Earth Engine API (see above) is needed to run the GEE Python interface.
cd /sacfei/scripts/
python3.6 gee.py -h
- When running
gee.py
, the output GeoTiffs will be saved to your Google Drive folder that is specified with--drive-folder
.- When finished, use
gdcp
(below) to batch download files.
- When finished, use
Process one year of data for MGRS grid 11SPS over Europe
python3.6 gee.py --start-date 2016-1-1 --end-date 2017-1-1 --mgrs-grids 11SPS --export-name my_image --export-cell 10 --export-crs euaeac --drive-folder GEE_dir
Process MGRS grids over South America, where the grids to process are given by a shapefile
python3.6 gee.py --start-date 2016-1-1 --end-date 2017-1-1 --mgrs-region /mgrs_grids.shp --export-name my_image --export-cell 15 --export-crs saaeac --drive-folder GEE_dir
E.g.,
gdcp download -i <Google Drive folder id> <output location>
python3.6 post_gee.py -i /GEE -o /EGM --export-crs euaeac
Print command-line options
python3 batch.py -h
Basic usage intersecting a land cover map
python3 batch.py -i /EGM/my_image_11SPS_edited.tif -o /objects/objects.tif --lc-image /land_cover.tif --method all --row-block 1000 --col-block 1000 --n-jobs 8
The command below specifies:
- the image normalization grid tile sizes
- the edge thresholding window sizes
- relaxes edge probabilities
- applies post-segmentation object cleaning
- specifies the logistic scaling paramaters
- appends additional image variables to each object
- uses WGS84 lat/lon CRS
python3 batch.py -i /EGM/edited_mosaic.vrt -o /objects/objects.tif --grid-tiles 16 32 --thresh-windows 25 51 --relax-probas --apply-clean --logistic-alpha 1.5 --logistic-beta 0.7 --projection wgs84 --var-image /extra_variables.vrt --method all --row-block 1000 --col-block 1000 --n-jobs 8