### A Pluto.jl notebook ### # v0.20.17 using Markdown using InteractiveUtils # This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). macro bind(def, element) #! format: off return quote local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end local el = $(esc(element)) global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el) el end #! format: on end # ╔═╡ f1498618-07d5-4892-9028-dabf977bff9b begin using CairoMakie, Drifters using Proj, MeshArrays, GeoJSON, PlutoUI, CSV, DataFrames lon0=-160.0; proj=Proj.Transformation(MA_preset=2,lon0=lon0) using Pkg; Pkg.status() end # ╔═╡ 39055364-6654-42dd-afad-9e67f286f054 md"""# Drifters.jl + Oscar Data Assimilative Model - Oscar provides daily averaged surface currents are provided on a global 0.25 x 0.25 degree grid. - Drifters.jl is used to compute trajectories of virtual floating parcels following Oscar flow fields. !!! note See Appendix for more information on software and data. """ # ╔═╡ e278df98-196b-4f05-a4e1-010b287d221f TableOfContents() # ╔═╡ 5e4f26a0-8954-44b7-a3cb-224197a2e0cb md"""## Visualize Precomputed Data - 30 days of precomputed trajectory data are retrieved from a `csv` file. - the file contains daily time series of positions and normalized velocities. - 50000 virtual parcels were initially released the time varying Oscar flow fields. - the parcel trajectories were then computed using Drifters.jl (code provided below). """ # ╔═╡ d6bd64ce-ebd3-11ef-3ea6-c77f6094d0a6 file_precomputed=joinpath(Drifters.datadeps.getdata("Oscar_2021_small"),"Drifters_Oscar_small.csv") # ╔═╡ 1dc43b12-c49f-4ab5-a239-9188d8452659 df=CSV.read(file_precomputed,DataFrame) # ╔═╡ 7d345828-4078-4273-a62e-9e5f5354591d begin times=sort(unique(df.t)) t0=Observable(1) nt0=2 🔴=@lift(filter(:t => x -> (x >= times[$t0])&&(x <=times[$t0+nt0-1] ), df)) lon=@lift($🔴.lon) lat=@lift($🔴.lat) vel=@lift(86400*sqrt.($🔴.dxdt.^2+$🔴.dydt.^2)) options=(plot_type=:Oscar_plot,proj=proj,lon0=-160,add_background=true,add_polygons=true, lon=lon,lat=lat,color=vel,colorrange=(0,2),colormap=:thermal,markersize=2) J=DriftersDataset( data=(df=df,), options=options) fig=plot(J) end # ╔═╡ 3acee516-d7cc-42ce-add8-9d3a3ec116a5 begin do_movie_bind = @bind do_movie CheckBox(default=false) md""" Create animation ? $(do_movie_bind)""" end # ╔═╡ c187acd0-50a5-4360-ad13-73d658ebe87f # Animation if do_movie file_output_mp4=tempname()*".mp4" record(fig, file_output_mp4, 1:length(times)-10, framerate = 25) do t t0[]=t end print(file_output_mp4) else "skip animation" end # ╔═╡ 1aed4830-43dc-4d98-bcc0-775738a477c1 md"""## Compute New Trajectories !!! warning This requires Oscar data to have been downloaded to the `input_path` folder. """ # ╔═╡ 714c83fd-d885-455b-b87a-2a0800446519 begin do_compute_bind = @bind do_compute CheckBox(default=false) md""" Compute New Trajectories ? $(do_compute_bind)""" end # ╔═╡ a8ddb075-73cf-4496-a8a5-4f824a5f80d6 begin input_path="oscar/data" input_files=Drifters.Oscar.list_files(input_path,2021) end # ╔═╡ dd7f5d46-6479-4612-a6a4-2fedca50b1a8 if do_compute && !isempty(input_files) nt=30; output_file=tempname()*"_oscar.csv" I=Drifters.Oscar.main_loop(input_files=input_files, do_save=true, output_file=output_file, n_part=10000, reset_rate=0.05, nt=nt, verbose=true) #requires upcoming v0.6.6 println(output_file) println(Int.(round.(extrema(unique(I.🔴.t))./86400))) O=(plot_type=:Oscar_plot,proj=proj,lon0=-160,add_background=true, add_polygons=true, markersize=2) K=DriftersDataset( data=(df=I.🔴,), options=O); "all set" else O=(plot_type=:Oscar_plot,proj=proj,lon0=-160,add_background=true, add_polygons=true, markersize=2) K=DriftersDataset( data=(df=df,), options=O) "skip new trajectory calculations" end # ╔═╡ 317359d2-428b-48dc-933f-4ad6a874f7a6 plot(K) # ╔═╡ 24ecbc7b-b0f2-4ebe-9ac4-1a827254f225 md"""## Appendix ### Julia Packages """ # ╔═╡ 4a122475-11ab-4d1e-9ce6-c12148339430 isdir(MeshArrays.GRID_LLC90) ? "all set for plotting" : "missing background data for plotting" # ╔═╡ 1f479c36-f021-464c-a279-0d62a1f33359 md"""### Software : Drifters.jl ($(Pkg.pkgversion(Drifters))) Forget, G., (2021). IndividualDisplacements.jl: a Julia package to simulate and study particle displacements within the climate system. Journal of Open Source Software, 6(60), 2813, ### Data : Oscar (v2.0) To compute trajectories you'll want to : - download Oscar data from . - put them in a subfolder called `oscar/data/` that should look as shown below. ``` OSCAR_L4_OC_FINAL_V2.0.citation.txt oscar_currents_final_19930101.nc oscar_currents_final_19930101.nc.md5 ... ``` !!! note Data set citation : ESR; Dohan, Kathleen. 2022. Ocean Surface Current Analyses Real-time (OSCAR) Surface Currents - Final 0.25 Degree (Version 2.0). Ver. 2.0. PO.DAAC, CA, USA. Dataset accessed [YYYY-MM-DD] at https://doi.org/10.5067/OSCAR-25F20 #### More on Oscar - Sample data granule : [this link](https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OSCAR_L4_OC_FINAL_V2.0/oscar_currents_final_20220504.nc) - How-to [download](