Skip to content

Commit 15c9d7d

Browse files
committed
Initial command and docs
1 parent fd0877c commit 15c9d7d

File tree

4 files changed

+491
-0
lines changed

4 files changed

+491
-0
lines changed

docs/cli/introduction.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ The commands are:
1919
- :ref:`Validate Command <validate-command>`
2020
- :ref:`Patch Command <patch-command>`
2121
- :ref:`Requests Command <requests-command>`
22+
- :ref:`Redefine Command <redefine-command>`

docs/cli/redefine.rst

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
.. _redefine-command:
2+
3+
Redefine Command
4+
===============
5+
6+
With this command, you can redefine the graph of a checkpoint file.
7+
This is useful when you want to change / reconfigure the local-domain of a model, or rebuild with a new graph.
8+
9+
We should caution that such transfer of the model from one graph to
10+
another is not guaranteed to lead to good results. Still, it is a
11+
powerful tool to explore generalisability of the model or to test
12+
performance before starting fine tuning through transfer learning.
13+
14+
This will create a new checkpoint file with the updated graph, and optionally save the graph to a file.
15+
16+
Subcommands allow for a graph to be made from a lat/lon coordinate file, bounding box, or from a defined graph config.
17+
18+
*********
19+
Usage
20+
*********
21+
22+
.. code-block:: bash
23+
24+
% anemoi-inference redefine --help
25+
26+
Redefine the graph of a checkpoint file.
27+
28+
positional arguments:
29+
path Path to the checkpoint.
30+
31+
options:
32+
-h, --help show this help message and exit
33+
-g GRAPH, --graph GRAPH
34+
Path to graph file to use
35+
-y GRAPH_CONFIG, --graph_config GRAPH_CONFIG
36+
Path to graph config to use
37+
-ll LATLON, --latlon LATLON
38+
Path to coordinate npy, should be of shape (N, 2) with latitudes and longitudes.
39+
-c COORDS COORDS COORDS COORDS COORDS, --coords COORDS COORDS COORDS COORDS COORDS
40+
Coordinates, (North West South East Resolution).
41+
-gr GLOBAL_RESOLUTION, --global_resolution GLOBAL_RESOLUTION
42+
Global grid resolution required with --coords, (e.g. n320, o96).
43+
--save-graph SAVE_GRAPH
44+
Path to save the updated graph.
45+
--output OUTPUT Path to save the updated checkpoint.
46+
47+
48+
*********
49+
Examples
50+
*********
51+
52+
Here are some examples of how to use the `redefine` command:
53+
54+
#. Using a graph file:
55+
56+
.. code-block:: bash
57+
58+
anemoi-inference redefine path/to/checkpoint --graph path/to/graph
59+
60+
#. Using a graph configuration:
61+
62+
.. code-block:: bash
63+
64+
anemoi-inference redefine path/to/checkpoint --graph_config path/to/graph_config
65+
66+
.. note::
67+
The configuration of the existing graph can be found using:
68+
69+
.. code-block:: bash
70+
71+
anemoi-inference metadata path/to/checkpoint -get config.graph ----yaml
72+
73+
#. Using latitude/longitude coordinates:
74+
This lat lon file should be a numpy file of shape (N, 2) with latitudes and longitudes.
75+
76+
It can be easily made from a list of coordinates as follows:
77+
78+
.. code-block:: python
79+
80+
import numpy as np
81+
coords = np.array(np.meshgrid(latitudes, longitudes)).T.reshape(-1, 2)
82+
np.save('path/to/latlon.npy', coords)
83+
84+
Once created,
85+
86+
.. code-block:: bash
87+
88+
anemoi-inference redefine path/to/checkpoint --latlon path/to/latlon.npy
89+
90+
#. Using bounding box coordinates:
91+
92+
.. code-block:: bash
93+
94+
anemoi-inference redefine path/to/checkpoint --coords North West South East Resolution
95+
96+
i.e.
97+
98+
.. code-block:: bash
99+
100+
anemoi-inference redefine path/to/checkpoint --coords 30.0 -10.0 20.0 0.0 0.1/0.1 --global_resolution n320
101+
102+
103+
All examples can optionally save the updated graph and checkpoint using the `--save-graph` and `--output` options.
104+
105+
***************************
106+
Complete Inference Example
107+
***************************
108+
109+
For this example we will redefine a checkpoint using a bounding box and then run inference
110+
111+
112+
Redefine the checkpoint
113+
-----------------------
114+
115+
.. code-block:: bash
116+
117+
anemoi-inference redefine path/to/checkpoint --coords 30.0 -10.0 20.0 0.0 0.1/0.1 --global_resolution n320 --save-graph path/to/updated_graph --output path/to/updated_checkpoint
118+
119+
Create the inference config
120+
---------------------------
121+
122+
If you have an input file of the expected shape handy use it in place of the input block, here we will show
123+
how to use MARS to handle the regridding.
124+
125+
.. note::
126+
Using the `anemoi-plugins-ecmwf-inference <https://github.com/ecmwf/anemoi-plugins-ecmwf>`_ package, preprocessors are available which can handle the regridding for you from other sources.
127+
128+
.. code-block:: yaml
129+
130+
checkpoint: path/to/updated_checkpoint
131+
date: -2
132+
133+
input:
134+
cutout:
135+
lam_0:
136+
mars:
137+
grid: 0.1/0.1 # RESOLUTION WE SET
138+
area: 30.0/-10.0/20.0/0.0 # BOUNDING BOX WE SET, N W S E
139+
global:
140+
mars:
141+
grid: n320 # GLOBAL RESOLUTION WE SET
142+
143+
144+
Run inference
145+
-----------------
146+
147+
.. code-block:: bash
148+
149+
anemoi-inference run path/to/updated_checkpoint
150+
151+
152+
**********
153+
Reference
154+
**********
155+
156+
.. argparse::
157+
:module: anemoi.inference.__main__
158+
:func: create_parser
159+
:prog: anemoi-inference
160+
:path: redefine

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ You may also have to install pandoc on MacOS:
153153
cli/inspect
154154
cli/patch
155155
cli/requests
156+
cli/redefine
156157

157158
.. toctree::
158159
:maxdepth: 1

0 commit comments

Comments
 (0)