Coder Social home page Coder Social logo

meom-group / jaxparrow Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 107.26 MB

A package for computing the inversion of the cyclogeostrophic balance based on a variational formulation approach, using JAX.

Home Page: https://jaxparrow.readthedocs.io/

License: Apache License 2.0

Python 100.00%
eddy flow geostrophy jax swirl velocity cyclogeostrophy

jaxparrow's Introduction

jaxparrow

Python PyPi Tests Docs

jaxparrow implements a novel approach based on a variational formulation to compute the inversion of the cyclogeostrophic balance.

It leverages the power of JAX, to efficiently solve the inversion as an optimization problem. Given the Sea Surface Height (SSH) field of an ocean system, jaxparrow estimates the velocity field that best satisfies the cyclogeostrophic balance.

Installation

The package is Pip-installable:

pip install jaxparrow

However, users with access to GPUs or TPUs should first install JAX separately in order to fully benefit from its high-performance computing capacities. See JAX instructions.
By default, jaxparrow will install a CPU-only version of JAX if no other version is already present in the Python environment.

Usage

As a package

Two functions are directly available from jaxparrow:

  • geostrophy computes the geostrophic velocity field (returns two 2darray) from:
    • a SSH field (a 2darray),
    • the latitude and longitude at the T points (two 2darray),
    • an optional mask grid (one 2darray).
  • cyclogeostrophy computes the cyclogeostrophic velocity field (returns two 2darray) from:
    • a SSH field (a 2darray),
    • the latitude and longitude at the T points (two 2darray),
    • an optional mask grid (one 2darray).

Because jaxparrow uses C-grids the velocity fields are represented on two grids (U and V), and the SSH on one grid (T).

In a Python script, assuming that the input grids have already been initialised / imported, it would resort to:

from jaxparrow import cyclogeostrophy, geostrophy

u_geos, v_geos = geostrophy(ssh_t=ssh,
                            lat_t=lat, lon_t=lon,
                            mask=mask)
u_cyclo, v_cyclo = cyclogeostrophy(ssh_t=ssh,
                                   lat_t=lat, lon_t=lon,
                                   mask=mask)

To vectorise the application of the geostrophy and cyclogeostrophy functions across an added time dimension, one aims to utilize vmap. However, this necessitates avoiding the use of np.ma.masked_array. Hence, our functions accommodate mask array as parameter to effectively consider masked regions.

By default, the cyclogeostrophy function relies on our variational method. Its method argument provides the ability to use an iterative method instead, either the one described by Penven et al., or the one by Ioannou et al.. Additional arguments also give a finer control over the three approaches hyperparameters.
See jaxparrow API documentation for more details.

Notebooks are available as step-by-step examples.

As an executable

jaxparrow is also available from the command line:

jaxparrow --conf_path conf.yml

The YAML configuration file conf.yml instruct where input netCDF files are locally stored, and how to retrieve variables and coordinates from them. It also provides the path of the output netCDF file. Optionally, it can specify which cyclogeostrophic approach should be applied and its hyperparameters.

An example configuration file detailing all the required and optional entries can be found here.

jaxparrow's People

Contributors

vadmbertr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jaxparrow's Issues

Differencing and averaging operators on C-grid

With the current implementation, differencing and averaging operators are not always defined at the midpoint.

Todo:

  • remove the ability for the user to provide U and V grids, only the T grid. Means that the cyclogeostrophy function should take the SSH as argument (instead of Ug and Vg), compute the geostrophic currents, and then the cyclo ones (plus, feels better in terms of design IMO),
  • adopt NEMO indexing convention (https://www.nemo-ocean.eu/doc/img360.png),
  • re-write differencing and averaging operators (should apply to an axis, with a left or right padding depending on the interpolation point),
  • re-write the test case to make sure it fails in case of regression.

`jax.vmap`

The cyclogeostrophy function should be vmapable.
Currently, some numpy artifacts prevent it:

  • np.ma.masked_array should not be allowed
  • np.* should be replaced by jnp.*

Provide an executable script

  • how do we handle inputs/outputs?
    • use as arg to the script a yaml/json conf file describing how and where input data should be read and output data should be stored
  • should args include methods HP?

handling of land boundaries

Currently, "land" boundaries are handled in a "hard" way when using operators: if one of the two inputs (values) of the operator (interpolation or derivative) is not finite, the operator result is not finite as well.
We could rather "duplicate" the finite value, in order to produce a finite value if one of the two inputs is finite.

Output on A grid

Give the possibility to interpolate back the velocities to a A-grid (original SSH A-grid).
Should be straightforward.

Link to doc

In the readme, the link goes to the API part of the doc, which is empty. Maybe change the link?

Doc improvement

  • API:
    • specify args arrays dimensions
  • rename "Notebooks" title to "Examples"
  • rename "jaxparrow" title to "Overview"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.