# -*- coding: utf-8 -*-
"""
Created on Mon Apr 27 10:50:14 2026

@author: chuffard
"""


import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import pandas as pd
import sys
import os.path
import warnings
import glob
from pathlib import Path
import math


MARS2023atn = r"//Thalassa/ProjectLibrary/902305_Event_Detection_with_SES/Analyses/2023 MARS deployment/SES_out_atnRED.csv"
MARS2023atn = pd.read_csv(MARS2023atn)

# Extract the pattern into a new column
MARS2023atn['file_name'] = MARS2023atn['file_name'].astype(str).str.strip()

MARS2023atn[['date', 'time']] = MARS2023atn['file_name'].str.extract(r'(\d{6})-(\d{6})')

# Convert to actual datetime objects for analysis
MARS2023atn['timestamp'] = pd.to_datetime(MARS2023atn['date'] + MARS2023atn['time'], format='%y%m%d%H%M%S')

MARS2023atn.columns



MARS2023atn["DateTime"] = pd.to_datetime(MARS2023atn['timestamp'])
#convert atn to POC flux

#from Estapa et al. 2023 optical sediment trap calibration. also accounting for image and collect area since those aren't in our og atn calculation

SEStraparea = 0.5;
#imgarea = length(find(isfinite(bgr(:))))./(0.07194.^2)./(1000000.^2);  % pix / (pix/um^2) / (um^2/m^2)#this was in Meg's example code but it's not for SES

#This is adapted to pyton from matlab code Meg gave us
SESimgarea = math.pi*(25/1000/2)**2  # diameter of lower end of funnel is 25 mm, compute area in m^2
SEScolltime = 5/(60*24) #in days
MARS2023atn['F_atn']= MARS2023atn['atn']/SEScolltime*SESimgarea/SEStraparea


#These are from SES at Station M in 2023 paper
MARS2023atn['POCmodel_mg']= 10**3.4 * MARS2023atn['F_atn']**0.94
MARS2023atn['POCmodel_g']= MARS2023atn['POCmodel_mg']/1000

MARS2023atn['POCmodel_g'].mean()#(0.2753247346815628)
MARS2023atn['POCmodel_g'].plot()
plt.show()

MARS2023atn.to_csv('//Thalassa/ProjectLibrary/902305_Event_Detection_with_SES/Analyses/2023 MARS deployment/MARS2023atn_POC_red.csv')
