{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# earthkit-data\n", "\n", "本节介绍如何使用 earthkit-data 加载 GRIB2 要素场,并使用 cedarkit-maps 绘图。\n", "\n", "## 安装\n", "\n", "使用 conda 安装 earthkit-data\n", "\n", "```bash\n", "conda install -c conda-forge earthkit-data\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 准备\n", "\n", "导入需要的包" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import pandas as pd\n", "import earthkit.data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "设置绘图的数据参数,使用 CMA-MESO 2024 年 4 月 1 日 00 时次 024 时效数据。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "system_name = \"CMA-MESO\"\n", "data_type = \"cma_meso_3km/grib2/orig\"\n", "start_time = pd.to_datetime(\"2024-04-01 00:00:00\")\n", "forecast_time = pd.to_timedelta(\"24h\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 加载数据\n", "\n", "设置 GRIB2 数据文件路径\n", "\n", "> 注:可以使用 reki 库查找本地文件路径" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "file_path = '/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2'\n", "file_path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> 注:可以使用 reki 库查找本地文件路径" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [ "hide-input", "hide-output" ] }, "outputs": [ { "data": { "text/plain": [ "PosixPath('/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2')" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from reki.data_finder import find_local_file\n", "\n", "file_path_use_reki = find_local_file(\n", " data_type,\n", " start_time=start_time,\n", " forecast_time=forecast_time,\n", ")\n", "file_path_use_reki" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "使用 earthkit.data 加载 2 米温度要素场。" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | centre | \n", "shortName | \n", "typeOfLevel | \n", "level | \n", "dataDate | \n", "dataTime | \n", "stepRange | \n", "dataType | \n", "number | \n", "gridType | \n", "
---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "babj | \n", "2t | \n", "heightAboveGround | \n", "2 | \n", "20240401 | \n", "0 | \n", "24 | \n", "fc | \n", "None | \n", "regular_ll | \n", "
<xarray.DataArray 't2m' (time: 1, step: 1, heightAboveGround: 1,\n", " latitude: 1671, longitude: 2501)> Size: 17MB\n", "array([[[[[-0.7192993 , -0.75930786, -0.80929565, ..., -4.1693115 ,\n", " -2.879303 , -2.95932 ],\n", " [-3.6593018 , -3.6693115 , -2.2792969 , ..., -6.9193115 ,\n", " -6.3193054 , -3.729309 ],\n", " [-3.5493164 , -3.589325 , -0.85931396, ..., -7.609314 ,\n", " -7.479309 , -3.4393005 ],\n", " ...,\n", " [26.600677 , 26.600677 , 26.590698 , ..., 25.80069 ,\n", " 25.79068 , 25.970703 ],\n", " [26.590698 , 26.600677 , 26.590698 , ..., 25.7807 ,\n", " 25.7807 , 26.000702 ],\n", " [26.590698 , 26.590698 , 26.600677 , ..., 25.7807 ,\n", " 25.79068 , 25.970703 ]]]]], dtype=float32)\n", "Coordinates:\n", " * time (time) datetime64[ns] 8B 2024-04-01\n", " * step (step) timedelta64[ns] 8B 1 days\n", " * heightAboveGround (heightAboveGround) float64 8B 2.0\n", " * latitude (latitude) float64 13kB 60.1 60.07 60.04 ... 10.03 10.0\n", " * longitude (longitude) float64 20kB 70.0 70.03 70.06 ... 145.0 145.0\n", " valid_time (time, step) datetime64[ns] 8B ...
<xarray.DataArray 't2m' (latitude: 1671, longitude: 2501)> Size: 17MB\n", "array([[-0.7192993 , -0.75930786, -0.80929565, ..., -4.1693115 ,\n", " -2.879303 , -2.95932 ],\n", " [-3.6593018 , -3.6693115 , -2.2792969 , ..., -6.9193115 ,\n", " -6.3193054 , -3.729309 ],\n", " [-3.5493164 , -3.589325 , -0.85931396, ..., -7.609314 ,\n", " -7.479309 , -3.4393005 ],\n", " ...,\n", " [26.600677 , 26.600677 , 26.590698 , ..., 25.80069 ,\n", " 25.79068 , 25.970703 ],\n", " [26.590698 , 26.600677 , 26.590698 , ..., 25.7807 ,\n", " 25.7807 , 26.000702 ],\n", " [26.590698 , 26.590698 , 26.600677 , ..., 25.7807 ,\n", " 25.79068 , 25.970703 ]], dtype=float32)\n", "Coordinates:\n", " time datetime64[ns] 8B 2024-04-01\n", " step timedelta64[ns] 8B 1 days\n", " heightAboveGround float64 8B 2.0\n", " * latitude (latitude) float64 13kB 60.1 60.07 60.04 ... 10.03 10.0\n", " * longitude (longitude) float64 20kB 70.0 70.03 70.06 ... 145.0 145.0\n", " valid_time datetime64[ns] 8B ...