From b014a141687987ef4311b9e0c9d7956e7d38cd1b Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 26 Aug 2019 17:06:17 +1000 Subject: [PATCH] Reverse chainages so elevations are monotonically increasing --- extract_contours.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/extract_contours.py b/extract_contours.py index 0602d6b..eb5cbea 100644 --- a/extract_contours.py +++ b/extract_contours.py @@ -40,14 +40,17 @@ for beach in beaches: survey = df.loc[(beach, block, profile, date), :] survey = survey.set_index('Chainage') - # Find last point in profile above ref contour elevation - last_idx = survey.where( - survey['Elevation'] > contour_z).last_valid_index() - elevation = survey.loc[last_idx:, 'Elevation'] - eastings = survey.loc[last_idx:, 'Easting'] - northings = survey.loc[last_idx:, 'Northing'] - x.append(np.interp(contour_z, elevation, eastings)) - y.append(np.interp(contour_z, elevation, northings)) + # Reverse survey chainage for interpolation + survey = survey[::-1] + + # Find largest chainage in profile above contour elevation + idx = survey.where( + survey['Elevation'] > contour_z).first_valid_index() + elevation = survey.loc[:idx, 'Elevation'] + eastings = survey.loc[:idx, 'Easting'] + northings = survey.loc[:idx, 'Northing'] + x = np.interp(contour_z, elevation, eastings) + y = np.interp(contour_z, elevation, northings) except KeyError: pass