File tree Expand file tree Collapse file tree
src/anemoi/datasets/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ .. _extract_command :
2+
3+ Extract Command
4+ ===============
5+
6+ The ``extract `` command extracts constant fields and/or climatologies from a
7+ dataset and writes them to a NetCDF file following CF conventions.
8+
9+ This is useful for producing ancillary files needed during inference, such as
10+ orography (a constant) or monthly mean sea-surface temperature (a climatology).
11+
12+ The ``DATASET `` argument can be:
13+
14+ - A dataset name or path (resolved by ``open_dataset ``).
15+ - A YAML or JSON file (ending in ``.yaml `` or ``.json ``) whose content is
16+ loaded and passed to ``open_dataset ``.
17+
18+ Usage examples
19+ --------------
20+
21+ Extract a constant field:
22+
23+ .. code :: console
24+
25+ $ anemoi-datasets extract --constant z dataset-name output.nc
26+
27+ Extract multiple constants:
28+
29+ .. code :: console
30+
31+ $ anemoi-datasets extract --constant z --constant lsm dataset-name output.nc
32+
33+ Extract climatologies (one value per month):
34+
35+ .. code :: console
36+
37+ $ anemoi-datasets extract --climatology sst --climatology ci dataset-name output.nc
38+
39+ Mix constants and climatologies:
40+
41+ .. code :: console
42+
43+ $ anemoi-datasets extract --constant z --climatology sst dataset-name output.nc
44+
45+ Use a YAML file to specify the dataset:
46+
47+ .. code :: console
48+
49+ $ anemoi-datasets extract --constant z dataset.yaml output.nc
50+
51+ .. argparse ::
52+ :module: anemoi.datasets.__main__
53+ :func: create_parser
54+ :prog: anemoi-datasets
55+ :path: extract
Original file line number Diff line number Diff line change @@ -40,3 +40,4 @@ The commands are:
4040 cli/patch
4141 cli/compare-lam
4242 cli/validate
43+ cli/extract
Original file line number Diff line number Diff line change @@ -53,7 +53,20 @@ def run(self, args: Any) -> None:
5353
5454 from anemoi .datasets import open_dataset
5555
56- ds = open_dataset (args .dataset )
56+ dataset = args .dataset
57+
58+ if dataset .endswith (".yaml" ) or dataset .endswith (".json" ):
59+ import json
60+
61+ import yaml
62+
63+ with open (dataset ) as f :
64+ if dataset .endswith (".yaml" ):
65+ dataset = yaml .safe_load (f )
66+ else :
67+ dataset = json .load (f )
68+
69+ ds = open_dataset (dataset )
5770
5871 constants = args .constant
5972 climatologies = args .climatology
You can’t perform that action at this time.
0 commit comments