### Install the demo target plugin Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/target_plugin.rst Install the 'earthkit-data-demo-target' package to use the example SQL database target. ```shell pip install earthkit-data-demo-target ``` -------------------------------- ### Download Example Files Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/file_parts.ipynb Downloads a list of example GRIB files for use in subsequent operations. ```python import earthkit.data as ekd ekd.download_example_file(["test.grib", "test6.grib", "tuv_pl.grib"]) ``` -------------------------------- ### Download Example Files Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/multi_files.ipynb Downloads necessary example GRIB files for testing. Ensure these files are available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file(["test.grib", "test4.grib"]) ``` -------------------------------- ### Setup Local FDB and Write GRIB Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_fdb_lazy.ipynb This snippet sets up a local FDB directory and writes sample GRIB data to it. It requires earthkit-data and pyfdb to be installed. ```python import os import earthkit.data as ekd fdb_schema = "../default_fdb_schema" fdb_dir = "./_fdb_lazy_demo" os.makedirs(fdb_dir, exist_ok=True) config = { "type": "local", "engine": "toc", "schema": fdb_schema, "spaces": [{"handler": "Default", "roots": [{"path": fdb_dir}]}], } # get GRIB data on pressure levels and load it into a fieldlist fl_in = ekd.from_source("sample", "pl.grib").to_fieldlist() # write GRIB data to our local FDB fl_in.to_target("fdb", config=config) ``` -------------------------------- ### Install demo sources plugin Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/sources_plugin.rst Install the 'earthkit-data-demo-source' package to enable access to data from an SQL database. ```shell pip install earthkit-data-demo-source ``` -------------------------------- ### Install Demo PNG Encoder Plugin Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/encoder_plugin.rst Install the example PNG encoder plugin package using pip. This package demonstrates encoder plugin implementation. ```shell pip install earthkit-data-demo-encoder-png ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/docs.rst Install the necessary Python dependencies for building the documentation. This command should be run from the project root. ```shell pip install ".[docs]" cd docs ``` -------------------------------- ### Download Example Files Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/files.ipynb Ensures that the necessary example files for the tutorial are available locally. This is a prerequisite for subsequent file reading operations. ```python import earthkit.data as ekd ekd.download_example_file(["test.grib", "test4.grib", "test6.grib", "test.nc"]) ``` -------------------------------- ### Download Example GRIB File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_overview.ipynb Downloads a sample GRIB file for use in examples. Ensure the file is available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file("test6.grib") ``` -------------------------------- ### Install and Configure Pre-commit Hooks Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/setup.rst Install the pre-commit package and then install the git hooks. These hooks run quality checks on commits. ```shell pip install pre-commit pre-commit install ``` -------------------------------- ### Download Example GRIB File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_missing.ipynb Downloads an example GRIB file named 'missing.grib' for use in subsequent examples. Requires the earthkit-data library and numpy. ```python import numpy as np import earthkit.data as ekd ekd.download_example_file("missing.grib") ``` -------------------------------- ### Download Example ODB File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/odb/odb.ipynb Downloads a sample 'test.odb' file for use in subsequent examples. Ensure the file is available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file("test.odb") ``` -------------------------------- ### Download Example BUFR File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/bufr/bufr_synop.ipynb Ensures the necessary example BUFR file for SYNOP data is available for use. ```python import earthkit.data as ekd ekd.download_example_file("synop_10.bufr") ``` -------------------------------- ### Install a target plugin package Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/target_plugin.rst Install a custom target plugin package from PyPI. The package name must start with 'earthkit-data-'. ```shell pip install earthkit-data-my-target ``` -------------------------------- ### Download Example BUFR File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/bufr/bufr_temp.ipynb Ensures the example BUFR file 'temp_10.bufr' is available for use. This is a prerequisite for the subsequent steps. ```python import earthkit.data as ekd ekd.download_example_file("temp_10.bufr") ``` -------------------------------- ### Download Example TAR File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/tar_files.ipynb Downloads a sample TAR file for use in subsequent examples. Ensure the file is available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file("test_gribs.tar") ``` -------------------------------- ### Install earthkit-data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/shapefile/shapefile.ipynb Install the earthkit-data library using pip. The --quiet flag suppresses output during installation. ```python !pip install geopandas --quiet ``` -------------------------------- ### Download Example NetCDF File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/netcdf/netcdf_fieldlist.ipynb Downloads an example NetCDF file named 'tuv_pl.nc' for use in subsequent examples. Ensure the file is available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file("tuv_pl.nc") ``` -------------------------------- ### Install Demo Source Plugin Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/demo_sources_plugin.ipynb Install the demo-source plugin for earthkit-data. This is a prerequisite for using the demo-source functionality. ```python # !pip install --quiet earthkit-data-demo-source ``` -------------------------------- ### Install a sources plugin package Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/sources_plugin.rst Install a custom data source plugin using pip. The package name must start with 'earthkit-data-'. ```shell pip install earthkit-data-my-source ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/setup.rst Install the package in editable mode with all development dependencies. This command should be run from the root of the cloned repository. ```shell pip install -e .[dev] ``` -------------------------------- ### Install Project and Development Dependencies Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/conda.rst Install the earthkit-data project in editable mode with development dependencies and set up pre-commit hooks. ```shell pip install -e .[dev] pre-commit install ``` -------------------------------- ### Download and load GRIB example file Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_nearest_gridpoint.ipynb Download a sample GRIB file and load it into an earthkit-data FieldList object for further processing. ```python ekd.download_example_file("test.grib") ds = ekd.from_source("file", "test.grib").to_fieldlist() ``` -------------------------------- ### Install earthkit-data using pip Source: https://github.com/ecmwf/earthkit-data/blob/develop/README.md Install the earthkit-data package from PyPI using pip. This is the standard method for most users. ```bash pip install earthkit-data ``` -------------------------------- ### Download Example NetCDF File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/netcdf/netcdf.ipynb Downloads a sample NetCDF file for use in subsequent examples. Ensure the file is available before proceeding. ```python import earthkit.data as ekd ekd.download_example_file("test.nc") ``` -------------------------------- ### Install Development Dependencies (zsh) Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/setup.rst When using zsh, the square brackets in the installation command may need to be quoted to be interpreted correctly. ```shell pip install -e ."[dev]" ``` -------------------------------- ### Prepare Local GRIB Files Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/multi_files.ipynb Copies downloaded GRIB files into a specific directory for testing purposes. This step is for local setup. ```bash !test -d _grib_dir_no_sql || (mkdir -p _grib_dir_no_sql; cp -f test.grib test4.grib _grib_dir_no_sql/) ``` -------------------------------- ### Install PyTorch Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_array_namespace.ipynb Installs the PyTorch library, which is an optional dependency for earthkit-data. Ensure PyTorch is installed before using the 'torch' array namespace. ```bash !pip install torch --quiet ``` -------------------------------- ### Install earthkit-data with Specific Optional Package (mars) Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/installation.rst Installs earthkit-data with the 'mars' optional package, enabling access to the MARS data source. ```bash python3 -m pip install earthkit-data[mars] ``` -------------------------------- ### Load GRIB file and select parameter Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_time_series.ipynb Downloads an example GRIB file and loads it into an earthkit FieldList. It then selects fields for the 't' (temperature) parameter. ```python ekd.download_example_file("time_series.grib") ds_in = ekd.from_source("file", "time_series.grib").to_fieldlist() ds = ds_in.sel({"parameter.variable": "t"}) ``` -------------------------------- ### Install earthkit-data with Multiple Specific Optional Packages Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/installation.rst Installs earthkit-data with multiple specified optional packages, such as 'cds' and 'mars', to enable access to their respective data sources. ```bash python3 -m pip install earthkit-data[cds,mars] ``` -------------------------------- ### Install earthkit-data with All Optional Packages Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/installation.rst Installs earthkit-data along with all optional Python packages for extended data type and remote service support. Excludes 'geotiff' and 'zarr' by default. ```bash python3 -m pip install earthkit-data[all] ``` -------------------------------- ### Install earthkit-data with All Optional Packages (zsh) Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/installation.rst Installs earthkit-data with all optional packages, using quotes for the package specifier, which is necessary in zsh shells. ```bash python3 -m pip install "earthkit-data[all]" ``` -------------------------------- ### Install Minimal earthkit-data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/installation.rst Installs the latest release of earthkit-data with basic GRIB and NetCDF support. Requires Python 3.10+ and pip. ```bash python3 -m pip install earthkit-data ``` -------------------------------- ### Accessing Parameter Information via get() Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/field/parameter.rst Shows how to retrieve parameter information using the generic 'get' interface with the 'parameter.' prefix. ```python print(field.get("parameter.variable")) print(field.get("parameter.units")) ``` -------------------------------- ### Download and Load Shapefile Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/shapefile/shapefile.ipynb Download an example Shapefile archive and load it into an earthkit-data DataArray. This prepares the data for further processing. ```python import earthkit.data as ekd ekd.download_example_file("major_basins.zip") d = ekd.from_source("file", "./major_basins.zip") d ``` -------------------------------- ### Load Sample GRIB Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_to_file_pattern_target.ipynb Loads sample GRIB data from earthkit.data. Requires the earthkit.data library to be installed. ```python # get input GRIB data import earthkit.data as ekd ds = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() ``` -------------------------------- ### Use Registered Plugins with from_source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/plugins.rst Import and use the from_source function to load data using registered plugin types. Ensure the plugin package is installed. ```python from earthkit.data import from_source ds1 = from_source("foo", args1) ds2 = from_source("bar", args2) ``` -------------------------------- ### Load Sample Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/inputs/from_source.rst Downloads and loads pre-prepared sample data from earthkit's remote storage. Ideal for testing and examples. ```python import earthkit.data as ekd fl = ekd.from_source("sample", "storm_ophelia_wind_850.grib").to_fieldlist() fl.ls() ``` -------------------------------- ### Read data from SQL database using demo source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/sources_plugin.rst Read tabular data from an SQLite database using the 'demo-source' plugin. This example assumes 'test.db' is available. ```python import earthkit.data # assume you have test.db available ds = earthkit.data.from_source( "demo-source", "sqlite:///test.db", "select * from data;", parse_dates=["time"], ) df = ds.to_pandas() ``` -------------------------------- ### Load GRIB Data from File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_fdb_write.ipynb Reads temperature, wind, and other GRIB data from a local file into an earthkit-data FieldList. Requires the 'tuv_pl.grib' example file. ```python ekd.download_example_file("tuv_pl.grib") ds = ekd.from_source("file", "tuv_pl.grib").to_fieldlist() ds.head() ``` -------------------------------- ### Install an Encoder Plugin Package Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/encoder_plugin.rst Install a custom encoder plugin package using pip. The package name must start with 'earthkit-data-'. ```shell pip install earthkit-data-my-encoder ``` -------------------------------- ### Quick Start: Load and Convert Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/README.md Load data from a sample source and convert it to NumPy, Pandas, or Xarray formats. Ensure the earthkit.data library is imported. ```python import earthkit.data as ekd data = ekd.from_source("sample", "test.grib") arr = data.to_numpy() df = data.to_pandas() dataset = data.to_xarray() ``` -------------------------------- ### Environment Variable Precedence Example Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/config.rst Demonstrates how environment variables override configuration file settings for 'url-download-timeout'. Shows the output of get() and config.env() when an environment variable is set and when it is unset. ```bash export EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT=5 ``` ```python from earthkit.data import config print(config.get("url-download-timeout")) print(config.env()) config.set("url-download-timeout", 10) print(config.get("url-download-timeout")) ``` ```bash unset EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT ``` ```python from earthkit.data import config print(config.get("url-download-timeout")) ``` -------------------------------- ### Load GRIB file into FieldList Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_contents.ipynb Loads a GRIB file from a sample source into a FieldList object for further inspection. Ensure earthkit-data is installed. ```python import earthkit.data as ekd fl = ekd.from_source("sample", "test6.grib").to_fieldlist() ``` -------------------------------- ### Get Metadata Values Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/fieldlist.rst Demonstrates retrieving lists of metadata values for specified keys using 'component.key' or source-native keys. ```python >>> ds.get("parameter.variable") ['u', 'v', 't', ...] >>> ds.get(["parameter.variable", "vertical.level"]) [('u', 1000), ('v', 1000), ('t', 1000), ...] >>> ds.metadata("shortName") ['u', 'v', 't', ...] ``` -------------------------------- ### Setting up the FDB Target Directory and Configuration Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_to_fdb_target.ipynb This snippet shows how to create the FDB directory and define the configuration dictionary for a local FDB target. Ensure FDB and pyfdb are installed and the FDB5_DIR environment variable is set. ```python import os fdb_schema = "../default_fdb_schema" fdb_dir = "./_fdb_target_demo" os.makedirs(fdb_dir, exist_ok=True) config = { "type": "local", "engine": "toc", "schema": fdb_schema, "spaces": [{"handler": "Default", "roots": [{"path": fdb_dir}]}], } ``` -------------------------------- ### Load GRIB data to FieldList Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/xr_engine/xarray_cupy.ipynb Loads GRIB data from a sample source into an earthkit FieldList object. Ensure earthkit-data is installed. ```python # Get GRIB data on pressure levels import earthkit.data as ekd ds = ekd.from_source("sample", "pl.grib").to_fieldlist() ``` -------------------------------- ### Example PP File Data Output Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/pp/ukmo_pp.ipynb This snippet shows the typical output when reading data from a UK Met Office PP file. It represents latitude and longitude grid data. ```python Result: (array([[ 90., 90., 90., ..., 90., 90., 90.], [ 85., 85., 85., ..., 85., 85., 85.], [ 80., 80., 80., ..., 80., 80., 80.], ..., [-80., -80., -80., ..., -80., -80., -80.], [-85., -85., -85., ..., -85., -85., -85.], [-90., -90., -90., ..., -90., -90., -90.]], shape=(37, 72), dtype=float32), array([[-180., -175., -170., ..., 165., 170., 175.], [-180., -175., -170., ..., 165., 170., 175.], [-180., -175., -170., ..., 165., 170., 175.], ..., [-180., -175., -170., ..., 165., 170., 175.], [-180., -175., -170., ..., 165., 170., 175.], [-180., -175., -170., ..., 165., 170., 175.]], shape=(37, 72), dtype=float32)) ``` -------------------------------- ### Load and Inspect a Field Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/field/field_assign_constant_value.ipynb Loads a Field from a GRIB file and prints its parameter, level, and shape. This sets up an example Field for subsequent operations. ```python ds = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() t_fields = ds.sel({"parameter.variable": "t"}) t = t_fields[0] print(f"param: {t.parameter.variable()}, level: {t.vertical.level()}, shape: {t.geography.shape()}") ``` -------------------------------- ### Accessing S3 Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/inputs/from_source.rst This example demonstrates how to retrieve data from an S3 bucket using earthkit-data. It shows how to specify objects and parts to download, and then lists the metadata of the downloaded fields. ```APIDOC ## Accessing S3 Data This example demonstrates how to retrieve data from an S3 bucket using earthkit-data. It shows how to specify objects and parts to download, and then lists the metadata of the downloaded fields. ### Example ```python req = { "endpoint": "object-store.os-api.cci1.ecmwf.int", "bucket": "earthkit-test-data-public", "objects": [ {"object": "test6.grib", "parts": (0, 240)}, {"object": "tuv_pl.grib", "parts": (2400, 240)}, ], } fl = ekd.from_source("s3", req, anon=True).to_fieldlist() fl.ls() ``` ### Output ``` centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType 0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll 1 ecmf u isobaricInhPa 500 20180801 1200 0 an 0 regular_ll ``` ``` -------------------------------- ### Configure FDB Directory and Schema Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_fdb_write.ipynb Sets up the FDB directory and configuration, including schema and storage roots. Ensure the FDB schema path is valid. ```python fdb_schema = "../default_fdb_schema" fdb_dir = "./_fdb" os.makedirs(fdb_dir, exist_ok=True) config = { "type": "local", "engine": "toc", "schema": fdb_schema, "spaces": [{"handler": "Default", "roots": [{"path": fdb_dir}]}], } ``` -------------------------------- ### Load a PP file Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/pp/ukmo_pp.ipynb Load a sample PP file using earthkit.data.from_source. Requires the earthkit-data package. ```python import earthkit.data as ekd d = ekd.from_source("sample", "hadslp2.pp") d ``` -------------------------------- ### Load Multi-Field GRIB Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/field/field_arithmetic.ipynb Load a multi-field GRIB file into a FieldList object to prepare for arithmetic operations. This example shows how to load sample data and check the number of fields. ```python ds = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() len(ds) ``` -------------------------------- ### Create and Use File-Pattern Target Object Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_to_file_pattern_target.ipynb Demonstrates the basic usage of a 'file-pattern' target object. It shows how to create a target, write data to it, and close it. The context manager pattern is also shown for automatic closing. ```python # basic usage target = ekd.create_target("file-pattern", out_pattern) target.write(ds) target.close() # can be used as a context manager, no need to call close() in the end with ekd.create_target("file-pattern", out_pattern) as target: target.write(ds) ``` -------------------------------- ### Create Test SQLite Database Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/demo_sources_plugin.ipynb Create a SQLite database named '_test.db' with a 'data' table and populate it with sample data. This database will be used by the demo-source plugin. ```python import os import sqlite3 import earthkit.data as ekd DATA = [ (50, 3.3, "2001-01-01 00:00:00", 4.9), (51, -3, "2001-01-02 00:00:00", 7.3), (50.5, -1.8, "2001-01-03 00:00:00", 5.5), ] def make_db(): if os.path.exists("_test.db"): os.unlink("_test.db") conn = sqlite3.connect("_test.db") c = conn.cursor() c.execute( """CREATE TABLE data( lat NUMBER, lon NUMBER, time TEXT, value NUMBER)""" ) c.executemany("INSERT INTO data VALUES(?,?,?,?);", DATA) conn.commit() make_db() ``` -------------------------------- ### Build HTML Documentation Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/docs.rst Build the HTML version of the documentation. This command should be executed from the 'docs' directory. ```shell make html ``` -------------------------------- ### Load sample .pp file using Iris source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/experimental/sources.rst Load a sample .pp file using the 'sample' source, demonstrating Iris data access. ```python >>> import earthkit.data as ekd >>> ds = ekd.from_source("sample", "air_temp.pp") >>> ds.ls() variable level valid_datetime units 0 air_temperature None 1998-12-01T00:00:00 K ``` -------------------------------- ### Create Temporary Configuration with Arguments Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/config.ipynb Create a temporary configuration context with specific settings applied immediately. The provided arguments override existing settings only within the context. ```python with config.temporary("url-download-timeout", 12): print(config.get("url-download-timeout")) print(config.get("url-download-timeout")) ``` -------------------------------- ### Install earthkit-data using conda Source: https://github.com/ecmwf/earthkit-data/blob/develop/README.md Install the earthkit-data package from the conda-forge channel. This method is recommended for users who prefer conda environments. ```bash conda install earthkit-data -c conda-forge ``` -------------------------------- ### Set up a Dask Local Cluster Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/xr_engine/xarray_engine_chunks_on_dask_cluster.ipynb Initializes a local Dask cluster and client. This is the first step to enable distributed computing. ```python from dask.distributed import LocalCluster cluster = LocalCluster() client = cluster.get_client() client ``` -------------------------------- ### Create and Inspect a FieldList Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/fieldlist.rst Demonstrates how to create a FieldList from a source and check its length and individual fields. ```python >>> import earthkit.data as ekd >>> ds = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() >>> len(ds) 18 >>> ds[0] GribField(u, 1000, 2020-01-01 00:00, 0, None, None) ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/setup.rst Create a Python virtual environment named 'earthkit-dev' and activate it. Replace 'YOUR_VENVS_DIR' with your preferred directory for virtual environments. ```shell cd YOUR_VENVS_DIR python -m venv earthkit-dev source earthkit-dev/bin/activate ``` -------------------------------- ### Accessing Geography Information via get() Method Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/field/geography.rst Shows how to retrieve geography information using the generic 'get' interface with a 'geography.' prefix. ```python >>> field.get("geography.area") (70, -20, 35, 40) >>> field.get("geography.shape") (19, 36) ``` -------------------------------- ### Accessing Field metadata using get() method Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/release-notes/migration_1.0.0.rst Demonstrates accessing field metadata using the `get()` method with a dot notation for component attributes. ```python # use the get() method f.get("time.base_datetime") ``` -------------------------------- ### Get Cache Directory (Off Policy) Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/caching.rst Demonstrates how to get the temporary cache directory when the 'off' cache policy is enabled. This directory is unmanaged and cleaned up on session exit. ```python >>> from earthkit.data import cache, config >>> config.set("cache-policy", "off") >>> cache.directory() '/var/folders/ng/g0zkhc2s42xbslpsywwp_26m0000gn/T/tmp_5bf5kq8' ``` -------------------------------- ### Get the number of resulting xarray Datasets Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/experimental/ekd_test_on_cds_era5_single_level.ipynb After splitting data using `to_xarray`, check the number of resulting xarray Datasets by getting the length of the `dss` list. ```python len(dss) ``` -------------------------------- ### Accessing raw GRIB metadata using get() with 'metadata.' prefix Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/release-notes/migration_1.0.0.rst To access raw metadata keys from the original GRIB message, use the `get()` method with the `metadata.` prefix. ```python f.get("metadata.shortName") ``` -------------------------------- ### Access Vertical Component via get() Method Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/field/vertical.rst Retrieve information about the vertical component using the generic get() method with a "vertical." prefix. This provides an alternative to direct attribute access. ```python >>> field.get("vertical.level") 1000 >>> field.get("vertical.level_type") 'pressure' ``` -------------------------------- ### Accessing Time Component via get() Method Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/field/time.rst Shows how to retrieve time component information using the generic get() method with a 'time.' prefix. This provides an alternative way to access temporal data. ```python print(field.get("time.base_datetime")) print(field.get("time.step")) ``` -------------------------------- ### Basic usage of the Target object Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_to_file_target.ipynb Demonstrates the basic creation and usage of a `Target` object for writing a FieldList to a file, including explicit closing and context manager usage. ```python # basic usage target = ekd.create_target("file", "_res_t.grib") target.write(ds) target.close() # can be used as a context manager, no need to call close() in the end with ekd.create_target("file", "_res_t.grib") as target: target.write(ds) # a filedlist can be written field by field into the target with ekd.create_target("file", "_res_t.grib") as target: for f in ds: target.write(f) ``` -------------------------------- ### Get current cache directory Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/cache.ipynb Retrieves the current path of the cache directory. ```python cache.directory() ``` -------------------------------- ### Get Datetime Metadata Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/dict/list_of_dicts_overview.ipynb Retrieves the 'valid_datetime' metadata for a specific data field. ```python ds[0].time.valid_datetime() ``` -------------------------------- ### Get encoded data as bytes Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_encoder.ipynb Retrieve the encoded GRIB data as a bytes object. ```python # get message as bytes r.to_bytes()[:10] ``` -------------------------------- ### Create and Use a GRIB Encoder Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/encoders/encoders.rst Demonstrates creating a GRIB encoder with a template and encoding data into a GRIB file. Requires the 'create_encoder' function and a 'field' template object. ```python >>> enc = create_encoder("grib", template=field) >>> result = enc.encode(values=arr, shortName="2t", step=6) >>> result.to_file(open("out.grib", "wb")) ``` -------------------------------- ### Configure Demo PNG Encoder Entry Point Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/encoder_plugin.rst Define the entry point for the demo PNG encoder in pyproject.toml, mapping 'demo-encoder-png' to the DemoEncoderPng class. ```toml entry-points."earthkit.data.encoders".demo-encoder-png = "earthkit_data_demo_encoder_png:DemoEncoderPng" ``` -------------------------------- ### Get geographical coordinates Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/pp/ukmo_pp.ipynb Obtain latitude and longitude information for a field from an Iris FieldList. ```python fl[0].geography.latlons() ``` -------------------------------- ### Get current cache policy Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/cache.ipynb Retrieves the current setting for the cache policy from the configuration. ```python config.get("cache-policy") ``` -------------------------------- ### Mix High-Level and Raw Metadata Keys Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_modify_metadata.ipynb Demonstrates setting metadata by mixing high-level keys (e.g., 'parameter.variable') with raw GRIB keys (e.g., 'metadata.level'). The high-level keys are applied first, followed by the raw keys. ```python f1 = f.set({"parameter.variable": "u", "parameter.units": "m/s", "metadata.level": 500}) f1.ls() ``` -------------------------------- ### Get time steps Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_time_series.ipynb Retrieves the time steps available in the selected GRIB data. ```python ds.get("time.step") ``` -------------------------------- ### Download and Read GeoJSON File Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/geojson/geojson_geopandas.ipynb Downloads an example GeoJSON file and reads it into an earthkit-data object. ```python ekd.download_example_file("NUTS_RG_20M_2021_3035.geojson") d = ekd.from_source("file", "NUTS_RG_20M_2021_3035.geojson") d ``` -------------------------------- ### Load and list fields Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/xr_engine/xarray_engine_remapping.ipynb Load a GRIB file into a FieldList and display its contents with extra metadata. ```python ds_fl = ekd.from_source("sample", "ens_cf_pf.grib").to_fieldlist() ds_fl.ls(extra_keys="metadata.dataType") ``` -------------------------------- ### Get shape of a field Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/pp/ukmo_pp.ipynb Retrieve the shape of a specific field (e.g., the first field) from an Iris FieldList. ```python fl[0].shape ``` -------------------------------- ### Inspect Cache Policy, Directory, Size, and Entries Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/caching.rst Demonstrates how to use various methods of the cache object to inspect its current policy, directory path, total size in bytes, and a dump of its entries. ```python >>> from earthkit.data import cache >>> cache.policy.name 'user' >>> cache.directory() '/var/folders/ng/g0zkhc2s42xbslpsywwp_26m0000gn/T/earthkit-data-myusername' >>> cache.size() 846785699 >>> cache.summary_dump_database() (40, 846785699) >>> d = cache.entries() >>> len(d) 40 >>> d[0].get("creation_date") '2023-10-30 14:48:31.320322' ``` -------------------------------- ### Get Latitudes and Longitudes Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/dict/list_of_dicts_overview.ipynb Retrieves the latitude and longitude grid for a specific data field within the FieldList. ```python ds[0].geography.latlons() ``` -------------------------------- ### Display FieldList Summary Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/fieldlist.rst Shows how to get a tabular summary of commonly used metadata keys for a FieldList. ```python >>> ds.ls() # in Jupyter notebook, this is rendered as a table >>> print(ds.ls()) # in terminal, an extra print() is needed to render the table ``` -------------------------------- ### Load GRIB and Select Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_to_netcdf.ipynb Loads a GRIB file and selects temperature fields using earthkit-data. ```python import earthkit.data as ekd from earthkit.data.utils.summary import ncdump ekd.download_example_file("tuv_pl.grib") # we only select the temperature fields ds = ekd.from_source("file", "tuv_pl.grib").to_fieldlist().sel({"parameter.variable": "t"}) ``` -------------------------------- ### Load GRIB data and list fields Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/projection.ipynb Loads GRIB data from a sample file and displays a list of fields. Requires the earthkit.data library. ```python import earthkit.data as ekd ``` ```python efas = ekd.from_source("sample", "efas.grib").to_fieldlist() efas.ls() ``` -------------------------------- ### Get Projection Information Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/geotiff/geotiff.ipynb Retrieves and displays the coordinate reference system (CRS) and projection details for the GeoTIFF data. ```python ds.geography.projection() ``` -------------------------------- ### Get Shape of a Field Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/geotiff/geotiff.ipynb Retrieves the shape (dimensions) of a specific field (e.g., the first band) from the field list. ```python ds[0].shape ``` -------------------------------- ### Convert PP data to Iris FieldList Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/pp/ukmo_pp.ipynb Load PP data into an Iris FieldList. This requires 'scitools-iris' and 'ncdata' to be installed. ```python fl = d.to_fieldlist() ``` -------------------------------- ### Configure entry points in pyproject.toml Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/plugins/target_plugin.rst Define the entry point for your custom target in the pyproject.toml file. This maps a target name to your custom class. ```toml entry-points."earthkit.data.targets".my-target = "earthkit_data_my_target:MyClass" ``` -------------------------------- ### Run only notebook tests Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/development/tests.rst Execute only the tests related to notebook examples. Uses the '-m notebook' flag to select these tests. ```shell pytest -v -m notebook ``` -------------------------------- ### Display current configuration Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/config_env_vars.ipynb Print the entire configuration object to see all settings, their sources (config file or environment variable), and current values. Environment variable sources are clearly indicated. ```python config ``` -------------------------------- ### Get Number of Fields Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_overview.ipynb Determines the total number of fields present in the FieldList. This is a common operation to understand the size of the dataset. ```python len(ds) ``` -------------------------------- ### Query SQLite Database with Demo Source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/misc/demo_sources_plugin.ipynb Load data from the created SQLite database using the 'demo-source' plugin and earthkit-data. The data is queried using a SQL statement and parsed dates are specified. ```python ds = ekd.from_source( "demo-source", "sqlite:///_test.db", "select * from data;", parse_dates=["time"], ) df = ds.to_pandas() df ``` -------------------------------- ### Get Specific Metadata Field Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/dict/list_of_dicts_overview.ipynb Extracts all values for a specified metadata key (e.g., 'vertical.level') across all fields in the FieldList. ```python ds.get("vertical.level") ``` -------------------------------- ### Load GRIB data into a FieldList Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_selection.ipynb Loads GRIB data from a sample source and converts it into a FieldList. This is the initial step before performing any metadata selections. ```python import earthkit.data as ekd ds = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() len(ds) ``` -------------------------------- ### Get Number of Messages in Feature List Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/bufr/bufr_temp.ipynb Retrieves the total number of BUFR messages contained within the feature list. ```python len(fl) ``` -------------------------------- ### Get User Cache Directory Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/caching.rst Retrieves the path to the user-defined cache directory. This is useful for understanding where cached data is stored. ```python >>> from earthkit.data import config >>> config.get("user-cache-directory") # Cache directory has been modified /big-disk/earthkit-data-cache ``` -------------------------------- ### List available data in the source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/gribjump.ipynb Use the ls() method on the GribJump source to display metadata about the available fields, including parameter, level, and time information. ```python source.ls() ``` -------------------------------- ### Load and inspect sample GRIB data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/target/grib_encoder.ipynb Load sample GRIB data from a source and inspect its contents using ls(). ```python # get some input GRIB data ds = ekd.from_source("sample", "test.grib").to_fieldlist() ds[0].ls() ``` -------------------------------- ### Load data from a source Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/field/field_overview.ipynb Load data from a specified source, such as a sample GRIB file. The result is a Dataset object. ```python ds = ekd.from_source("sample", "test.grib") ds ``` -------------------------------- ### Load and Inspect GRIB Data Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/grib/grib_lat_lon_value_ll.ipynb Load a GRIB file from a sample source and select a specific parameter ('t'). The .ls() method displays metadata about the fields. ```python ds_in = ekd.from_source("sample", "tuv_pl.grib").to_fieldlist() ds = ds_in.sel({"parameter.variable": "t"}) ds.ls() ``` -------------------------------- ### File Pattern Source with hive_partitioning=False Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/misc/patterns.rst Use this when hive_partitioning is False to specify all possible values for pattern parameters. The file paths are constructed from the Cartesian product of these values. ```python from_source( "file-pattern", "mydir/{year}/myfile_{param}.grib", year=[2023, 2024], param=["t", "r"], ) ``` -------------------------------- ### Load a Single GRIB File from a URL Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/url.ipynb Use the 'url' type to load a single GRIB file directly from a web address. Ensure the URL points to a valid GRIB file. ```python import earthkit.data as ekd fs = ekd.from_source("url", "https://sites.ecmwf.int/repository/earthkit-data/examples/test.grib") ``` -------------------------------- ### Accessing Field Metadata Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/field/field.rst Demonstrates accessing metadata components and their keys using direct attribute access and the generic 'get' method. ```python >>> import earthkit.data as ekd >>> field = ekd.from_source("sample", "test.grib").to_fieldlist()[0] >>> field.parameter.variable() '2t' >>> field.get("parameter.variable") '2t' >>> field.vertical.level() 0 >>> field.get("time.base_datetime") datetime.datetime(2020, 1, 1, 0, 0) ``` -------------------------------- ### Accessing Configuration Options Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/concepts/config.rst Use the Python API to retrieve configuration values. Environment variables take precedence over values stored in the configuration file. ```python from earthkit.data import config # Access a configuration option print(config.get("url-download-timeout")) ``` -------------------------------- ### Create Data Source with URL Pattern Source: https://github.com/ecmwf/earthkit-data/blob/develop/docs/source/tutorials/source/url.ipynb Use `ekd.from_source` with a URL pattern to specify data access. Define custom date formats using `:date()` and provide a dictionary for pattern values. ```python import datetime fs = ekd.from_source( "url-pattern", "https://sites.ecmwf.int/repository/earthkit-data/test-data/test_{my_date:date(%Y-%m-%d)}_{name}.grib", {"my_date": datetime.datetime(2020, 5, 13), "name": ["t2", "msl"]}, ) fs.to_fieldlist().ls() ```