5 个版本

0.2.2 2024年1月29日
0.2.1 2024年1月2日
0.2.0 2023年12月20日
0.1.1 2023年5月15日
0.1.0 2023年5月9日

#562解析实现

每月32次下载

MIT 许可证

75KB
1.5K SLoC

rweather-decoder

各种天气报告的解码器。

解码器是命令行界面(CLI)应用程序,将解码的报告存储在 JSON 文件中,适合进一步机器处理。

路线图

  • METAR / SPECI
    • 标题,风向,能见度,云,温度,露点,气压
    • 跑道视程,现在和最近的天气,风切变,海
    • TREND
    • REMARK
  • TAF
  • SYNOP
  • ACARS
  • ISD

安装

要使用此软件包,您需要在您的计算机上安装 Rust 和 Cargo。要安装 Rust,请访问官方 Rust 网站 https://rust-lang.net.cn/learn/get-started 并按照给定操作系统的说明进行安装。Rust 提供了一个安装程序,该程序将安装 Rust 和 Cargo。

然后运行以下命令

[filip@fractal ~]$ cargo install rweather-decoder

Cargo 将从 Rust 软件包存储库下载软件包并在您的系统上编译它。安装完成后,您就可以开始使用 CLI 解码器了。

用法

要解码 METAR 报告,请使用 decode-metar CLI 应用程序,查看帮助

[filip@fractal ~]$ decode-metar --help
rweather-decoder 0.2.2
CLI decoder of METAR reports

USAGE:
    decode-metar [FLAGS] [OPTIONS] <input-globs>... <output>

FLAGS:
    -h, --help            Prints help information
    -p, --pretty-print    Enable pretty-printing of output JSON file
    -q, --quiet           Quiet
    -V, --version         Prints version information

OPTIONS:
    -a, --anchor-time <anchor-time>    Anchor time (YYYY-MM-DD) for the plain file format. Specifies a datetime that is
                                       ideally close to that one when the report was actually published. If given, the
                                       decoded METAR day and time will be converted to a full datetime
    -f, --file-format <file-format>    METAR file format (noaa-metar-cycles, plain) [default: noaa-metar-cycles]

ARGS:
    <input-globs>...    Input files (glob patterns separated by space)
    <output>            Output JSON file. Same input reports will be deduplicated

decode-metar 工具目前支持两种 METAR 文件格式

  1. noaa-metar-cycles(默认)- 存储在文本文件中的 METAR 报告,这些文件是从位于 https://tgftp.nws.noaa.gov/data/observations/metar/cycles/ 的 NOAA METAR 循环页面下载的。
  2. plain - 每行一个报告的文本文件中的 METAR 报告。

解码后的 METAR 报告将作为对象的数组保存到输出 JSON 文件中。有关输出结构的更多详细信息,请参阅下面的“示例”部分,并参考在 https://docs.rs/rweather-decoder 可用的文档,该文档还包括 Rust 数据类型和 JSON 输出之间的差异。

示例

要检查最新的METAR报告,请访问 https://tgftp.nws.noaa.gov/data/observations/metar/cycles/。从那里您可以下载特定的文件,例如 16Z.TXT(循环16Z),并按照以下方式使用decode-metar CLI工具

[filip@fractal ~]$ decode-metar -p 16Z.TXT 16Z.json

解码后的METAR报告已保存到JSON文件 16Z.json。使用-p选项启用了输出的美化打印,以便于阅读。以下是一个解码的METAR报告示例,针对LFBD机场(波尔多-梅里尼亚克机场)

