GRIB2 archive decoder and geographic window query library
moon test --deny-warn
moon test --target js --deny-warn
moon run cmd/main --target js -- range-inventory sample.grib2
moon run cmd/main --target js -- range-window sample.grib2 0 119.5 29.7 120.6 30.7
moon run cmd/main --target js -- estimate sample.grib2 0 30.2 120.1 bilinear
moon run cmd/main --target js -- raster sample.grib2 0 119.5 29.7 120.6 30.7 asc| 能力 | 入口或范围 |
|---|---|
| 文件和消息 | open_archive 从内存打开,open_indexed 按需读取。支持连续消息、消息内多字段、可选本地节和先前位图引用 |
| 网格 | 规则经纬网格 3.0、规则高斯网格 3.40,支持正反方向、行列优先、交替扫描和缺测位图。缩减网格和交错网格超出当前范围 |
| 内存读取 | 简单打包 5.0、通用组拆分 5.2、一阶及二阶空间差分 5.3,以及单精度或双精度 IEEE 5.4 |
| 读取文件范围 | range-window 按需读取 5.0 和 5.4 的偏移区间,range-inventory 仅读取消息结构和元数据 |
| 查询和比较 | point、stats、estimate、profile、compare。支持最近邻、双线性插值和缺测策略 |
| 时间轴 | 支持瞬时产品的有效时刻、点位和区域时间序列,interval 展示模板 4.8 的区间与统计描述 |
| 导出和编码 | 窗口 CSV、JSON Lines、ASCII Grid、PGM。MoonBit API 可编码规则经纬网格的简单整数打包或 IEEE64 |
moon build --target js
python examples/verify_eccodes.py
python -B examples/benchmark_window.py| 窗口 | 格点数 | 整场解码后裁剪 | 内存内窗口解码 | 按范围读取 | 范围读取字节 |
|---|---|---|---|---|---|
| 小窗口 | 121 | 191.16 ms | 113.66 ms | 112.43 ms | 1152 |
| 大窗口 | 40401 | 238.30 ms | 182.57 ms | 202.60 ms | 81712 |
moon build --target js
python -B examples/demo.py ./forecast-demo
python -B examples/verify_encoded.pypub(all) struct AggregationInterval {
start : ReferenceTime?
end : ReferenceTime
missing_inputs : UInt64?
ranges : Array[StatisticalRange]
}fn Archive::aggregation_interval(self : Archive, index : Int) -> AggregationInterval? raise GribErrorfn Archive::point_series(self : Archive, filter : Filter, pos : Position, start : ReferenceTime, end : ReferenceTime, options? : SeriesOptions) -> Array[SeriesPoint] raise GribErrorfn Archive::regional_series(self : Archive, filter : Filter, bounds : Bounds, start : ReferenceTime, end : ReferenceTime, max_fields? : Int, max_points? : Int) -> Array[RegionalSeriesPoint] raise GribErrorfn Archive::select_valid_time(self : Archive, filter : Filter, start : ReferenceTime, end : ReferenceTime) -> Array[Metadata] raise GribErrorpub(all) struct AreaStatistics {
points : Int
present : Int
missing : Int
footprint_steradians : Double
covered_steradians : Double
weighted_mean : Double?
}pub struct ByteSource {
length : Int
// private fields
}fn ByteSource::new(length : Int, read : (Int, Int) -> Bytes raise GribError) -> ByteSource raise GribErrorfn DecodedField::area_statistics(self : DecodedField, bounds : Bounds, max_points? : Int) -> AreaStatistics raise GribErrorfn DecodedField::compare_window(self : DecodedField, other : DecodedField, bounds : Bounds, tolerance? : Double, max_points? : Int) -> WindowDifference raise GribErrorfn DecodedField::estimate(self : DecodedField, position : Position, interpolation? : InterpolationMethod, missing? : MissingPolicy) -> EstimatedValue raise GribErrorfn DecodedField::profile(self : DecodedField, from : Position, to : Position, points : Int, interpolation? : InterpolationMethod, missing? : MissingPolicy) -> Array[EstimatedValue] raise GribErrorfn DecodedField::raster(self : DecodedField, bounds : Bounds, max_points? : Int) -> Raster raise GribErrorfn DecodedField::resample(self : DecodedField, target : TargetGrid, interpolation? : InterpolationMethod, missing? : MissingPolicy, max_points? : Int) -> ResamplingResult raise GribErrorfn DecodedField::scan_window(self : DecodedField, bounds : Bounds, max_points? : Int, scan_limit? : Int) -> Array[Sample] raise GribErrorfn DecodedField::statistics(self : DecodedField, bounds : Bounds, max_points? : Int) -> Statistics raise GribErrorfn DecodedField::visit_window(self : DecodedField, bounds : Bounds, emit : (Sample) -> Unit, max_points? : Int) -> Unit raise GribErrorfn DecodedField::window(self : DecodedField, bounds : Bounds, max_points? : Int) -> Array[Sample] raise GribErrorpub(all) enum FieldStatus {
Ready
Malformed(Int, String)
UnsupportedField(Int, String)
}pub(all) struct Filter {
discipline : Int?
category : Int?
parameter : Int?
centre : Int?
surface_kind : Int?
forecast_unit : Int?
forecast_offset : Int?
reference_time : String?
}pub(all) struct ForecastTime {
reference : ReferenceTime
valid : ReferenceTime
offset_seconds : Int64
}pub struct Grid {
columns : Int
rows : Int
points : Int
first_latitude : Double
first_longitude : Double
latitude_step : Double
longitude_step : Double
column_major : Bool
alternating : Bool
// private fields
}pub struct IndexedArchive {
// private fields
}fn IndexedArchive::raw_message(self : IndexedArchive, index : Int, max_bytes? : Int) -> Bytes raise GribErrorfn IndexedArchive::select(self : IndexedArchive, filter : Filter) -> Array[Metadata] raise GribErrorpub(all) struct IntegerPackingSpec {
binary_scale : Int
decimal_scale : Int
}pub(all) struct Metadata {
field_index : Int
origin : ReferenceTime
centre : Int
subcentre : Int
variable : Variable
product_template : Int
grid_template : Int
packing_template : Int
forecast_unit : Int?
forecast_offset : Int?
first_surface : Surface?
second_surface : Surface?
message : Span
}pub(all) struct ProductSpec {
variable : Variable
reference : ReferenceTime
centre : Int
subcentre : Int
forecast_unit : Int
forecast_offset : Int
level_kind : Int
level_value : Int?
}fn RangeField::window(self : RangeField, bounds : Bounds, options? : RangeOptions) -> ReadWindow raise GribErrorpub(all) struct RangeOptions {
max_points : Int
merge_gap : Int
max_read : Int
}pub struct Raster {
rows : Int
columns : Int
north : Double
west : Double
latitude_spacing : Double
longitude_spacing : Double
// private fields
}pub(all) struct ReferenceTime {
year : Int
month : Int
day : Int
hour : Int
minute : Int
second : Int
}pub(all) struct RegionalSeriesPoint {
field_index : Int
time : ForecastTime
statistics : Statistics
}pub(all) struct RegularGridSpec {
columns : Int
rows : Int
latitude_microdegrees : Int
longitude_microdegrees : Int
i_increment_microdegrees : Int
j_increment_microdegrees : Int
}pub(all) struct ResamplingResult {
raster : Raster
present : Int
missing : Int
outside_or_unsampled : Int
}pub(all) struct Sample {
row : Int
column : Int
latitude : Double
longitude : Double
value : Double?
}pub(all) struct SeriesOptions {
interpolation : InterpolationMethod
missing : MissingPolicy
max_fields : Int
}pub(all) struct StatisticalRange {
process : Int
increment_type : Int
range_unit : Int
range_length : UInt64?
increment_unit : Int
increment : UInt64?
}pub(all) struct Statistics {
points : Int
present : Int
missing : Int
minimum : Double?
maximum : Double?
mean : Double?
population_variance : Double?
}pub(all) struct TargetGrid {
rows : Int
columns : Int
north : Double
west : Double
latitude_spacing : Double
longitude_spacing : Double
}pub(all) struct WindowDifference {
evaluated : Int
paired : Int
both_missing : Int
left_only : Int
right_only : Int
above_tolerance : Int
mean_delta : Double?
mean_absolute_error : Double?
maximum_absolute_error : Double?
}fn encode_ieee(grid : RegularGridSpec, product : ProductSpec, values : Array[Double?]) -> Bytes raise GribErrorfn encode_simple(grid : RegularGridSpec, product : ProductSpec, scales : IntegerPackingSpec, values : Array[UInt?]) -> Bytes raise GribError