EZfate and python, a quick guide

The EZfate package on GitHub is written mostly in R, but most of the data was created in python, and all the anlysis can be performed in python. The data structures are available in zarr, which is easilly read by python. The following text describes the underlying data structures that EZfate provides, and documents some routines I have provided to get started using EZfate data in python.

All of this description will make more sense if you spend some time reading at least the introduction to EZfate given at its GitHub page here.

Python packages you need

The codes I provide expect that the following python modules exist on your system. They are all easily installed with conda:

Data structures

EZfate provides two main data structures, the forward connectivity E and the backwards connectivity Etranspose. These are best thought of as sparce matrices that define where all the particles released at one location go (E) and where all particles released at one location came from (Etranspose). The two data structures are stored as Zarr files which are downloaded by getEZfateFromOSN.py, described below. They have been precomputed globally for all months from 2007 to last year, as is described on the EZfate GitHub page. Climatological connectivity is also provided.

All locations are given as indices into the Mercator Ocean Model GLORYS 1/12th degree grid. This was done to conserve space and bandwidth. Instructions for converting this into latitude and longitude is given below.

E contains 6 columns of data:

Etranspose contains a similar 6 columns of data, and is nearly symmetric with E with “From” and “To” switched:

(nx,ny) to (longitude,latitude)

As part of the data distributed, the model grid for the GLORYS model is provided. It can be fetched with the provided getEZfateFromOSN.py module, and used to convert vectors of nx,ny to longitude and latitude with the following code.

import getEZfateFromOSN
import netCDF4 as nc

#get the file which contains the bathymetry and grid data for the mercator ocean model and for
#the connectivity files
maskFile='EZfateData/EZfateFiles/ext-PSY4V3R1_mesh_zgr.nc'
maskFile=getEZfateFromOSN.getFileFromOSN(maskFile)
with nc.Dataset(maskFile,'r') as gridData:
    lonMat=gridData['nav_lon'][:]
    latMat=gridData['nav_lat'][:]

#write a function that takes a vector of nx grid locations and ny
#locations and returns vectors of longitude and latitude.
def nxny2lonlat(nxVec,nyVec):
    lonVec=array([lonMat[p] for p in zip(nyVec,nxVec)])
    latVec=array([latMat[p] for p in zip(nyVec,nxVec)])
    return lonVec,latVec

Example files

Soon I will provide more documentation, but for now I will provide three helpful (I hope) example python scripts to show how to use this connectivity data.

The graphics produced are crude because I did not want to add cartopy or equivalent as a dependency.

Usefull python functions

These call several important utility modules in which much of the real work is done. In the future I will document the many useful functions in them in this document, but they are well documented in the files themselves. Below is a subset of the most useful functions they provide.