hydro_radar_base_rs/lib.rs
1//! # hydro-radar-base-rs
2//!
3//! 水利测雨雷达 + CMA 标准基数据(QXT 653-2022)解析库。
4//!
5//! 两种格式 → 统一的 [`parser::RadarData`](parser::RadarData) 结构
6//! (Sweep-centric 体数据;双偏振矩 ZH/V/W/ZDR/KDP/ΦDP/CC/RF…):
7//!
8//! - **水利格式**:`RadarParser::parse_file`(卷标 "RD"/"GD",binrw 逐头解析,
9//! bz2 自动解压)
10//! - **CMA 标准格式**:`cma_parser::parse_cma_bytes`(魔数判定
11//! [`cma_parser::is_cma_format`];数据类型码对齐 PyCINRAD `dtype_corr`)
12//!
13//! ## 用法
14//!
15//! ```no_run
16//! use hydro_radar_base_rs::RadarParser;
17//!
18//! let data = RadarParser::parse_file("VOLZO074_20250811080000.bin.bz2")?;
19//! println!("站 {} 共 {} 层", data.station_info.site_name(), data.layer_count());
20//! let zh = data.get_product_arc(
21//! hydro_radar_base_rs::types::VariableType::HorizontalReflectivity, 0,
22//! );
23//! # Ok::<(), hydro_radar_base_rs::error::RadarError>(())
24//! ```
25//!
26//! 模块名与 RadarApp 源码一致(`parser`/`protocol`/`types`/…),迁移零改动。
27
28pub mod cma_parser;
29pub mod error;
30pub mod parser;
31pub mod protocol;
32pub mod radial;
33pub mod sweep_data;
34pub mod time_utils;
35pub mod variable;
36pub mod types;
37
38pub use error::{RadarError, Result};
39pub use parser::{BaseProduct, BaseProductLayer, RadarData, RadarDataSummary, RadarParser};
40
41/// 基数据格式判定结果。
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum Format {
44 /// 水利测雨雷达格式(卷标 "RD"/"GD")。
45 WaterConservancy,
46 /// CMA 标准格式(QXT 653-2022)。
47 Cma,
48 Unknown,
49}
50
51/// 按字节前缀判型(bz2 压缩流判 BZh → 需先解压再判内容;
52/// 此处对**未压缩**字节判型;压缩文件请用 [`RadarParser::parse_file`])。
53pub fn detect_format(bytes: &[u8]) -> Format {
54 if cma_parser::is_cma_format(bytes) {
55 return Format::Cma;
56 }
57 if bytes.len() >= 2 {
58 let head = &bytes[..2];
59 if head == b"RD" || head == b"GD" {
60 return Format::WaterConservancy;
61 }
62 }
63 Format::Unknown
64}