Event-SAR / README.md
Ehzoahis's picture
Update Event-SAR loader: shared-mask filtering, product modes and aligned crops
9fc4a1d verified
|
Raw History Blame Contribute Delete
14.2 kB
---
license: apache-2.0
pretty_name: Event-SAR
viewer: false
size_categories:
- n<1K
tags:
- geospatial
- remote-sensing
- sar
- insar
- earthquake
- volcano
- webdataset
- pytorch
task_categories:
- image-feature-extraction
configs:
- config_name: default
data_files:
- split: train
path: data/event-sar-train-*.tar
dataset_info:
features:
- name: npz.bin
dtype: binary
- name: json
struct:
- name: sample_key
dtype: string
- name: event_type
dtype: string
- name: event_id
dtype: string
- name: patch_id
dtype: string
- name: shared_valid_ratio
dtype: float64
- name: shared_valid_dem_vh_ratio
dtype: float64
- name: shared_valid_all_ratio
dtype: float64
- name: metadata_json
dtype: string
- name: __key__
dtype: string
- name: __url__
dtype: string
---
# Event-SAR
Event-SAR contains **416 reviewed, coordinate-aligned SAR patches** around earthquake
and volcanic events: **314 earthquake patches from 53 events** and **102 volcano
patches from 102 events**. It complements [NA-SAR](https://huggingface.co/datasets/GFM-Bench/NA-SAR)
using the same WebDataset tar/NumPy packaging approach.
All 416 accepted patches are retained, including patches with partial coverage.
The latest final-pass GUI decisions are not used to remove samples. Original review
scores (3–5), event information, source provenance, geospatial grids, and exact valid
fractions are preserved. Additional matching acquisitions were processed with ASF
HyP3 to recover available missing coverage. Missing observations remain missing.
`train` is a storage split containing the entire corpus, **not** a prescribed
training/evaluation split. Multiple patches can belong to the same event and overlap;
use event-aware, spatially and temporally appropriate splits for evaluation.
<!-- EVENT-SAR-PREVIEWS -->
## Browse samples online
**[Open the six-example gallery](https://huggingface.co/datasets/GFM-Bench/Event-SAR/blob/main/previews/README.md)** — no dataset download or Python required. Three earthquake and three volcano examples, with Fair, Good, and Excellent review labels. Each shows all five stages and available orbits.
Fair, Good, and Excellent describe the existing review ratings; coverage is a separate measure. These are downsampled display previews, not training arrays. Checkerboards indicate missing data. The gallery explains scales and sample selection.
### Review rating distribution
Counts cover the full released dataset, not just the six examples. Review ratings and valid coverage are separate measures.
![Patch counts by review rating for earthquakes and volcanoes](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/review_counts.png)
| Event type | Fair | Good | Excellent | Total |
|---|---:|---:|---:|---:|
| Earthquake | 97 | 82 | 135 | 314 |
| Volcano | 23 | 52 | 27 | 102 |
[Download SVG](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/review_counts.svg) · [Counts CSV](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/review_counts.csv)
### Earthquake · Fair · us2000bqsn
![earthquake sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000186.jpg)
### Earthquake · Good · us7000irp8
![earthquake sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000296.jpg)
### Earthquake · Excellent · us20003k7w
![earthquake sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000124.jpg)
### Volcano · Fair · gvp_312030_22129
![volcano sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000392.jpg)
### Volcano · Good · gvp_273010_22151
![volcano sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000357.jpg)
### Volcano · Excellent · gvp_252120_22319
![volcano sample](https://huggingface.co/datasets/GFM-Bench/Event-SAR/resolve/main/previews/images/000000000320.jpg)
<!-- /EVENT-SAR-PREVIEWS -->
## Contents
- One WebDataset sample per accepted spatial patch, with `<sample_key>.npz.bin` and
`<sample_key>.json` members in a tar shard.
- Five ordered stages: `pre0`, `pre1`, `event`, `post0`, `post1`.
- 218 patches have one orbit; 198 patches have two orbits. Orbit IDs and their
acquisition times/directions are in the sample metadata. Views are sorted by orbit
ID; `view_0` does **not** always mean ascending. No missing view is synthesized.
- Earthquake patches: 314 at 1024×1024 pixels.
- Volcano patches: 49 at 512×512, 47 at 1024×1024, and 6 at 2048×2048 pixels.
- All products within each patch share exactly the same CRS, affine transform,
bounds, and dimensions. Alignment does not imply complete valid coverage.
- 23,570 source rasters, retained losslessly as arrays. Original wrapped phase is
kept in addition to the derived cosine/sine representation.
For each available view `v`, with `T=5` and the patch's original `H,W`:
| Array key | Shape | Meaning |
|---|---|---|
| `prime_rtc_view_v` | `(T,2,H,W)` | Reference RTC channels `[VV,VH]`, raw linear backscatter |
| `secondary_rtc_view_v` | `(T,2,H,W)` | Secondary RTC channels `[VV,VH]` |
| `inc_angle_view_v` | `(T,1,H,W)` | Incidence from local vertical, radians |
| `ifg_view_v` | `(T,2,H,W)` | Derived `[cos(phase),sin(phase)]` |
| `wrapped_phase_view_v` | `(T,1,H,W)` | Original wrapped phase, radians |
| `coh_view_v` | `(T,1,H,W)` | Coherence |
| `dem` | `(1,H,W)` | Original DEM elevation values, meters |
| `slope_deg` | `(1,H,W)` | Original terrain slope, degrees |
| `common_valid` | `(1,H,W)` | Joint reference/secondary VV + coherence + phase mask |
| `common_valid_dem_vh` | `(1,H,W)` | Joint mask also requiring DEM and reference/secondary VH |
| `common_valid_all` | `(1,H,W)` | Joint mask also requiring incidence and slope |
All joint masks intersect **every saved orbit and stage**. They contain uint8 0/1;
scientific arrays retain float32 values and NaNs. A completely unavailable VH
acquisition remains NaN and can make the extended/all-product shared ratio zero.
DEM source vertical-reference information is preserved; no datum conversion is
applied. Incidence is **not** terrain-local incidence.
### Relationship to NA-SAR
The view-key families, RTC channel order, cosine/sine phase channels, raw DEM,
slope, tar shards, Parquet index, and shard manifest follow NA-SAR's conventions.
Event-SAR adds a leading stage dimension, variable patch sizes and orbit counts,
original wrapped phase, validity masks, and rich event metadata. Unlike NA-SAR's
zero-padding policy, Event-SAR preserves nodata as NaN for exact coverage filtering.
The NPZ payload uses the `.npz.bin` suffix so Hugging Face keeps it as binary
bytes instead of automatically expanding large arrays into nested Python lists.
It is an ordinary NumPy NPZ archive, readable with `numpy.load`. Rich metadata
is held in a JSON string to avoid automatic schema inference altering variable
source fields. Use the included Event-SAR loader rather than assuming NA-SAR's fixed-shape loader
can consume these samples unchanged. No normalization, resizing, cropping, or
coverage-based exclusion is applied during export.
## Metadata and coverage filtering
`metadata.parquet` has one row per patch, including:
- `sample_key`, `shard_path`, `shard_index`, `sample_index_in_shard`;
- event type/ID, patch ID, original score, stages, orbit IDs, dimensions;
- CRS, affine transform, projected/geographic bounds, event metadata JSON;
- `shared_valid_ratio`, `shared_valid_dem_vh_ratio`, `shared_valid_all_ratio`;
- NPZ/JSON checksums and the original metadata checksum.
`file_metadata.parquet` has one row per source raster, with its exact `valid_ratio`,
original GeoTIFF checksum, product/stage/orbit, and corresponding array key,
stage index, and channel index inside the NPZ.
Each sample's JSON has a fixed outer schema with identity and coverage fields. Its
`metadata_json` string preserves the complete patch/event/acquisition metadata and adds
`hf_export`: the view-to-orbit mapping, array shapes, source-to-array mapping,
and GeoTIFF units, scales, offsets, descriptions, and tags. Machine-specific path
prefixes are replaced by `source/diskN/` and `repository/`; these are provenance
identifiers, not URLs. The local original GeoTIFF release remains separate.
All ratios are exact fractions in `[0,1]`, not rounded percentages:
| Shared VV + InSAR coverage | Patches |
|---|---:|
| Exactly 100% | 49 |
| At least 99% | 347 |
| Above 95% | 385 |
| At or below 95% | 31 |
```python
import pandas as pd
from huggingface_hub import hf_hub_download
path = hf_hub_download('GFM-Bench/Event-SAR', 'metadata.parquet', repo_type='dataset')
metadata = pd.read_parquet(path)
selected = metadata[metadata.shared_valid_ratio > 0.95] # 385 patches
```
## Streaming with Hugging Face Datasets
```python
from io import BytesIO
import numpy as np
from datasets import load_dataset
stream = load_dataset('GFM-Bench/Event-SAR', split='train', streaming=True)
sample = next(iter(stream))
with np.load(BytesIO(sample['npz.bin']), allow_pickle=False) as archive:
rtc = archive['prime_rtc_view_0'] # (5,2,H,W)
mask = archive['common_valid'] # (1,H,W)
import json
metadata = json.loads(sample['json']['metadata_json'])
print(metadata['event_id'], metadata['common_valid_fraction'])
```
The explicit equivalent is `load_dataset('webdataset',
data_files={'train':'hf://datasets/GFM-Bench/Event-SAR/data/event-sar-train-*.tar'},
split='train', streaming=True)`. Each large sample contains all of its stages;
streaming does not decompress the entire dataset in advance.
## Local PyTorch loading
Download the published folder with `huggingface_hub.snapshot_download`, or use an
existing local export. Import the included `event_sar_dataset.py`:
```python
from torch.utils.data import DataLoader
from event_sar_dataset import EventSARWebDataset
ds = EventSARWebDataset('/path/to/Event-SAR-HF', min_shared_valid_ratio=0.95)
# Threshold applies inclusively to the cropped common_valid mask.
loader = DataLoader(ds, batch_size=None, num_workers=2)
sample = next(iter(loader))
rtc = sample['arrays']['prime_rtc_view_0']
# To select one stage and remove its leading dimension:
event_only = EventSARWebDataset('/path/to/Event-SAR-HF', stage='event')
# event_only yields prime_rtc_view_0 with shape (2,H,W).
```
Variable sizes and orbit counts require an appropriate batching/collation policy.
The loader preserves raw values; models should handle NaNs using the supplied
masks and apply their own normalization.
The loader supports aligned crops and product selection:
```python
from event_sar_dataset import EventSARDataset, event_sar_collate
ds = EventSARDataset(
'/path/to/Event-SAR-HF',
event_type=['earthquake', 'volcano'],
mode='all', # rtc, insar, or all (default)
stages=['event'],
crop_size=512,
crop_mode='all', # random, central, or all
min_shared_valid_ratio=0.95,
)
loader = DataLoader(ds, batch_size=4, collate_fn=event_sar_collate)
```
`rtc` returns reference/secondary VV/VH; `insar` returns cos/sin phase, wrapped
phase and coherence. `all` includes both plus DEM, slope and incidence. Explicit
`include_dem`, `include_slope`, `include_inc_angle` flags override auxiliary
defaults (off for rtc/insar, on for all). Unselected arrays are not decompressed.
Filtering uses only the cropped `common_valid` mask, intersecting VV/InSAR across
all original stages/views regardless of mode or selected stages. This mask does
not require valid VH or auxiliary products. No channel-specific thresholds are
used. A failing crop is skipped, with no random retries. The output
`shared_valid_ratio` reports actual crop coverage. Scores and score filters are
not exposed: the historical 3–5 review ratings are not final decisions. They
remain in raw source metadata solely as provenance.
`all` crop mode produces separate nonoverlapping tiles (1024 -> four 512 tiles);
dimensions must divide exactly. `random` produces one repeatable crop per sample
and epoch. Call `set_epoch(epoch)` before iteration; recreate persistent workers
after changing epochs. `central` selects the image center. `event_ids` and
`sample_keys` support custom selections. Raw values and NaNs remain unchanged.
Outputs include event date, center coordinates, magnitude/type (Mw or VEI),
stages, crop window and adjusted grid. Original patch coordinates are saved in
Parquet (`transform`, CRS, bounds, dimensions) and JSON (`grid`). Earthquake JSON
also preserves `reviewed_box` row/column offsets; volcano grids are event-centered.
Loader-created `crop_window` coordinates are relative to the native exported
patch and are generated at runtime, not stored on HF.
The collator returns a list to accommodate variable orbit counts. When filtering,
length is unknown until iteration; `num_candidate_crops` is an upper bound.
Shards are partitioned across workers/ranks; training must handle uneven counts.
## Provenance and integrity
SAR observations are Sentinel-1 products processed with ASF HyP3. Exact source
acquisitions, orbit groups, stage assignments, event catalog attributes, processing
parameters, and terrain provenance are recorded per sample. Original provider
attribution and source-product terms remain applicable.
`webdataset_summary.json` summarizes the export and verification.
`shard_manifest.jsonl` records each tar shard's sample count, size, and SHA256.
`SHA256SUMS` covers the published release files. Every source raster checksum/grid
was checked, every raw exported array was round-trip verified, and the joint masks
were reconstructed and compared before packaging. Cosine/sine phase is derived;
the original phase array is retained for exact reconstruction.
Remaining nodata, partial footprints, variable acquisition intervals, and absent VH
are part of this release. A high valid ratio measures data availability, not event
visibility or coherence quality. Event labels do not constitute pixel-level damage
or deformation annotations.