[
  {
    "station_id": "LFBD",
    "observation_time": {
      "value_type": "date_time",
      "value": "2023-05-12T16:00:00Z"
    },
    "is_corrected": false,
    "is_automated": true,
    "wind_from_direction": {
      "value_type": "exact",
      "value": 330.0,
      "units": "degT"
    },
    "wind_from_direction_range": {
      "value_type": "range",
      "value": [
        {
          "value_type": "exact",
          "value": 270.0
        },
        {
          "value_type": "exact",
          "value": 40.0
        }
      ],
      "units": "degT"
    },
    "wind_speed": {
      "value_type": "exact",
      "value": 16.0,
      "units": "kt"
    },
    "wind_gust": {
      "value_type": "exact",
      "value": 32.0,
      "units": "kt"
    },
    "prevailing_visibility": {
      "value_type": "above",
      "value": 10000.0,
      "units": "m"
    },
    "minimum_visibility": {
      "value_type": "exact",
      "value": 600.0,
      "units": "m"
    },
    "directional_visibilites": [],
    "runway_visual_ranges": [
      {
        "runway": "23",
        "visual_range": {
          "value_type": "exact",
          "value": 1100.0,
          "units": "m"
        },
        "trend": "decreasing"
      },
      {
        "runway": "05",
        "visual_range": {
          "value_type": "above",
          "value": 2300.0,
          "units": "m"
        },
        "trend": null
      },
      {
        "runway": "29",
        "visual_range": {
          "value_type": "exact",
          "value": 1800.0,
          "units": "m"
        },
        "trend": "decreasing"
      }
    ],
    "present_weather": [
      {
        "intensity": "heavy",
        "is_in_vicinity": false,
        "descriptors": [
          "thunderstorm"
        ],
        "phenomena": [
          "rain"
        ]
      },
      {
        "intensity": "moderate",
        "is_in_vicinity": false,
        "descriptors": [
          "patches"
        ],
        "phenomena": [
          "fog"
        ]
      }
    ],
    "clouds": [
      {
        "cover": "few",
        "height": {
          "value_type": "exact",
          "value": 2400.0,
          "units": "ft"
        },
        "cloud_type": null
      },
      {
        "cover": "broken",
        "height": {
          "value_type": "exact",
          "value": 3800.0,
          "units": "ft"
        },
        "cloud_type": null
      },
      {
        "cover": "broken",
        "height": {
          "value_type": "exact",
          "value": 4400.0,
          "units": "ft"
        },
        "cloud_type": null
      },
      {
        "cover": null,
        "height": null,
        "cloud_type": "cumulonimbus"
      }
    ],
    "temperature": {
      "value_type": "exact",
      "value": 15.0,
      "units": "degC"
    },
    "dew_point": {
      "value_type": "exact",
      "value": 11.0,
      "units": "degC"
    },
    "pressure": {
      "value_type": "exact",
      "value": 1018.0,
      "units": "hPa"
    },
    "recent_weather": [],
    "wind_shears": [],
    "sea_temperature": null,
    "sea_state": null,
    "wave_height": null,
    "trend_changes": [
      {
        "indicator": "temporary",
        "from_time": null,
        "to_time": null,
        "at_time": null,
        "wind_from_direction": null,
        "wind_from_direction_range": null,
        "wind_speed": null,
        "wind_gust": null,
        "prevailing_visibility": {
          "value_type": "exact",
          "value": 3000.0,
          "units": "m"
        },
        "minimum_visibility": null,
        "directional_visibilites": [],
        "weather": [
          {
            "intensity": "moderate",
            "is_in_vicinity": false,
            "descriptors": [
              "shower"
            ],
            "phenomena": [
              "rain"
            ]
          }
        ],
        "clouds": [
          {
            "cover": "broken",
            "height": {
              "value_type": "exact",
              "value": 1000.0,
              "units": "ft"
            },
            "cloud_type": null
          },
          {
            "cover": "scattered",
            "height": {
              "value_type": "exact",
              "value": 2000.0,
              "units": "ft"
            },
            "cloud_type": "cumulonimbus"
          },
          {
            "cover": "broken",
            "height": {
              "value_type": "exact",
              "value": 3000.0,
              "units": "ft"
            },
            "cloud_type": "towering_cumulus"
          }
        ]
      }
    ],
    "report": "LFBD 121600Z AUTO 33016G32KT 270V040 9999 0600 R23/1100D R05/P2300 R29/1800D +TSRA BCFG FEW024/// BKN038/// BKN044/// //////CB 15/11 Q1018 TEMPO 3000 SHRA BKN010 SCT020CB BKN030TCU"
  }
]

依赖项

~12MB
~276K SLoC