import pandas as pd
import numpy as np

# Replace 'your_file.csv' with the name of your uploaded file
df = pd.read_csv('/content/inflection_points.csv')

# Step 3: Extract latitude and longitude values
latitudes = df['x'].values
longitudes = df['y'].values

# Initialize lists to store amplitude and wavelength for each point
amplitudes = []
wavelengths = []

# Calculate amplitude and wavelength for each point
for i in range(1, len(latitudes) - 1):
    # Amplitude is the difference between the point and its nearest peak or trough
    amplitude = (latitudes[i] - latitudes[i-1]) / 2 + (latitudes[i+1] - latitudes[i]) / 2
    amplitudes.append(amplitude)

    # Wavelength is the distance to the nearest inflection point
    wavelength = (longitudes[i+1] - longitudes[i-1]) / 2
    wavelengths.append(wavelength)

# Wavelength is the distance between successive inflection points
#wavelength = longitudes[i+1] - longitudes[i-1]
#wavelengths.append(wavelength)

# Add the first and last points manually
amplitudes.insert(0, amplitudes[0])
amplitudes.append(amplitudes[-1])
wavelengths.insert(0, wavelengths[0])
wavelengths.append(wavelengths[-1])

# Add the new columns to the DataFrame
df['amplitude'] = amplitudes
df['wavelength'] = wavelengths

# Save the updated DataFrame back to a CSV file
df.to_csv('/content/InflectionPoints_with_amplitude_wavelength.csv', index=False)

print('Amplitude and wavelength calculated and saved to CSV.')
