Skip to content

Commit

Permalink
Remove old drifter file and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
surgura committed May 28, 2024
1 parent 0672d8c commit e0b9252
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 122 deletions.
2 changes: 1 addition & 1 deletion tests/sailship_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"max_depth": "max"
},
"drifter_deploylocations": [

[-23.081289, 63.743631]
],
"argo_deploylocations": [
[-23.081289, 63.743631]
Expand Down
7 changes: 4 additions & 3 deletions tests/test_sailship.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def test_sailship() -> None:
ctd_fieldset.add_constant("max_depth", -ctd_fieldset.U.depth[-1])

drifter_fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "T": 0},
{
"U": 0,
"V": 0,
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
{"lon": 0, "lat": 0},
)

argo_float_fieldset = FieldSet.from_data(
Expand Down
109 changes: 0 additions & 109 deletions virtual_ship/drifter_deployments.py

This file was deleted.

33 changes: 24 additions & 9 deletions virtual_ship/sailship.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from shapely.geometry import Point, Polygon

from .costs import costs
from .drifter_deployments import drifter_deployments
from .instruments.argo_float import ArgoFloat, simulate_argo_floats
from .instruments.drifter import Drifter, simulate_drifters
from .instruments.location import Location
from .postprocess import postprocess
from .virtual_ship_configuration import VirtualShipConfiguration
Expand Down Expand Up @@ -137,11 +137,12 @@ def SampleT(particle, fieldset, time):

# initialize drifters and argo floats
drifter = 0
drifter_time = []
drifters: list[Drifter] = []
argo = 0
argo_floats: list[ArgoFloat] = []

ARGO_MIN_DEPTH = -config.argo_float_fieldset.U.depth[0]
argo_min_depth = -config.argo_float_fieldset.U.depth[0]
drifter_min_depth = -config.drifter_fieldset.U.depth[0]

# run the model for the length of the sample_lons list
for i in range(len(sample_lons) - 1):
Expand Down Expand Up @@ -203,14 +204,23 @@ def SampleT(particle, fieldset, time):
pset_CTD.time[0] + timedelta(minutes=20).total_seconds()
) # add CTD time and 20 minutes for deployment

# check if we are at a drifter deployment location
# check if we are at a `drifter` deployment location
if drifter < len(config.drifter_deploylocations):
while (
abs(sample_lons[i] - config.drifter_deploylocations[drifter][0]) < 0.01
and abs(sample_lats[i] - config.drifter_deploylocations[drifter][1])
< 0.01
):
drifter_time.append(total_time)
drifters.append(
Drifter(
location=Location(
latitude=config.drifter_deploylocations[drifter][0],
longitude=config.drifter_deploylocations[drifter][1],
),
deployment_time=total_time,
min_depth=drifter_min_depth,
)
)
drifter += 1
print(
f"Drifter {drifter} deployed at {sample_lons[i]}, {sample_lats[i]}"
Expand All @@ -231,7 +241,7 @@ def SampleT(particle, fieldset, time):
longitude=config.argo_deploylocations[argo][1],
),
deployment_time=total_time,
min_depth=ARGO_MIN_DEPTH,
min_depth=argo_min_depth,
max_depth=config.argo_characteristics["maxdepth"],
drift_depth=config.argo_characteristics["driftdepth"],
vertical_speed=config.argo_characteristics["vertical_speed"],
Expand Down Expand Up @@ -267,10 +277,15 @@ def SampleT(particle, fieldset, time):
)
print("Cruise has ended. Please wait for drifters and/or Argo floats to finish.")

# simulate drifter deployments
drifter_deployments(config, drifter_time)
# simulate drifters
simulate_drifters(
drifters=drifters,
fieldset=config.drifter_fieldset,
out_file_name=os.path.join("results", "drifters.zarr"),
outputdt=timedelta(minutes=5),
)

# simulate argo deployments
# simulate argo floats
simulate_argo_floats(
argo_floats=argo_floats,
fieldset=config.argo_float_fieldset,
Expand Down

0 comments on commit e0b9252

Please sign in to comment.