Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow Users to Upload a CSV file with slopes for each transect for tide correction #264

Open
4 tasks
2320sharon opened this issue Jun 27, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@2320sharon
Copy link
Collaborator

2320sharon commented Jun 27, 2024

  • Allow users to to upload a CSV of transect IDs and slopes
  • Allow users to to specify a default slope value if one of the transects provided does not have any slope values
  • Modify tide correction to use slopes from the CSV file instead of a single slope value to correct for tides
  • Add a new page on how to use a CSV file with slope transects and times to perform tide correction

Example Data

TrucVert_fieldsurvey_in_situ_slopes.csv

Initial Code

import pandas as pd
import numpy as np


def get_closest_slope(csv_file_path, transect_id, target_date:str,default_slope=0.0):

    provided_date = pd.to_datetime(target_date)
    df = pd.read_csv(csv_file_path, header=None)

    # Rename the first column to 'date' for better readability
    df.rename(columns={0: 'date'}, inplace=True)

    # Convert the 'date' column to datetime format
    df['date'] = pd.to_datetime(df['date'])
    # set the date column as the index
    df.set_index('date', inplace=True)
    # get the first row and turn it into the columns exception the first column
    df.columns = df.iloc[0].values
    # drop the first row because it contains the column names
    df = df[1:]

    if transect_id not in df.columns:
        raise ValueError(f"Transect ID {transect_id} not found in the CSV file")
    if np.all(df[transect_id].isna()):
        raise ValueError(f"All slope values for transect {transect_id} are NaN")

    # Filter non-NA values for the given transect ID
    transect_id_dates = df[transect_id].dropna()

    # Find the index of the date closest to the provided date
    closest_date_idx = np.abs(transect_id_dates.index - provided_date).argmin()

    # Get the value (slope) at the closest date
    closest_slope = transect_id_dates.iloc[closest_date_idx]

    return closest_slope

# # Example usage
csv_file_path = "TrucVert_fieldsurvey_in_situ_slopes.csv"
target_date = '2011-08-02'
transect_id = 840.0  # Example transect ID
slope=get_closest_slope(csv_file_path, transect_id, target_date)
slope
@2320sharon 2320sharon added the enhancement New feature or request label Jun 27, 2024
@2320sharon 2320sharon self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant