Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Oct 25, 2024
1 parent 159100d commit 54a9b12
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/apis/code/state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import datetime

import numpy as np

from anemoi.inference.runner import DefaultRunner

# Create a runner with the checkpoint file
runner = DefaultRunner("checkpoint.ckpt")

# Select a starting date
date = datetime.datetime(2024, 10, 25)

# Assuming that the initial conditions requires two
# dates, e.g. T0 and T-6

lagged = 2

# Define the grid

latitudes = np.linspace(90, -90, 181) # 1 degree resolution
longitudes = np.linspace(0, 359, 360)

number_of_points = len(latitudes) * len(longitudes)
latitudes, longitudes = np.meshgrid(latitudes, longitudes)

# Create the initial state

input_state = {
"date": date,
"latitudes": latitudes,
"longitudes": longitudes,
"fields": {
"2t": np.random.rand(lagged, number_of_points),
"msl": np.random.rand(lagged, number_of_points),
"z_500": np.random.rand(lagged, number_of_points),
...: ...,
},
}

# Run the model

for state in runner.run(input_state=input_state, lead_time=240):
# This is the date of the new state
print("New state:", state["date"])

# This is value of a field for that date
print("Forecasted 2t:", state["fields"]["2t"])
16 changes: 16 additions & 0 deletions docs/apis/level1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _api_level1:

####################
NumPy to NumPy API
####################

The simplest way to run a inference from a checkpoint is to provide the
initial state as a dictionary containing NumPy arrays for each input
variable.

You then create a Runner object and call the `run` method, which will
yield the state at each time step. Below is a simple code example to
illustrate this:

.. literalinclude:: code/state.py
:language: python
5 changes: 5 additions & 0 deletions docs/apis/level2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _api_level2:

#####################
Object oriented API
#####################
5 changes: 5 additions & 0 deletions docs/apis/level3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _api_level1:

##################
Command line API
##################
8 changes: 8 additions & 0 deletions docs/cli/inspect.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inspect
==========

.. argparse::
:module: anemoi.inference.__main__
:func: create_parser
:prog: anemoi-inference
:path: inspect
5 changes: 5 additions & 0 deletions docs/cli/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ The commands are:
.. toctree::
:maxdepth: 1

run
metadata
inspect
patch
requests


.. argparse::
:module: anemoi.inference.__main__
Expand Down
8 changes: 8 additions & 0 deletions docs/cli/patch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
patch
==========

.. argparse::
:module: anemoi.inference.__main__
:func: create_parser
:prog: anemoi-inference
:path: patch
8 changes: 8 additions & 0 deletions docs/cli/requests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
requests
==========

.. argparse::
:module: anemoi.inference.__main__
:func: create_parser
:prog: anemoi-inference
:path: requests
8 changes: 8 additions & 0 deletions docs/cli/run.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
run
==========

.. argparse::
:module: anemoi.inference.__main__
:func: create_parser
:prog: anemoi-inference
:path: run
15 changes: 15 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ of the *Anemoi* packages.

installing

**Tree levels of APIs**

- :doc:`apis/level1`
- :doc:`apis/level2`
- :doc:`apis/level3`

.. toctree::
:maxdepth: 1
:hidden:
:caption: APIs

apis/level1
apis/level2
apis/level3

*********
Modules
*********
Expand Down
8 changes: 8 additions & 0 deletions docs/modules/checkpoint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
############
checkpoint
############

.. automodule:: anemoi.inference.checkpoint
:members:
:no-undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/modules/forcings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##########
forcings
##########

.. automodule:: anemoi.inference.forcings
:members:
:no-undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/modules/input.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#######
input
#######

.. automodule:: anemoi.inference.input
:members:
:no-undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/modules/metadata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##########
metadata
##########

.. automodule:: anemoi.inference.metadata
:members:
:no-undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/modules/output.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
########
output
########

.. automodule:: anemoi.inference.output
:members:
:no-undoc-members:
:show-inheritance:
File renamed without changes.

0 comments on commit 54a9b12

Please sign in to comment.