fmemuir / COASTGUARD

Coastal Observation + Analysis using Satellite-derived Timeseries, Generated Using AI + Real-time Data
38 stars 5 forks source link

FindShoreContours_WP() fails on poor quality/hazy images #16

Open fmemuir opened 3 months ago

fmemuir commented 3 months ago

In certain sites and images, the veg edge extraction process falls over when contours are attempted to be extracted. Specifically at:

File COASTGUARD/VegetationLine.py, line 232
    contours_ndvi, t_ndvi = FindShoreContours_WP(im_ndvi, im_labels, cloud_mask, im_ref_buffer)
File COASTGUARD/VegetationLine.py, line 1030
    t_ndi, _ = Toolbox.FindWPThresh(int_veg, int_nonveg)
File COASTGUARD/Toolbox.py, line 2013
    model.fit(sample)

The code fails because model cannot take a variable of shape (0,1) (i.e. sample is empty). Tracing this back, this happens on very hazy/dark/poor quality images, which have somehow passed the initial catches for image quality (cloud masking, empty rasters). The reason the array going into FindWPThresh is empty is because not enough classes have been found in order to define a contour along; most likely all pixels have been classes as nonveg.

This needs to be fixed by either catching these images early and discarding based on reflectance histograms, or the slightly faster route of a conditional after the images have been classified which skips this image if the labels are all one class.