# -*- coding: utf-8 -*-
"""
Created on Wed Aug 26 14:45:03 2026

@author: chuffard
"""

# -*- 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


MARS2025atn = r"W:/Analyses/2025 MARS deployment/SES_out_atn_Red_5only.csv"
MARS2025atn = pd.read_csv(MARS2025atn)

# Extract the pattern into a new column
MARS2025atn['file_name'] = MARS2025atn['file_name'].astype(str).str.strip()

MARS2025atn[['date', 'time']] = MARS2025atn['file_name'].str.extract(r'(\d{6})-(\d{6})')

# Convert to actual datetime objects for analysis
MARS2025atn['timestamp'] = pd.to_datetime(MARS2025atn['date'] + MARS2025atn['time'], format='%y%m%d%H%M%S')

MARS2025atn.columns



MARS2025atn["DateTime"] = pd.to_datetime(MARS2025atn['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
MARS2025atn['F_atn']= MARS2025atn['atn']/SEScolltime*SESimgarea/SEStraparea


#These are from SES at Station M in 2023 paper
MARS2025atn['POCmodel_mg']= 10**3.4 * MARS2025atn['F_atn']**0.94
MARS2025atn['POCmodel_g']= MARS2025atn['POCmodel_mg']/1000

MARS2025atn['POCmodel_g'].mean()#(0.2753247346815628)
MARS2025atn['POCmodel_g'].plot()
plt.show()

MARS2025atn.to_csv('//Thalassa/ProjectLibrary/902305_Event_Detection_with_SES/Analyses/2025 MARS deployment/MARS2025atn_POC_red.csv')
