A location prediction for floating particles on the ocean surface, based on Markov chains.
This code is based on two packages:
- pygtm - which you will need to download locally.
I have added here the package with the moddeddataset2.pyfile, but the only difference is the oversmapling value.
Available at foldermodded-pygtm. - parcels - which can be installed with pip.
I wrote a 2-part guide to complement the tutorials provided by Miron for using the pygtm package and using the Markov prediction.
Note that the reading of NC files is different here, as the structure of the NC file for this example was different from the files created by the parcels script added here.
Data files are not provided, please ask if you need them for validation or help.
Note that NC files might have different structs and might require different handling in the code.
In order to use these codes with ease, please read below.
We need to run several files to make a map prediction using Markov.
-
Run a script that creates particles over the ocean - such as:
parcels_creator_300m_on_mask.py
This code is without parallelization.MPI_parcels_creator_300m_on_mask.py
This code is with parallelization with MPI.To run it, you will need to have MPI installed and run the following:
mpiexec -np ### python MPI_parcels_creator_300m_on_mask.py
! Replace ### with the number of cores you would like to use.Details about some parameters:
- 'cut_n' - splices the area of data over the ocean. The bigger it is, the less data there is (jump value).
- 'nend' - should match the biggest value in the file name of the u,v,vorticity files. Can be smaller for testing purposes.
- 'output_zarr_name' = the file name / folder name of the output from this code
-
Convert using a script the zarr file to an nc file:
tool_zarr_to_nc.py- Use this one for zarr files created without MPI or with MPI with 1 processing unit
tool_zarr_to_nc_MPI.py- Use this one for zarr files created with MPI with more than 1 processing unitDetails about some parameters:
- 'filename' - change file name to match the folder name in output_zarr_name
- 'zarr_file_path' - looks for the predfined path in the output_zarr_name, change if needed
From here you can choose to animate the particles flow (3,4) and / or create a markov prediction (5)
-
Plot the particles and vorticity if you'd like AND animate:
cmap_vorticity_plot_300.py
Note that at function plot_vorticity at comment:
# Plot current location
You have two options - using a cmap or a single color. Choose your preference.Details about some parameters:
- 'parcels_file_name' - should match 'filename' from tool_zarr_to_nc.py, will also be the name of the mp4 and gif files.
-
Animate without remaking the frames / use in case of an error in cmap_vorticity_plot_300.py before the animation is completed:
tool_traj_only_animation.pyDetails about some parameters:
- 'parcels_file_name' - should match 'filename' from tool_zarr_to_nc.py, will also be the name of the mp4 and gif files.
-
Create Markov prediction map using:
markov_pushforward_map.pyDetails about some parameters:
- 'Med_particle' - should match 'parcels_file_name'
- 'files_n' - should match or be lower then the total amount of files available of the u,v,vorticity files
- 'T' - change based on the relevant autocorrelation value on average for the area in question
- 'x0','y0' - change to select starting location
- 'output_dir' - change output location of the frames
- 'output_file' - change output file (frame) name if you'd like
- 'output_anim' - gif and mp4 location