Skip to content

Instantly share code, notes, and snippets.

@jklymak
Created January 28, 2024 00:25
Show Gist options
  • Save jklymak/288d859dc2f056d978908769e5caaf3f to your computer and use it in GitHub Desktop.
Save jklymak/288d859dc2f056d978908769e5caaf3f to your computer and use it in GitHub Desktop.
LinePPlan
import numpy as np
import matplotlib.pyplot as plt
import seawater
%matplotlib widget
import pooch
import xarray as xr
import pandas
"""
eg
Station Lat Latmin Lon Lonmin depth activity
P1 48 34.5 125 30.0 120 CTD
P2 48 36.0 126 00.0 114 Rosette/Bongo
P3 48 37.5 126 20.0 750 CTD
"""
df = pandas.read_csv('LinePStations.txt', delimiter=' ', header='infer', index_col=0)
df['dlat'] = df.Lat + df.Latmin / 60
df['dlon'] = -df.Lon - df.Lonmin / 60
along, head = seawater.dist(df.dlat, df.dlon, units='nm')
df['along'] = np.cumsum(np.concatenate([[0], along]))
# make time series from StationTimes.txt
t0 = np.datetime64('2024-01-27T12:43')
lat0 = 49 + 2.6/60
lon0 = -131 - 23.65/60
"""
eg
# Station, sampling [h], speed to station [kts]
P26, 12.0, 12.0
P25, 1.5, 12.0
P24, 1.5, 12.0
P23, 1.5, 12.0
"""
ts = [[],[], [], []]
for nn, plan in enumerate(['StationTimes12there8back.txt',
'StationTimes8there12back.txt',
'StationTimes12there12back.txt',
'StationTimes12there8back36Papa.txt',
]):
station_data = pandas.read_csv(plan, delimiter=',', names=['station', 'sampletime', 'speed'],
comment='#')
ts[nn]={}
Nstations = len(station_data)
time = np.zeros(2*Nstations+1, dtype='datetime64[s]')
tslat = np.zeros(2*Nstations+1, dtype='float')
tslon = np.zeros(2*Nstations+1, dtype='float')
# need a start...
time[0] = t0
tslat[0] = lat0
tslon[0] = lon0
num = 0
for i in range(0, Nstations):
# each station has an arrive time, and a depart time.
station = station_data.iloc[i]
stname = station['station']
# arrive
speed = station['speed']
num += 1
tslat[num] = df.loc[stname].dlat
tslon[num] = df.loc[stname].dlon
dist, ang = seawater.dist(tslat[num-1:num+1], tslon[num-1:num+1], units='nm')
time[num] = time[num-1] + np.timedelta64(int(dist / speed * 3600) , 's')
# leave
num += 1
stationtime = np.timedelta64(int(station['sampletime'] * 3600), 's')
time[num] = time[num-1] + stationtime
tslat[num] = df.loc[stname].dlat
tslon[num] = df.loc[stname].dlon
ts[nn]['time'] = time
ts[nn]['lon'] = tslon
ts[nn]['lat'] = tslat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment