I am generating contour lines from a DEM using QGIS and the python console. The process generates many small circles in regions of low slope (little black circles) that detract from the long connected contour representing the "true" contour (indicated by hand in blue) in the picture.
As suggested "https://community.esri.com/thread/206552-isyhypses-filtering-out-very-small-areas-of-elevation" I could filter the contour lines for length but that may also remove many "true" contours that can be seen in my attached image such as the few small hills here and there (indicated by hand for example in red).
Google searches suggest to smooth the underlying source DEM as in smoothing DEM but that would reduce the quality of the generated contour lines.
The best idea I had, would be to somehow boolean filter the contour lines against length as described above AND/OR local slope % as described calculating-slope-in-percentage-with-qgis, but I haven't yet determined how or if this is possible in pyQGIS - possibly by calculating a slope % tif and then reading it at every vertex of each contour then averaging for each contour feature to create a second attribute to boolean filter along with length. Before I embark on that (probably time consuming) solution, is there an existing method for removing the low-slope artifacts generated in the DEM to contour process available in pyQGIS?