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