ecmwf / earthkit-regrid

1 stars 0 forks source link

Allow using user defined local matrix source #12

Closed sandorkertesz closed 4 months ago

sandorkertesz commented 4 months ago

This PR adds the matrix_source option to use a local user defined matrix inventory for interpolate:

import earthkit.regrid
import numpy as np

my_db_path = "my_local_db"

in_array = np.ones(6599680)
res_array = earthkit.regrid.interpolate(in_array, 
                                {"grid": "O1280"}, 
                                {"grid": [0.25,0.25]}, 
                                matrix_source=my_db_path)

When matrix_source is None (the default) the default inventory hosted on Nexus is used.

Also added the tool tools/make-local-db.pyto create a local matrix inventory by subsetting the default one.

usage: make_local_db.py [-h] [--conf CONF] [--out-dir OUT_DIR] [--allow-missing] [--strict] [--dry-run] [--log-level {debug,info,warn,error,critical}]

options:
  -h, --help            show this help message and exit
  --conf CONF           configuration file path
  --out-dir OUT_DIR     output directory path
  --allow-missing       do not fail when a required grid combination is not supported
  --strict              fail when out_dir is not empty
  --dry-run             perform test run without data processing
  --log-level {debug,info,warn,error,critical}
                        set the logging level (default=info)

An example:

 python make_local_db.py --conf=local_conf.yaml --out-dir=my_local_db --strict

local_conf.yaml

- input:
    grid: "O1280"
  output:
    grid: [0.1, 0.1]
- input:
    grid: "O1280"
  output:
    grid: [0.125, 0.125]
- input:
    grid: "O1280"
  output:
    grid: [0.25, 0.25]