From 17bf8c1734b514f6b1747c00e00b9cdf48f235db Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 06:44:55 -0600 Subject: [PATCH 1/4] feat(data): raster readers give loss codes for what they leave out or assume (#2371) --- crates/data/src/raster/ascii.rs | 5 +- crates/data/src/raster/cog.rs | 13 ++-- crates/data/src/raster/dted.rs | 12 ++-- crates/data/src/raster/geotiff.rs | 31 +++++---- crates/data/src/raster/grib.rs | 38 +++++++---- crates/data/src/raster/grib_tests.rs | 66 +++++++++---------- crates/data/src/raster/mod.rs | 20 +++--- crates/data/src/raster/pam.rs | 55 +++++++++++----- crates/data/src/raster/zarr.rs | 51 +++++++++----- crates/engine/src/cmd/cube.rs | 8 +-- crates/engine/src/cmd/embeddings.rs | 6 +- crates/engine/src/cmd/imagery.rs | 9 +-- crates/engine/src/cmd/layer.rs | 25 ++++--- crates/engine/src/cmd/project.rs | 2 +- crates/engine/src/cmd/raster.rs | 51 +++++++++----- crates/engine/src/cmd/stac.rs | 14 ++-- crates/engine/src/cmd/zarr.rs | 6 +- .../integration/portable_projects/reload.rs | 2 +- crates/geolibre/src/lib.rs | 2 +- crates/map/src/raster.rs | 8 +-- crates/tiles/src/cog.rs | 2 +- crates/ui-egui/src/geolibreui.rs | 5 +- crates/ui-egui/src/workspacepanes.rs | 5 +- crates/ui-egui/src/zarrui.rs | 4 +- 24 files changed, 270 insertions(+), 170 deletions(-) diff --git a/crates/data/src/raster/ascii.rs b/crates/data/src/raster/ascii.rs index 1e1a372a37..873e509318 100644 --- a/crates/data/src/raster/ascii.rs +++ b/crates/data/src/raster/ascii.rs @@ -111,8 +111,9 @@ pub(super) fn read_with_nodata( r.lost.extend(super::planetary::note_of(crs)); if assumed { r.crs_assumed = true; - r.lost.push(super::assumed_wgs84_note( - crs_issue.unwrap_or("it doesn't say its coordinate system (a .prj file next to an ASCII grid does)"), + r.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::AssumedCrs, + super::assumed_wgs84_note(crs_issue.unwrap_or("it doesn't say its coordinate system (a .prj file next to an ASCII grid does)")), )); } if rounded > 0 { diff --git a/crates/data/src/raster/cog.rs b/crates/data/src/raster/cog.rs index 6dedc6c524..5f312f1d52 100644 --- a/crates/data/src/raster/cog.rs +++ b/crates/data/src/raster/cog.rs @@ -242,7 +242,7 @@ pub struct Layout { /// What the header holds but isn't read: a colour table or GDAL metadata that doesn't decode, /// a colour table too short for its pixels. One line each, for a window to say (AGENTS.md, /// Never silent); drawing in place shows the file grey without them, as before. - pub lost: Vec, + pub lost: crate::loss::Notes, /// Who holds the rights to the picture (its Copyright tag), as [`super::Raster::copyright`]. pub copyright: Option, } @@ -394,10 +394,10 @@ fn read_layout(r: Sparse) -> Result { Err(e) => Ok(Err(e.to_string())), }; // Another body's system is said, as when the file is read whole. - let mut lost: Vec = super::planetary::note_of(geo.0).into_iter().collect(); + let mut lost: crate::loss::Notes = super::planetary::note_of(geo.0).into_iter().collect(); // A datum assumed, and the file's copyright, as when it is read whole. if geo.3 { - lost.push(super::geotiff::NO_EPSG_GEOGRAPHIC.to_string()); + lost.push(crate::loss::Note::loss(crate::loss::LossCode::AssumedCrs, super::geotiff::NO_EPSG_GEOGRAPHIC)); } // Its bytes asked for when not read yet, as the other tags' are. let copyright = match tag(&mut dec, Tag::Copyright)? { @@ -1151,7 +1151,10 @@ pub(crate) mod tests { let clean = layout_of(example(64, 32)); assert!(clean.lost.is_empty() && clean.copyright.is_none(), "{:?}", clean.lost); let assumed = layout_of(example_with(&Example { size: 64, tile: 32, no_epsg: true, ..Example::default() })); - assert_eq!(assumed.lost, vec![super::super::geotiff::NO_EPSG_GEOGRAPHIC.to_string()]); + assert_eq!( + assumed.lost.iter().map(|n| (n.text.as_str(), n.loss)).collect::>(), + [(super::super::geotiff::NO_EPSG_GEOGRAPHIC, Some(crate::loss::LossCode::AssumedCrs))] + ); let mut r = crate::raster::Raster::new( "credited", 64, @@ -1376,7 +1379,7 @@ pub(crate) mod tests { let entry = (0..n).map(|k| 10 + k * 12).find(|&e| bad[e..e + 2] == [0x80, 0xA4]).unwrap(); bad[entry + 8..entry + 12].copy_from_slice(&(len + 1000).to_le_bytes()); let Parse::Done(l) = layout(&Sparse::default().with_len(u64::from(len)).with(0, bad)).unwrap() else { panic!("not read") }; - let said: Vec<&String> = l.lost.iter().chain(l.described.iter().flat_map(|d| d.lost.iter())).collect(); + let said: Vec<&str> = l.lost.texts().chain(l.described.iter().flat_map(|d| d.lost.texts())).collect(); assert!(said.iter().any(|x| x.contains("band and class names and wavelengths are left out")), "{said:?}"); } diff --git a/crates/data/src/raster/dted.rs b/crates/data/src/raster/dted.rs index 5375966e36..f4a87513c3 100644 --- a/crates/data/src/raster/dted.rs +++ b/crates/data/src/raster/dted.rs @@ -258,7 +258,7 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize if east - west > 1.0 + 1e-9 || north - south > 1.0 + 1e-9 || north > 90.0 + 1e-9 || east > 180.0 + 1e-9 { return Err(bad("its posts span more than the one-degree cell a DTED file holds")); } - let mut lost = Vec::new(); + let mut lost = crate::loss::Notes::new(); // What the DSI says differently (3.12 d), and what the spec sets for the level (3.9.2). let dsi = [ (digits(bytes, DSI + 273, 4), lat_tenths, "latitude interval"), @@ -329,7 +329,7 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize Some(other) if !other.trim().is_empty() => { lost.push(format!("its horizontal datum is {:?}, not WGS84; it is read as WGS 84", other.trim())); } - _ => lost.push("it doesn't name its horizontal datum; it is read as WGS 84, as MIL-PRF-89020B sets".into()), + _ => lost.push("it doesn't name its horizontal datum; it is read as WGS 84, as MIL-PRF-89020B sets"), } let surface = match field(bytes, DSI + 141, 3) { Some("E96") => "the EGM96 geoid (mean sea level)".to_string(), @@ -456,7 +456,10 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize lost.push(format!("{extra} bytes after its last column are ignored")); } if damaged > 0 { - lost.push(format!("{} a damaged record header (not the 0xAA sentinel), read as no data", count(damaged))); + lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedValue, + format!("{} a damaged record header (not the 0xAA sentinel), read as no data", count(damaged)), + )); } match misnumbered { 0 => {} @@ -477,8 +480,7 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize match twos { 0 => {} 1 => lost.push( - "1 of its heights was written in two's complement, not the signed magnitude MIL-PRF-89020B sets; it is read as two's complement" - .into(), + "1 of its heights was written in two's complement, not the signed magnitude MIL-PRF-89020B sets; it is read as two's complement", ), n => lost.push(format!( "{n} of its heights were written in two's complement, not the signed magnitude MIL-PRF-89020B sets; they are read as two's complement" diff --git a/crates/data/src/raster/geotiff.rs b/crates/data/src/raster/geotiff.rs index 9d84fb1315..a9a1ef67d5 100644 --- a/crates/data/src/raster/geotiff.rs +++ b/crates/data/src/raster/geotiff.rs @@ -2070,19 +2070,26 @@ fn read_image( return Err(DataError::Format(e.clone())); } if let Some(asked) = asked.filter(|_| geo.custom_error.is_none() && !geo.geographic_model && !degrees) { - assumed = Some(format!("it doesn't say its coordinate system: read in {}, the system it was asked for in", asked.label())); + // Read in the system asked for: nothing assumed past the request. + assumed = Some(crate::loss::Note::plain(format!( + "it doesn't say its coordinate system: read in {}, the system it was asked for in", + asked.label() + ))); asked } else if geo.geographic_model || degrees { - assumed = Some(match &geo.custom_error { - // The file's own projection couldn't be read, but its coordinates fit in degrees: - // why is said, not dropped. - Some(e) => super::assumed_wgs84_note(&format!( - "its own coordinate system can't be read ({})", - e.strip_prefix("GeoTIFF: ").unwrap_or(e) - )), - None if geo.geographic_model => NO_EPSG_GEOGRAPHIC.to_string(), - None => super::assumed_wgs84_note("it doesn't say its coordinate system"), - }); + assumed = Some(crate::loss::Note::loss( + crate::loss::LossCode::AssumedCrs, + match &geo.custom_error { + // The file's own projection couldn't be read, but its coordinates fit in degrees: + // why is said, not dropped. + Some(e) => super::assumed_wgs84_note(&format!( + "its own coordinate system can't be read ({})", + e.strip_prefix("GeoTIFF: ").unwrap_or(e) + )), + None if geo.geographic_model => NO_EPSG_GEOGRAPHIC.to_string(), + None => super::assumed_wgs84_note("it doesn't say its coordinate system"), + }, + )); Crs::LonLat } else { return Err(err("the file's coordinate system isn't recognised")); @@ -3060,7 +3067,7 @@ mod tests { let rotated = [30.0, 5.0, 0.0, 400_000.0, 3.0, -30.0, 0.0, 5_000_000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]; let r = read(std::io::Cursor::new(tests_support::matrix_tiff(rotated, false)), "rot").unwrap(); assert_eq!(r.lost.len(), 1, "{:?}", r.lost); - let said = &r.lost[0]; + let said = &r.lost[0].text; assert!(said.starts_with("it is rotated or skewed, so it is resampled (nearest pixel) onto a north-up grid of "), "{said}"); assert!(said.contains(&format!("{} × {} pixels of 30.25 each", r.width, r.height)), "{said}"); assert!(!said.contains("coarser"), "{said}"); diff --git a/crates/data/src/raster/grib.rs b/crates/data/src/raster/grib.rs index b49d5cf68f..c53b665744 100644 --- a/crates/data/src/raster/grib.rs +++ b/crates/data/src/raster/grib.rs @@ -209,7 +209,10 @@ fn read_limited(mut source: R, name: &str, sidecar_nodata: Optio return Err(bad(if skipped.cut > 0 { "the first message is cut short" } else { "no GRIB message in the file" })); } if fields.is_empty() { - return Err(bad(format!("nothing in it can be read here: {}", skipped.notes(limit).join("; ")))); + return Err(bad(format!( + "nothing in it can be read here: {}", + skipped.notes(limit).iter().map(|n| n.as_str()).collect::>().join("; ") + ))); } // Each grid's notices, once: grids at the same places may still say different things (one // laid out from BAM's latitudes, one not). Past [`MAX_REASONS`] of them, the fields with more @@ -505,35 +508,39 @@ impl Skipped { tally(&mut self.damage, why); } - fn notes(&self, limit: usize) -> Vec { - let mut out: Vec = self.reasons.iter().map(|(r, n)| format!("{} left out: {r}, not read yet", count(*n))).collect(); - out.extend(self.damage.iter().map(|(r, n)| format!("{} left out: damaged ({r})", count(*n)))); + /// Fields and messages left out are lost, with their codes (those past a memory limit as + /// such); bytes that aren't GRIB are passed over, plain. + fn notes(&self, limit: usize) -> Vec { + use crate::loss::{LossCode, Note}; + let feature = |t: String| Note::loss(LossCode::DroppedFeature, t); + let mut out: Vec = self.reasons.iter().map(|(r, n)| feature(format!("{} left out: {r}, not read yet", count(*n)))).collect(); + out.extend(self.damage.iter().map(|(r, n)| feature(format!("{} left out: damaged ({r})", count(*n))))); out.extend(self.messages.iter().map(|(r, n)| { let what = if *n == 1 { "1 message".to_string() } else { format!("{n} messages") }; - format!("{what} left out: {r}") + feature(format!("{what} left out: {r}")) })); if self.other_grid > 0 { - out.push(format!("{} left out: on another grid than the first field's", count(self.other_grid))); + out.push(feature(format!("{} left out: on another grid than the first field's", count(self.other_grid)))); } if self.over_limit > 0 { - out.push(format!( + out.push(Note::loss(LossCode::DroppedOverLimit, format!( "{} left out: the bands read hold the most this computer keeps in memory ({limit} values); split the file with a GRIB tool (wgrib2 or CDO) and add its parts", count(self.over_limit) - )); + ))); } if self.too_long > 0 { - out.push(format!( + out.push(Note::loss(LossCode::DroppedOverLimit, format!( "{} left out: their message is larger than the memory left lets be read whole, even where one of its fields would fit; split the file with a GRIB tool (wgrib2 or CDO) and add its parts", count(self.too_long) - )); + ))); } if self.cut > 0 { - out.push("the file ends inside a message, which is left out".to_string()); + out.push(feature("the file ends inside a message, which is left out".to_string())); } if self.junk == 1 { - out.push("1 byte outside its messages isn't GRIB, and is passed over".to_string()); + out.push(Note::plain("1 byte outside its messages isn't GRIB, and is passed over")); } else if self.junk > 1 { - out.push(format!("{} bytes outside its messages aren't GRIB, and are passed over", self.junk)); + out.push(Note::plain(format!("{} bytes outside its messages aren't GRIB, and are passed over", self.junk))); } out } @@ -769,7 +776,10 @@ fn to_raster(fields: Vec, name: &str) -> Result { } if past > 0 { let (what, has) = if past == 1 { ("1 value".to_string(), "has") } else { (format!("{past} values"), "have") }; - r.lost.push(format!("{what} past the range of 32-bit floats (±3.4 × 10^38) {has} no value")); + r.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedValue, + format!("{what} past the range of 32-bit floats (±3.4 × 10^38) {has} no value"), + )); } Ok(r) } diff --git a/crates/data/src/raster/grib_tests.rs b/crates/data/src/raster/grib_tests.rs index 1e030aa615..bf3f24f40c 100644 --- a/crates/data/src/raster/grib_tests.rs +++ b/crates/data/src/raster/grib_tests.rs @@ -348,7 +348,7 @@ fn bam_latitudes_against_the_scanning_mode() { let t = r.transform; assert_eq!((t.origin_x, t.origin_y), (-210.0, 60.0)); assert!( - r.lost.contains(&"the grid gives its first row at -30° and its last at 30° but scans north to south: its 2 rows of 60° are laid out as the scanning mode says, centred between the two, from 30° to -30°".to_string()), + r.lost.says("the grid gives its first row at -30° and its last at 30° but scans north to south: its 2 rows of 60° are laid out as the scanning mode says, centred between the two, from 30° to -30°"), "{:?}", r.lost ); @@ -398,7 +398,7 @@ fn grib2_other_packings_are_left_out_and_said() { b.template5 = 42; let r = read_bytes(&grib2_message(&[a, b]), "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"1 field left out: GRIB2 CCSDS (template 5.42), not read yet".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: GRIB2 CCSDS (template 5.42), not read yet"), "{:?}", r.lost); // A file with nothing readable is an error naming why. let mut c = F2::new(2, 1, vec![1, 2]); c.template5 = 40; @@ -421,7 +421,7 @@ fn fields_on_another_grid_are_left_out_and_said() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 2); assert_eq!(r.bands[1].data, vec![5.0, 6.0, 7.0, 8.0]); - assert!(r.lost.contains(&"1 field left out: on another grid than the first field's".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: on another grid than the first field's"), "{:?}", r.lost); } #[test] @@ -431,7 +431,7 @@ fn a_cut_message_is_said_or_refused() { file.extend(&one[..one.len() - 5]); let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"the file ends inside a message, which is left out".to_string()), "{:?}", r.lost); + assert!(r.lost.says("the file ends inside a message, which is left out"), "{:?}", r.lost); let e = read_bytes(&one[..one.len() - 1], "t").unwrap_err().to_string(); assert!(e.contains("cut short"), "{e}"); let e = read_bytes(b"not a grib file at all", "t").unwrap_err().to_string(); @@ -476,8 +476,8 @@ fn another_edition_is_said_and_the_next_message_read() { assert_eq!(r.bands[0].data, vec![3.0, 4.0]); // Its body isn't said to be bytes outside the messages. assert_eq!( - r.lost.iter().filter(|l| !l.starts_with("its earth")).collect::>(), - vec!["1 message left out: not GRIB 1 or 2 (edition 3)"] + r.lost.iter().filter(|l| !l.starts_with("its earth")).map(|l| (l.text.as_str(), l.loss)).collect::>(), + [("1 message left out: not GRIB 1 or 2 (edition 3)", Some(crate::loss::LossCode::DroppedFeature))] ); // Nothing readable: the error names why. let mut only = G1::new(2, 1, vec![1, 2]).bytes(); @@ -496,7 +496,7 @@ fn a_long_gap_between_messages_is_passed_and_said() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 2); assert_eq!(r.bands[1].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&format!("{} bytes outside its messages aren't GRIB, and are passed over", 70 * 1024 + 3)), "{:?}", r.lost); + assert!(r.lost.says(&format!("{} bytes outside its messages aren't GRIB, and are passed over", 70 * 1024 + 3)), "{:?}", r.lost); // A "GRIB" split over two chunks is found. for pad in 4090..4100 { let mut file = vec![0u8; pad]; @@ -541,7 +541,7 @@ fn a_damaged_field_is_said_as_damaged() { msg[s5 + 5..s5 + 9].copy_from_slice(&u(2000, 4)); let r = read_bytes(&msg, "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"1 field left out: damaged (a field whose values don't fill its grid)".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: damaged (a field whose values don't fill its grid)"), "{:?}", r.lost); assert!(!r.lost.iter().any(|l| l.contains("not read yet")), "{:?}", r.lost); } @@ -567,7 +567,7 @@ fn a_length_past_its_message_hides_nothing() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); } #[test] @@ -583,7 +583,7 @@ fn scale_factors_past_f64_give_the_values_they_make() { (g.d, g.bits) = (-400, 16); let r = read_bytes(&g.bytes(), "t").unwrap(); assert!(r.bands[0].data.iter().all(|v| v.is_nan())); - assert!(r.lost.contains(&"2 values past the range of 32-bit floats (±3.4 × 10^38) have no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("2 values past the range of 32-bit floats (±3.4 × 10^38) have no value"), "{:?}", r.lost); // A constant field of 0 with D = 400: exactly 0, nothing said. let mut g = G1::new(2, 1, vec![]); (g.d, g.bits) = (400, 0); @@ -605,7 +605,7 @@ fn scale_factors_past_f64_give_the_values_they_make() { g.x = vec![u32::MAX, 1]; let r = read_bytes(&g.bytes(), "t").unwrap(); assert!(r.bands[0].data.iter().all(|v| v.is_nan())); - assert!(r.lost.contains(&"2 values past the range of 32-bit floats (±3.4 × 10^38) have no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("2 values past the range of 32-bit floats (±3.4 × 10^38) have no value"), "{:?}", r.lost); } #[test] @@ -661,7 +661,7 @@ fn a_length_past_the_file_hides_nothing() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); assert!(!r.lost.iter().any(|l| l.contains("ends inside")), "{:?}", r.lost); } @@ -676,11 +676,7 @@ fn a_repeated_first_column_is_left_out_and_the_globe_laid_out_from_180() { // From −180°: the 180° column first. assert_eq!(r.bands[0].data, vec![4.0, 5.0, 6.0, 1.0, 2.0, 3.0]); assert_eq!(r.transform.origin_x, -210.0); - assert!( - r.lost.contains(&"its last column repeats the first, 360° on, and is left out: 6 columns are read".to_string()), - "{:?}", - r.lost - ); + assert!(r.lost.says("its last column repeats the first, 360° on, and is left out: 6 columns are read"), "{:?}", r.lost); } #[test] @@ -694,7 +690,7 @@ fn a_repeated_first_column_is_not_counted_as_rounded_or_past_the_range() { let mut g = G1::new(7, 1, vec![1, 2, 3, 4, 5, 6, 1]); (g.lat1, g.lat2, g.lon1, g.lon2, g.di, g.dj, g.d) = (0, 0, 0, 0, 60_000, 60_000, -400); let r = read_bytes(&g.bytes(), "t").unwrap(); - assert!(r.lost.contains(&"6 values past the range of 32-bit floats (±3.4 × 10^38) have no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("6 values past the range of 32-bit floats (±3.4 × 10^38) have no value"), "{:?}", r.lost); } #[test] @@ -726,7 +722,7 @@ fn a_sum_of_0_past_f64s_decimal_scale_is_0() { let r = read_bytes(&g.bytes(), "t").unwrap(); assert_eq!(r.bands[0].data[0], 0.0); assert!(r.bands[0].data[1].is_nan()); - assert!(r.lost.contains(&"1 value past the range of 32-bit floats (±3.4 × 10^38) has no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 value past the range of 32-bit floats (±3.4 × 10^38) has no value"), "{:?}", r.lost); } #[test] @@ -737,7 +733,7 @@ fn a_packed_0_past_f64s_binary_scale_is_the_reference_value() { let r = read_bytes(&g.bytes(), "t").unwrap(); assert_eq!(r.bands[0].data[0], 1.0); assert!(r.bands[0].data[1].is_nan()); - assert!(r.lost.contains(&"1 value past the range of 32-bit floats (±3.4 × 10^38) has no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 value past the range of 32-bit floats (±3.4 × 10^38) has no value"), "{:?}", r.lost); } #[test] @@ -811,7 +807,7 @@ fn a_message_of_too_many_sections_is_left_out() { file.extend(grib2_message(&[F2::new(2, 1, vec![3, 4])])); let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"1 message left out: damaged (more than 1024 sections)".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged (more than 1024 sections)"), "{:?}", r.lost); // The decoder refuses one too, should it get one. let first = grib2(&file, usize::MAX, None, Uncounted::default()); assert!(matches!(first.first(), Some(Err(Skip::Damaged(m))) if m.contains("more than 1024 sections"))); @@ -827,13 +823,13 @@ fn values_past_f32_are_said_not_rounded() { assert_eq!(v[0], 0.0); assert!(v[1].is_nan(), "{v:?}"); assert!(r.rounded.is_empty(), "{:?}", r.rounded); - assert!(r.lost.contains(&"1 value past the range of 32-bit floats (±3.4 × 10^38) has no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 value past the range of 32-bit floats (±3.4 × 10^38) has no value"), "{:?}", r.lost); // A constant field whose reference value is past it (IBM 16^60). let mut c = G1::new(2, 1, vec![]); (c.bits, c.r) = (0, 0x7c10_0000); let r = read_bytes(&c.bytes(), "t").unwrap(); assert!(r.bands[0].data.iter().all(|v| v.is_nan())); - assert!(r.lost.contains(&"2 values past the range of 32-bit floats (±3.4 × 10^38) have no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("2 values past the range of 32-bit floats (±3.4 × 10^38) have no value"), "{:?}", r.lost); } #[test] @@ -843,7 +839,7 @@ fn a_constant_past_f64_is_said_and_a_reference_that_isnt_a_number_is_damage() { (c.bits, c.r, c.d) = (0, 0x4925_40be, -300); let r = read_bytes(&c.bytes(), "t").unwrap(); assert!(r.bands[0].data.iter().all(|v| v.is_nan()), "{:?}", r.bands[0].data); - assert!(r.lost.contains(&"2 values past the range of 32-bit floats (±3.4 × 10^38) have no value".to_string()), "{:?}", r.lost); + assert!(r.lost.says("2 values past the range of 32-bit floats (±3.4 × 10^38) have no value"), "{:?}", r.lost); assert!(r.rounded.is_empty()); // A GRIB2 constant field whose IEEE reference value is NaN. let mut f = F2::new(2, 1, vec![]); @@ -893,7 +889,7 @@ fn a_grib2_field_without_its_own_sections_is_damaged() { let r = read_bytes(&msg, "t").unwrap(); assert_eq!(r.bands.len(), 1, "{number}"); assert_eq!(r.bands[0].data, vec![1.0, 2.0]); - assert!(r.lost.contains(&format!("1 field left out: damaged (a field without {why})")), "{number}: {:?}", r.lost); + assert!(r.lost.says(&format!("1 field left out: damaged (a field without {why})")), "{number}: {:?}", r.lost); } } @@ -910,7 +906,7 @@ fn a_length_that_hides_the_next_message_is_damage() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); // GRIB2 alike. let mut first = grib2_message(&[F2::new(2, 1, vec![1, 2])]); let second = grib2_message(&[F2::new(2, 1, vec![3, 4])]); @@ -921,7 +917,7 @@ fn a_length_that_hides_the_next_message_is_damage() { let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); } #[test] @@ -937,7 +933,7 @@ fn grids_are_compared_where_their_points_are() { file.extend(grid(50_000).bytes()); let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"1 field left out: on another grid than the first field's".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: on another grid than the first field's"), "{:?}", r.lost); // The same points scanned from the other end (south to north) are the same grid: a second // band, placed by its own scanning mode. let mut south_up = G1::new(2, 2, vec![3, 4, 1, 2]); @@ -1058,7 +1054,7 @@ fn a_field_the_message_ends_without_its_data_is_damaged() { let r = read_bytes(&message_of(&body), "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![1.0, 2.0]); - assert!(r.lost.contains(&"1 field left out: damaged (a field without its data section)".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: damaged (a field without its data section)"), "{:?}", r.lost); } #[test] @@ -1067,7 +1063,7 @@ fn one_byte_outside_the_messages_is_said_as_one() { file.push(9); file.extend(G1::new(2, 1, vec![3, 4]).bytes()); let r = read_bytes(&file, "t").unwrap(); - assert!(r.lost.contains(&"1 byte outside its messages isn't GRIB, and is passed over".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 byte outside its messages isn't GRIB, and is passed over"), "{:?}", r.lost); } #[test] @@ -1088,7 +1084,7 @@ fn grid_notices_past_the_most_said_are_counted() { // GRIB1's earth is said once too: 15 of the latitudes' notices, then the 6 fields with more. assert!(r.lost.iter().any(|l| l.starts_with("its earth is")), "{:?}", r.lost); assert_eq!(r.lost.iter().filter(|l| l.contains("gives its first row")).count(), MAX_REASONS - 1); - assert!(r.lost.contains(&"more notices about the grids of 6 fields aren't listed".to_string()), "{:?}", r.lost); + assert!(r.lost.says("more notices about the grids of 6 fields aren't listed"), "{:?}", r.lost); } #[test] @@ -1201,7 +1197,7 @@ fn a_field_whose_sections_come_again_before_its_data_is_damaged() { let r = read_bytes(&message_of(&body), "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 field left out: damaged (a field without its data section)".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 field left out: damaged (a field without its data section)"), "{:?}", r.lost); // Then field B without its bitmap section: never read with A's bitmap. let mut body = without_section(&a(), 7); body.extend(without_section(&b, 6)); @@ -1240,7 +1236,7 @@ fn sections_that_break_before_a_length_that_hides_the_next_message_are_damage() let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); // GRIB2: a data section shorter than its header, then one running past the first message's // "7777" into the second. for grow in [None, Some(2)] { @@ -1257,7 +1253,7 @@ fn sections_that_break_before_a_length_that_hides_the_next_message_are_damage() let r = read_bytes(&file, "t").unwrap(); assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); - assert!(r.lost.contains(&"1 message left out: damaged".to_string()), "{:?}", r.lost); + assert!(r.lost.says("1 message left out: damaged"), "{:?}", r.lost); } } @@ -1275,7 +1271,7 @@ fn fields_of_a_message_too_large_to_read_whole_are_said_so() { assert_eq!(r.bands.len(), 1); assert_eq!(r.bands[0].data, vec![3.0, 4.0]); let said = "1 field left out: their message is larger than the memory left lets be read whole, even where one of its fields would fit; split the file with a GRIB tool (wgrib2 or CDO) and add its parts"; - assert!(r.lost.contains(&said.to_string()), "{:?}", r.lost); + assert!(r.lost.says(said), "{:?}", r.lost); assert!(!r.lost.iter().any(|l| l.contains("the bands read hold the most")), "{:?}", r.lost); } diff --git a/crates/data/src/raster/mod.rs b/crates/data/src/raster/mod.rs index 7de4f2942b..435eab9865 100644 --- a/crates/data/src/raster/mod.rs +++ b/crates/data/src/raster/mod.rs @@ -792,7 +792,7 @@ pub struct Raster { /// What reading it left out or cut (a colour table, names), one line a kind with a count, /// for whoever adds it to the map to say (AGENTS.md, Never silent). Empty when nothing was /// left out. - pub lost: Vec, + pub lost: crate::loss::Notes, /// How many values of each band changed when read as `f32` (Int32 IDs past 16,777,216, Float64 /// values with more digits than `f32` holds), by band; empty when none did. NaN values and /// samples that are the no-data value aren't counted (one that rounds onto it is). The two are @@ -986,7 +986,7 @@ impl Raster { posts: false, georeferenced: true, crs_assumed: false, - lost: Vec::new(), + lost: Default::default(), rounded: Vec::new(), rounded_some: Vec::new(), copyright: None, @@ -1006,7 +1006,8 @@ impl Raster { /// overview's only approximate them). What it left out is said as `from`'s ("its GDAL /// metadata", "its .aux.xml sidecar"). pub fn apply_pam(&mut self, pam: &pam::Pam, from: &str) { - self.lost.extend(pam.lost.iter().map(|l| format!("{from}: {l}"))); + // Each with its code, named by where it came from. + self.lost.extend(pam.lost.iter().map(|l| l.clone().prefixed(from))); // Names and wavelengths for bands the raster doesn't have have nowhere to go. let beyond = pam .bands @@ -1753,7 +1754,10 @@ pub fn read_converted(path: &Path, c: &gdal::Converted) -> Result { // it is read, as a reload says them again. if c.assumed_lonlat { r.crs_assumed = true; - r.lost.push(format!("{} (give \"crs\" if not)", assumed_wgs84_note("it doesn't say its coordinate system"))); + r.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::AssumedCrs, + format!("{} (give \"crs\" if not)", assumed_wgs84_note("it doesn't say its coordinate system")), + )); } if !c.others.is_empty() { let shown: Vec<&str> = c.others.iter().take(20).map(String::as_str).collect(); @@ -2631,7 +2635,7 @@ pub(crate) mod tests { one.apply_pam( &pam::Pam { bands: vec![pam::PamBand { band: 2, description: Some("NIR".into()), ..Default::default() }], - lost: vec!["1 band record(s) for no band from 1 to 65536 left out".into()], + lost: vec!["1 band record(s) for no band from 1 to 65536 left out"].into(), }, pam::SIDECAR, ); @@ -2644,7 +2648,7 @@ pub(crate) mod tests { let mut zero = small(); zero.nodata = None; zero.apply_pam( - &pam::Pam { bands: vec![pam::PamBand { band: 2, nodata: Some(0.0), ..Default::default() }], lost: Vec::new() }, + &pam::Pam { bands: vec![pam::PamBand { band: 2, nodata: Some(0.0), ..Default::default() }], lost: Default::default() }, pam::SIDECAR, ); assert_eq!(zero.nodata, None); @@ -2656,7 +2660,7 @@ pub(crate) mod tests { pam::PamBand { band: 1, nodata: Some(a), ..Default::default() }, pam::PamBand { band: 1, nodata: Some(b), ..Default::default() }, ], - lost: Vec::new(), + lost: Default::default(), }; two.apply_pam(&both(0.0, 255.0), pam::SIDECAR); assert_eq!(two.nodata, None); @@ -2896,7 +2900,7 @@ pub(crate) mod tests { std::fs::write(dir.join("g.prj"), "not a coordinate system").unwrap(); let r = read_path(&asc).unwrap(); assert_eq!(r.lost.len(), 1, "{:?}", r.lost); - let note = &r.lost[0]; + let note = &r.lost[0].text; assert!(note.starts_with("the .prj file: ") && note.contains("so it's read as WGS 84"), "{note}"); assert!(!note.contains("it doesn't say its coordinate system"), "{note}"); std::fs::write(&asc, "ncols 2\nnrows 1\nxllcorner 1000\nyllcorner 4000\ncellsize 1\n1 2\n").unwrap(); diff --git a/crates/data/src/raster/pam.rs b/crates/data/src/raster/pam.rs index d56865fd7f..1e2a858ce9 100644 --- a/crates/data/src/raster/pam.rs +++ b/crates/data/src/raster/pam.rs @@ -70,7 +70,7 @@ pub struct Pam { pub bands: Vec, /// What [`parse`] or [`parse_gdal_metadata`] left out or cut, one line a kind with a count, /// for the caller to say (AGENTS.md, Never silent). Empty when the document is read whole. - pub lost: Vec, + pub lost: crate::loss::Notes, } /// Where [`Raster::apply_pam`](super::Raster::apply_pam) says a document's losses came from: a @@ -82,7 +82,7 @@ pub const SIDECAR: &str = "its .aux.xml sidecar"; impl Pam { /// A document that names nothing, with the reason it was left out. pub fn losing(why: String) -> Pam { - Pam { bands: Vec::new(), lost: vec![why] } + Pam { bands: Vec::new(), lost: vec![why].into() } } /// The band numbered `band` (from 1). @@ -423,7 +423,10 @@ fn parse_sidecar(text: &str) -> Result { pam.lost.push(format!("{units_again} other wavelength unit(s) for a band or the dataset left out (the first is kept)")); } if beyond > 0 { - pam.lost.push(format!("{beyond} class name(s) past the first {MAX_CATEGORIES} of a band left out")); + pam.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedOverLimit, + format!("{beyond} class name(s) past the first {MAX_CATEGORIES} of a band left out"), + )); } if rat.ranges > 0 { pam.lost.push(format!("{} attribute table(s) of value ranges not read as class names", rat.ranges)); @@ -448,19 +451,25 @@ fn parse_sidecar(text: &str) -> Result { pam.lost.push(format!("{} class name(s) of an attribute table given again for a value left out (the first is kept)", rat.again)); } if rat.rows > 0 { - pam.lost.push(format!("{} attribute table row(s) past the first {MAX_RAT_ROWS} left out", rat.rows)); + pam.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedOverLimit, + format!("{} attribute table row(s) past the first {MAX_RAT_ROWS} left out", rat.rows), + )); } if rat.over > 0 { - pam.lost.push(format!( - "{} class name(s) of an attribute table past the sidecar's first {MAX_RAT_SLOTS} class values left out", - rat.over + pam.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedOverLimit, + format!("{} class name(s) of an attribute table past the sidecar's first {MAX_RAT_SLOTS} class values left out", rat.over), )); } if rat.named > 0 { pam.lost.push(format!("{} attribute table(s) of class names not read: the band's category names are used", rat.named)); } if cut > 0 { - pam.lost.push(format!("{cut} band or class name(s) cut to {MAX_NAME} characters")); + pam.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::ChangedCut, + format!("{cut} band or class name(s) cut to {MAX_NAME} characters"), + )); } Ok(pam) } @@ -734,7 +743,10 @@ pub fn parse_gdal_metadata(text: &str) -> Option { pam.lost.push(format!("{twice} band or class name(s) given again left out (the first is kept)")); } if cut > 0 { - pam.lost.push(format!("{cut} band or class name(s) cut to {MAX_NAME} characters")); + pam.lost.push(crate::loss::Note::loss( + crate::loss::LossCode::ChangedCut, + format!("{cut} band or class name(s) cut to {MAX_NAME} characters"), + )); } if !classes.is_empty() { match pam.bands.iter_mut().find(|b| b.band == 1) { @@ -890,7 +902,7 @@ mod tests { let pam = parse_gdal_metadata(&xml).unwrap(); assert_eq!(pam.band(1).unwrap().categories[1], "Forest"); assert_eq!(pam.band(1).unwrap().categories[2].chars().count(), 256); - let said = pam.lost.join("; "); + let said = pam.lost.texts().collect::>().join("; "); for want in ["1 band description(s) for no band", "2 CLASS_ item(s)", "1 band or class name(s) given again", "1 band or class name(s) cut"] { @@ -986,7 +998,10 @@ mod tests { ); assert_eq!(parse(&long).unwrap().band(1).unwrap().categories[0].len(), 256); // What is cut or left out is said; a sidecar read whole says nothing. - assert_eq!(parse(&long).unwrap().lost, ["1 band or class name(s) cut to 256 characters"]); + assert_eq!( + parse(&long).unwrap().lost.iter().map(|n| (n.text.as_str(), n.loss)).collect::>(), + [("1 band or class name(s) cut to 256 characters", Some(crate::loss::LossCode::ChangedCut))] + ); assert!(pam.lost.is_empty(), "{:?}", pam.lost); let many = format!( r#"{}"#, @@ -996,7 +1011,13 @@ mod tests { let kept = &many.band(1).unwrap().categories; assert_eq!((kept.len(), kept[0].as_str()), (MAX_CATEGORIES, "c0")); assert_eq!(kept[MAX_CATEGORIES - 1], format!("c{}", MAX_CATEGORIES - 1)); - assert_eq!(many.lost, [format!("2 class name(s) past the first {MAX_CATEGORIES} of a band left out")]); + assert_eq!( + many.lost.iter().map(|n| (n.text.clone(), n.loss)).collect::>(), + [( + format!("2 class name(s) past the first {MAX_CATEGORIES} of a band left out"), + Some(crate::loss::LossCode::DroppedOverLimit) + )] + ); // A record for no band, a scale, an offset and a unit are said; a scale of 1 and an offset // of 0 aren't. let odd = parse( @@ -1155,8 +1176,11 @@ mod tests { let held: usize = pam.bands.iter().map(|b| b.categories.len()).sum(); assert!(held <= MAX_RAT_SLOTS, "{held}"); assert_eq!( - pam.lost, - [format!("3 class name(s) of an attribute table past the sidecar's first {MAX_RAT_SLOTS} class values left out")] + pam.lost.iter().map(|n| (n.text.clone(), n.loss)).collect::>(), + [( + format!("3 class name(s) of an attribute table past the sidecar's first {MAX_RAT_SLOTS} class values left out"), + Some(crate::loss::LossCode::DroppedOverLimit) + )] ); } @@ -1205,7 +1229,8 @@ mod tests { let many = vec![&["n"][..]; MAX_RAT_ROWS + 3]; let many = parse(&table("", &[("Name", 2, 2)], &many)).unwrap(); assert!( - many.lost.iter().any(|l| l == &format!("3 attribute table row(s) past the first {MAX_RAT_ROWS} left out")), + many.lost.iter().any(|l| l.text == format!("3 attribute table row(s) past the first {MAX_RAT_ROWS} left out") + && l.loss == Some(crate::loss::LossCode::DroppedOverLimit)), "{:?}", many.lost ); diff --git a/crates/data/src/raster/zarr.rs b/crates/data/src/raster/zarr.rs index 56dcb88a16..a414a670b4 100644 --- a/crates/data/src/raster/zarr.rs +++ b/crates/data/src/raster/zarr.rs @@ -2071,15 +2071,20 @@ pub fn assemble(store: &Store, plan: &Plan, chunks: &HashMap>, n let found = crs_of(store, a); let unread = if found.is_none() { unread_proj(a) } else { None }; let mut crs_assumed = false; - let (crs, crs_notes): (Option, Vec) = if lonlat { + // Read as WGS 84 against what the store says (or doesn't): an assumption, with its code. + let (crs, crs_notes): (Option, Vec) = if lonlat { let assumed = lonlat_assumption(found.as_ref().map(|(c, _)| *c), crs); crs_assumed = assumed.is_some(); let (actual, note) = found.unwrap_or((Crs::LonLat, None)); - (Some(if actual.is_geographic() { actual } else { Crs::LonLat }), note.into_iter().chain(assumed).collect()) + let assumed = assumed.map(|a| crate::loss::Note::loss(crate::loss::LossCode::AssumedCrs, a)); + ( + Some(if actual.is_geographic() { actual } else { Crs::LonLat }), + note.into_iter().map(crate::loss::Note::plain).chain(assumed).collect(), + ) } else { match found { - Some((crs, note)) => (Some(crs), note.into_iter().collect()), - None => (crs, crs.and_then(super::planetary::note_of).into_iter().collect()), + Some((crs, note)) => (Some(crs), note.into_iter().map(crate::loss::Note::plain).collect()), + None => (crs, crs.and_then(super::planetary::note_of).into_iter().map(crate::loss::Note::plain).collect()), } }; let Some(crs) = crs else { @@ -2121,7 +2126,8 @@ pub fn assemble(store: &Store, plan: &Plan, chunks: &HashMap>, n } r.crs_assumed = crs_assumed; r.lost.extend(crs_notes); - r.lost.extend(unread); + // The store's `proj:` keys that name no system read: its system's name isn't kept. + r.lost.extend(unread.map(|u| crate::loss::Note::loss(crate::loss::LossCode::DroppedCrsName, u))); // A transform the coordinates stood in for is said, not dropped without a word. if has_transform(a) && spatial_grid(a).is_none() { r.lost.push(format!("{}: {TRANSFORM_UNREAD}: its coordinates place it", a.path)); @@ -3560,29 +3566,37 @@ mod tests { let (want, note) = wkt::read_wkt(ed50).unwrap(); let r = read(serde_json::json!({"crs_wkt": ed50}), &lons); assert!(want != Crs::LonLat && want.is_geographic()); - assert_eq!((r.crs, r.lost.clone()), (want, note.into_iter().collect::>()), "{:?}", r.lost); + assert_eq!( + (r.crs, r.lost.texts().map(String::from).collect::>()), + (want, note.into_iter().collect::>()), + "{:?}", + r.lost + ); let moved = r.crs.transformer().unwrap().to_lonlat(rustgis_geom::Coord::new(10.0, 50.0)).unwrap(); assert!((moved.x - 10.0).abs() > 1e-4 || (moved.y - 50.0).abs() > 1e-4, "{moved:?}"); let osgb36 = wkt::to_wkt(Crs::Epsg(4277)).unwrap(); let (want, note) = wkt::read_wkt(&osgb36).unwrap(); let r = read(serde_json::json!({"crs_wkt": osgb36}), &lons); assert!(want != Crs::LonLat && want.is_geographic()); - assert_eq!((r.crs, r.lost), (want, note.into_iter().collect::>())); + assert_eq!((r.crs, r.lost.texts().map(String::from).collect::>()), (want, note.into_iter().collect::>())); let (want, note) = wkt::read_wkt(local).unwrap(); let r = read(serde_json::json!({"crs_wkt": local}), &lons); assert!(want != Crs::LonLat && want.is_geographic()); assert!(note.as_deref().is_some_and(|n| n.contains("has no conversion to WGS 84")), "{note:?}"); - assert_eq!((r.crs, r.lost), (want, note.into_iter().collect::>())); + assert_eq!((r.crs, r.lost.texts().map(String::from).collect::>()), (want, note.into_iter().collect::>())); // Another body's: kept, and said once, by its body. let (want, note) = wkt::read_wkt(mars).unwrap(); assert!(want.is_planetary()); let r = read(serde_json::json!({"crs_wkt": mars}), &lons); - assert_eq!((r.crs, r.lost), (want, note.into_iter().collect::>())); + assert_eq!((r.crs, r.lost.texts().map(String::from).collect::>()), (want, note.into_iter().collect::>())); let proj = "+proj=longlat +a=3396190 +b=3396190 +no_defs"; let want = Crs::parse(proj).unwrap(); assert!(want.is_planetary()); let r = read(serde_json::json!({"proj4": proj}), &lons); - assert_eq!((r.crs, r.lost), (want, planetary::note_of(want).into_iter().collect::>())); + assert_eq!( + (r.crs, r.lost.texts().map(String::from).collect::>()), + (want, planetary::note_of(want).into_iter().collect::>()) + ); // A PROJ definition says what its WKT would: no datum shift is said once, a shift or a datum isn't. for (def, said) in [ ("+proj=longlat +ellps=intl +no_defs", true), @@ -3599,20 +3613,27 @@ mod tests { for code in [4326u32, 4230] { let want = Crs::from_epsg(code).unwrap(); let r = read(serde_json::json!({"epsg_code": code}), &lons); - assert_eq!((r.crs, r.lost), (want, Vec::new()), "EPSG:{code}"); + assert_eq!((r.crs, r.lost.texts().map(String::from).collect::>()), (want, Vec::::new()), "EPSG:{code}"); } let wgs84 = wkt::to_wkt(Crs::LonLat).unwrap(); for attrs in [serde_json::json!({"crs_wkt": wgs84}), serde_json::json!({"crs_wkt": "EPSG:4326"})] { let r = read(attrs.clone(), &lons); - assert_eq!((r.crs, r.lost), (Crs::LonLat, Vec::new()), "{attrs}"); + assert_eq!((r.crs, r.lost.texts().map(String::from).collect::>()), (Crs::LonLat, Vec::new()), "{attrs}"); } // No system at all, or a projected one on degree axes: the axes win, and the WGS 84 reading is said. let said = |why: &str| vec![crate::raster::assumed_wgs84_note(why)]; let r = read(serde_json::json!({}), &lons); - assert_eq!((r.crs, r.lost), (Crs::LonLat, said("the store doesn't say its coordinate system")), "no system"); + assert_eq!( + (r.crs, r.lost.texts().map(String::from).collect::>()), + (Crs::LonLat, said("the store doesn't say its coordinate system")), + "no system" + ); let utm17 = wkt::to_wkt(Crs::Epsg(32617)).unwrap(); let r = read(serde_json::json!({"crs_wkt": utm17}), &lons); - assert_eq!((r.crs, r.lost), (Crs::LonLat, said("its coordinate system isn't geographic"))); + assert_eq!( + (r.crs, r.lost.texts().map(String::from).collect::>()), + (Crs::LonLat, said("its coordinate system isn't geographic")) + ); // A geographic system's longitudes of 0–360 are turned to start at -180, as WGS 84's are. let r = read(serde_json::json!({"crs_wkt": ed50}), &[190.5, 191.5]); assert!(r.crs != Crs::LonLat); @@ -4243,7 +4264,7 @@ mod tests { let mut long = odd.clone(); long["consolidated_metadata"]["metadata"]["v"]["attributes"]["proj:code"] = format!("X{}", "y".repeat(10_000)).into(); let r = assemble(&read(&long), &p, &read_plan(&files, &p), "v", None).unwrap(); - let note = r.lost.iter().find(|l| l.contains("proj:code")).unwrap(); + let note = &r.lost.iter().find(|l| l.contains("proj:code")).unwrap().text; assert!(note.len() < 300 && note.contains("(10003 characters)"), "{note}"); // A proj: value that is read says nothing. let clean = read(&root); diff --git a/crates/engine/src/cmd/cube.rs b/crates/engine/src/cmd/cube.rs index 78e9b63991..586b1f3d61 100644 --- a/crates/engine/src/cmd/cube.rs +++ b/crates/engine/src/cmd/cube.rs @@ -99,7 +99,7 @@ pub trait TimeCube: Send + Sync { /// What reading its slices said (a shift a Zarr store's system doesn't apply, …), once each, /// asked once every slice is read: the outputs are on their grid, so it is said of them too. /// A stack's slices are layers, whose notices were said when they were added. - fn lost(&self) -> Vec { + fn lost(&self) -> Vec { Vec::new() } /// Whether its dates are masked by a quality band (a STAC collection's `"mask"`), so each @@ -120,7 +120,7 @@ pub trait TimeCube: Send + Sync { fn with_lost(outputs: Result, String>, cube: &dyn TimeCube) -> Result, String> { let mut outputs = outputs?; if let Some(first) = outputs.first_mut() { - first.lost = cube.lost(); + first.lost = cube.lost().into(); } Ok(outputs) } @@ -172,7 +172,7 @@ impl TimeCube for Stack { /// A Zarr variable along its time dimension, and what reading its slices said, once each. #[cfg(not(target_arch = "wasm32"))] -struct ZarrCube(super::zarr::ZarrCube, std::sync::Mutex>); +struct ZarrCube(super::zarr::ZarrCube, std::sync::Mutex>); #[cfg(not(target_arch = "wasm32"))] impl TimeCube for ZarrCube { @@ -200,7 +200,7 @@ impl TimeCube for ZarrCube { } Ok(Some((r, 0))) } - fn lost(&self) -> Vec { + fn lost(&self) -> Vec { self.1.lock().unwrap_or_else(std::sync::PoisonError::into_inner).clone() } fn label(&self) -> String { diff --git a/crates/engine/src/cmd/embeddings.rs b/crates/engine/src/cmd/embeddings.rs index a7151863c7..3debbf353c 100644 --- a/crates/engine/src/cmd/embeddings.rs +++ b/crates/engine/src/cmd/embeddings.rs @@ -961,11 +961,11 @@ pub(crate) fn two_years_notes(a: &super::layer::WindowRaster, b: &super::layer:: notes.push(format!("the {to} file: {n}")); } } - for l in &a.raster.lost { - let both = b.raster.lost.contains(l); + for l in a.raster.lost.texts() { + let both = b.raster.lost.says(l); notes.push(if both { format!("the {from} and {to} files: {l}") } else { format!("the {from} file: {l}") }); } - notes.extend(b.raster.lost.iter().filter(|l| !a.raster.lost.contains(l)).map(|l| format!("the {to} file: {l}"))); + notes.extend(b.raster.lost.texts().filter(|l| !a.raster.lost.says(l)).map(|l| format!("the {to} file: {l}"))); notes } diff --git a/crates/engine/src/cmd/imagery.rs b/crates/engine/src/cmd/imagery.rs index 2cbe75df24..d6fa02e15f 100644 --- a/crates/engine/src/cmd/imagery.rs +++ b/crates/engine/src/cmd/imagery.rs @@ -2481,9 +2481,9 @@ impl Tiles { .iter() .skip(1) .filter(|r| r.copyright.is_some() && r.copyright != first.copyright) - .map(|r| (r.name.clone(), "its copyright differs from the first input's and is not kept in the mosaic".to_string())) + .map(|r| (r.name.clone(), rustgis_data::loss::Note::plain("its copyright differs from the first input's and is not kept in the mosaic"))) .collect(); - notes.extend(super::raster::loss_lines(credits).into_iter().map(|n| (n, false))); + notes.extend(super::raster::loss_lines(credits).into_iter().map(|n| (n.text, false))); // Cells rounded when an input was read may be among those the mosaic keeps. out.keep_rounded_marks(rs.iter().map(|r| &**r)); let other: Vec<&str> = @@ -2548,7 +2548,7 @@ pub(crate) fn mosaic_rasters_work(s: &Session, p: &Value) -> Result = Vec::new(); + let mut lost: Vec<(String, rustgis_data::loss::Note)> = Vec::new(); for input in rest { rustgis_data::progress::check().map_err(|e| e.to_string())?; let r = match input? { @@ -2561,7 +2561,8 @@ pub(crate) fn mosaic_rasters_work(s: &Session, p: &Value) -> Result Result { // The inputs are let go of once joined, before the file is written. let out = tiles.join(given, &mut notes)?; diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 17f561c12e..300df0bde4 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -4775,14 +4775,14 @@ pub(crate) fn add_layer_text_within(s: &mut Session, text: &str, reach: crate::r s.active_layer = Some(id); // What reading its raster left out is said, as for a raster added (one still read in the // background isn't here yet). - let lost: Vec = s + let lost: Vec = s .map() .layer(id) .and_then(|l| Some((&l.name, l.raster.as_ref()?.data.as_ref()?))) - .map(|(name, d)| d.lost.iter().map(|l| format!("{name}: {l}")).collect()) + .map(|(name, d)| d.lost.iter().map(|l| l.clone().prefixed(name)).collect()) .unwrap_or_default(); for l in lost { - s.notify(l, false); + s.say(l); } Ok(json!({"layer": id})) } @@ -6052,7 +6052,7 @@ pub(crate) fn add_cog_with(s: &mut Session, p: &Value, url: &str, strict: bool, } } for line in cog_tile_losses(&info) { - s.notify(format!("{shown}: {line}"), false); + s.say(line.prefixed(&shown)); } } else if probed || why.is_some() || r.get("dated").is_some() { // Added, but its (first date's) file couldn't be read: the view stays where it was. @@ -6092,16 +6092,18 @@ pub(crate) fn cog_tile_where(t: &rustgis_map::tiles::TileLayer, address: &str) - /// drawn in place, its tiles are drawn as values (a palette image's by its colour table), so what /// the header holds beside them (band and class names, wavelengths) comes only with a window. Said /// as the layer is added, or once its header lands ([`Session::notice_landed_rasters`]). -pub(crate) fn cog_tile_losses(info: &crate::render::rustgis_tiles::cog::Info) -> Vec { +pub(crate) fn cog_tile_losses(info: &crate::render::rustgis_tiles::cog::Info) -> Vec { let l = &info.layout; let named = l .described .as_ref() .is_some_and(|d| d.bands.iter().any(|b| b.description.is_some() || !b.categories.is_empty() || b.wavelength.is_some())); - let mut said: Vec = l.lost.clone(); - said.extend(l.described.iter().flat_map(|d| d.lost.iter().map(|x| format!("{}: {x}", rustgis_data::raster::pam::GDAL_METADATA)))); + let mut said: Vec = l.lost.to_vec(); + said.extend(l.described.iter().flat_map(|d| d.lost.iter().map(|x| x.clone().prefixed(rustgis_data::raster::pam::GDAL_METADATA)))); if named { - said.push("drawn in place without its band names, class names or wavelengths: a window (\"bbox\") reads them".into()); + said.push(rustgis_data::loss::Note::plain( + "drawn in place without its band names, class names or wavelengths: a window (\"bbox\") reads them", + )); } said } @@ -6644,7 +6646,10 @@ pub(crate) fn read_window_raster(asked: &WindowAsked, stop: &std::sync::atomic:: r.rounded = rounded; } if overflowed > 0 { - r.lost.push(format!("{overflowed} value(s) past the range of 32-bit floats left out: those cells have no value")); + r.lost.push(rustgis_data::loss::Note::loss( + rustgis_data::loss::LossCode::DroppedValue, + format!("{overflowed} value(s) past the range of 32-bit floats left out: those cells have no value"), + )); } // What the header holds but isn't read (a colour table, names): said when the layer is added. r.lost.extend(layout.lost.iter().cloned()); @@ -6735,7 +6740,7 @@ impl WindowRaster { /// holds but isn't read, values past `f32`'s range), for a caller that makes another raster /// from it and so doesn't add this one (whose `lost` the layer would say). pub(crate) fn notes(&self) -> Vec { - self.read_notes().into_iter().chain(self.raster.lost.iter().cloned()).collect() + self.read_notes().into_iter().chain(self.raster.lost.texts().map(String::from)).collect() } /// What to say of the read alone (its size and level, a cell size finer than the file's, the diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 02f00f24df..7cef2d6bce 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -344,7 +344,7 @@ fn reset(s: &mut Session, p: Project) { s.wait_in_place_reads(); // What reading a raster left out (a colour table, names, a sidecar's scale) is said again as // the project opens, as when it was added. One still read in the background isn't here yet. - let mut lost: Vec<(String, String)> = Vec::new(); + let mut lost: Vec<(String, rustgis_data::loss::Note)> = Vec::new(); for l in s.project.maps.iter_mut().flat_map(|m| &mut m.layers) { if let Some(rl) = &mut l.raster { lost.extend(rl.lost_unsaid().into_iter().map(|what| (l.name.clone(), what))); diff --git a/crates/engine/src/cmd/raster.rs b/crates/engine/src/cmd/raster.rs index 6356e37064..1081e3b885 100644 --- a/crates/engine/src/cmd/raster.rs +++ b/crates/engine/src/cmd/raster.rs @@ -407,7 +407,7 @@ pub(super) fn read_notices(s: &mut Session, name: &str, layer: &mut RasterLayer) s.notify(format!("{name}: showing a {} × {} overview of the {fw} × {fh} raster", r.width, r.height), false); } for loss in lost { - s.notify(format!("{name}: {loss}"), false); + s.say(loss.prefixed(name)); } if let Some(r) = pixels.as_deref() { if let Some(held) = layer.reads_in_place().then(|| crate::in_place_overview(r, layer.tiled)).flatten() { @@ -494,9 +494,9 @@ pub(crate) fn as_scan(p: &Value) -> Result { } /// Says what reading several rasters left out ([`loss_lines`]), a notice a line. -pub(crate) fn say_losses(s: &mut Session, losses: Vec<(String, String)>) { +pub(crate) fn say_losses(s: &mut Session, losses: Vec<(String, rustgis_data::loss::Note)>) { for line in loss_lines(losses) { - s.notify(line, false); + s.say(line); } } @@ -508,7 +508,7 @@ pub(crate) fn say_losses(s: &mut Session, losses: Vec<(String, String)>) { /// numbers are the same for every raster the kind is said once; when they differ, each raster's /// own line is said (three rasters or fewer), or the range they give, for each of them ("4 /// rasters (a, b, c, …), each: 1–2 scale…"): never summed, since a size limit isn't a count. -pub(crate) fn loss_lines(losses: Vec<(String, String)>) -> Vec { +pub(crate) fn loss_lines(losses: Vec<(String, rustgis_data::loss::Note)>) -> Vec { // A line's kind: its text with each number taken out, and those numbers. A number is a run of // digits standing as a word of its own: one inside a name (`scene2024.tif`) stays text. fn kind_of(line: &str) -> (Vec<&str>, Vec) { @@ -542,29 +542,31 @@ pub(crate) fn loss_lines(losses: Vec<(String, String)>) -> Vec { parts.push(&line[from..]); (parts, numbers) } - // Each kind: its text parts, each number's lowest and highest, and the rasters with their - // own lines. - type Kind = (Vec, Vec<(u64, u64)>, Vec<(String, String)>); + // Each kind: its loss code, its text parts, each number's lowest and highest, and the + // rasters with their own lines. Lines of different codes are different kinds. + type Kind = (Option, Vec, Vec<(u64, u64)>, Vec<(String, String)>); let mut kinds: Vec = Vec::new(); - for (name, line) in losses { + for (name, note) in losses { + let (code, line) = (note.loss, note.text); let (parts, numbers) = kind_of(&line); let parts_owned: Vec = parts.iter().map(|p| p.to_string()).collect(); - match kinds.iter_mut().find(|(p, n, _)| *p == parts_owned && n.len() == numbers.len()) { - Some((_, ranges, named)) => { + match kinds.iter_mut().find(|(c, p, n, _)| *c == code && *p == parts_owned && n.len() == numbers.len()) { + Some((_, _, ranges, named)) => { for (r, n) in ranges.iter_mut().zip(&numbers) { *r = (r.0.min(*n), r.1.max(*n)); } named.push((name, line)); } - None => kinds.push((parts_owned, numbers.iter().map(|n| (*n, *n)).collect(), vec![(name, line)])), + None => kinds.push((code, parts_owned, numbers.iter().map(|n| (*n, *n)).collect(), vec![(name, line)])), } } let mut lines = Vec::new(); - for (parts, ranges, named) in kinds { + for (code, parts, ranges, named) in kinds { + let line = |text: String| rustgis_data::loss::Note { loss: code, text }; let differ = ranges.iter().any(|(lo, hi)| lo != hi); // A few rasters whose numbers differ: each its own, so none is lost in a range. if differ && named.len() <= 3 { - lines.extend(named.into_iter().map(|(name, line)| format!("{name}: {line}"))); + lines.extend(named.into_iter().map(|(name, l)| line(format!("{name}: {l}")))); continue; } let names: Vec = named.into_iter().map(|(name, _)| name).collect(); @@ -583,7 +585,7 @@ pub(crate) fn loss_lines(losses: Vec<(String, String)>) -> Vec { } }; let each = if differ { ", each" } else { "" }; - lines.push(format!("{who}{each}: {line}")); + lines.push(rustgis_data::loss::Note { loss: code, text: format!("{who}{each}: {line}") }); } lines } @@ -804,7 +806,11 @@ fn add_jpeg2000_bytes(s: &mut Session, p: &Value, name: &str, bytes: Vec, zo // The GeoTIFF GDAL made names the WGS 84 it assumed, as if the file had. r.crs_assumed |= c.assumed_lonlat; if c.assumed_lonlat { - s.notify(format!("{name} doesn't say its coordinate system; its coordinates look like longitude/latitude, so it's read as WGS 84 (give \"crs\" if not)"), false); + // As reading the converted file by path says it: an assumption, with its code. + s.say(rustgis_data::loss::Note::loss( + rustgis_data::loss::LossCode::AssumedCrs, + format!("{name} doesn't say its coordinate system; its coordinates look like longitude/latitude, so it's read as WGS 84 (give \"crs\" if not)"), + )); } let title = ps(p, "name").map(str::trim).filter(|n| !n.is_empty()).map(str::to_string).unwrap_or_else(|| r.name.clone()); add_raster_after(s, &title, RasterLayer::from_bytes(r, file_name, c.tif), zoom) @@ -1538,7 +1544,7 @@ mod tests { let said = |losses: &[(&str, &str)]| { let mut s = Session::new(crate::Project::default()); let mark = s.notice_mark(); - say_losses(&mut s, losses.iter().map(|(n, l)| (n.to_string(), l.to_string())).collect()); + say_losses(&mut s, losses.iter().map(|(n, l)| (n.to_string(), rustgis_data::loss::Note::plain(*l))).collect()); s.notices_since(mark).iter().map(|n| n.text.clone()).collect::>() }; let cut = |n: u32| format!("{n} band or class name(s) cut to 256 characters"); @@ -1549,5 +1555,18 @@ mod tests { said(&[("a", &one), ("b", &three), ("c", &two), ("d", &one)]), ["4 rasters (a, b, c, …), each: 1–3 band or class name(s) cut to 256 characters"] ); + // The same words with a code and without are two kinds, each said with its own. + let mut s = Session::new(crate::Project::default()); + let mark = s.notice_mark(); + let coded = rustgis_data::loss::Note::loss(rustgis_data::loss::LossCode::ChangedCut, two.clone()); + say_losses( + &mut s, + vec![("a".into(), coded.clone()), ("b".into(), coded), ("c".into(), rustgis_data::loss::Note::plain(two.clone()))], + ); + let got: Vec<_> = s.notices_since(mark).iter().map(|n| (n.text.clone(), n.loss())).collect(); + assert_eq!( + got, + [(format!("2 rasters (a, b): {two}"), Some(rustgis_data::loss::LossCode::ChangedCut)), (format!("c: {two}"), None)] + ); } } diff --git a/crates/engine/src/cmd/stac.rs b/crates/engine/src/cmd/stac.rs index 78efa23cca..a3c5372bfb 100644 --- a/crates/engine/src/cmd/stac.rs +++ b/crates/engine/src/cmd/stac.rs @@ -1128,12 +1128,16 @@ impl super::cube::TimeCube for StacCube { } /// Band pixels their item's mask file doesn't cover: left out as not clear, and said with /// their count and the first such mask. - fn lost(&self) -> Vec { + fn lost(&self) -> Vec { + // Pixels with a value left out as not clear: a value lost. match self.uncovered.lock().map(|u| u.clone()) { - Ok((n, Some(href))) if n > 0 => vec![crate::sources::message_with_address( - &href, - &format!( - "{n} band pixel(s) with a value lie outside their item's mask file (this one the first), so they were left out as not clear" + Ok((n, Some(href))) if n > 0 => vec![rustgis_data::loss::Note::loss( + rustgis_data::loss::LossCode::DroppedValue, + crate::sources::message_with_address( + &href, + &format!( + "{n} band pixel(s) with a value lie outside their item's mask file (this one the first), so they were left out as not clear" + ), ), )], _ => Vec::new(), diff --git a/crates/engine/src/cmd/zarr.rs b/crates/engine/src/cmd/zarr.rs index 071596b8fe..f737ca15c8 100644 --- a/crates/engine/src/cmd/zarr.rs +++ b/crates/engine/src/cmd/zarr.rs @@ -415,7 +415,7 @@ pub fn pick_variable(store: &zarr::Store, sel: &mut zarr::Selection) -> Result<( #[cfg(not(target_arch = "wasm32"))] fn crs_lost(r: &mut raster::Raster, text: Option<&str>, store: &zarr::Store, variable: &str) { if let Some(note) = text.and_then(|t| zarr::typed_crs_note(store, variable, r, t)) - && !r.lost.contains(¬e) + && !r.lost.says(¬e) { r.lost.push(note); } @@ -1835,7 +1835,7 @@ impl ReduceRun { let mut unwritten = 0usize; // What reading the slices said (a shift the store's system doesn't apply, …), once each: // the summary is in their grid, so it is said of it too. - let mut lost: Vec = Vec::new(); + let mut lost: Vec = Vec::new(); for &i in &self.steps { if cancel.load(Ordering::Relaxed) { return Err("cancelled".into()); @@ -1904,7 +1904,7 @@ impl ReduceRun { raster::Raster::new(&self.name, first.0, first.1, vec![out], first.2, first.3, None, raster::ColorHint::Gray, "Float32") .map_err(|e| e.to_string())?; r.source = Some(self.root.clone()); - r.lost = lost; + r.lost = lost.into(); Ok(r) } } diff --git a/crates/engine/tests/integration/portable_projects/reload.rs b/crates/engine/tests/integration/portable_projects/reload.rs index 894e5b3588..565a7153a5 100644 --- a/crates/engine/tests/integration/portable_projects/reload.rs +++ b/crates/engine/tests/integration/portable_projects/reload.rs @@ -493,7 +493,7 @@ fn raster_reload_and_repair_disclose_fresh_losses_once_without_repeating_them_on s.notice_landed_rasters(); s.notice_landed_rasters(); for loss in losses { - assert_eq!(s.notices_since(mark).iter().filter(|n| n.text.ends_with(&loss)).count(), 1, "{command}: {loss}"); + assert_eq!(s.notices_since(mark).iter().filter(|n| n.text.ends_with(loss.as_str())).count(), 1, "{command}: {}", loss.text); } } raster_file(&moved, 1); diff --git a/crates/geolibre/src/lib.rs b/crates/geolibre/src/lib.rs index d7a9813459..dd9ba4c55b 100644 --- a/crates/geolibre/src/lib.rs +++ b/crates/geolibre/src/lib.rs @@ -1136,7 +1136,7 @@ fn colours_split(grey: &rustgis_data::raster::Raster, bytes: &[u8], layer_name: "{layer_name}: its one band of packed colours (alpha, blue, green and red bytes) was split into red, green and blue bands, see-through where alpha is 0 or the pixel is no-data" )); // What reading the tool's file left out, which the rewritten file no longer shows. - messages.extend(grey.lost.iter().map(|l| format!("{layer_name}: {l}"))); + messages.extend(grey.lost.texts().map(|l| format!("{layer_name}: {l}"))); rgba } Ok(None) => bytes.to_vec(), diff --git a/crates/map/src/raster.rs b/crates/map/src/raster.rs index 5df1209661..a80676c015 100644 --- a/crates/map/src/raster.rs +++ b/crates/map/src/raster.rs @@ -765,7 +765,7 @@ impl RasterLayer { /// What reading its pixels left out (`Raster::lost`), the first time it is asked for after /// they landed, so it is said once: as the layer is added, as its project opens, or when they /// land later (the browser). - pub fn lost_unsaid(&mut self) -> Vec { + pub fn lost_unsaid(&mut self) -> rustgis_data::loss::Notes { if self.lost_said { // A look applied after the pixels' losses were said: what it asked for that the file // hasn't, on its own, not the pixels' losses again. @@ -1298,7 +1298,7 @@ impl RasterLayer { } let mut r = read_path_with(p, subdataset, crs)?; if reopening && !r.georeferenced { - r.lost.push("it has no coordinates now, though it had them when added: it is drawn at a stand-in place".into()); + r.lost.push("it has no coordinates now, though it had them when added: it is drawn at a stand-in place"); } Ok(r) } @@ -2977,7 +2977,7 @@ mod tests { #[test] fn a_look_applied_after_the_losses_were_said_says_its_own_alone() { let mut r = dem(); - r.lost.push("its colour table is left out".into()); + r.lost.push("its colour table is left out"); let mut rl = RasterLayer::in_place(r, "test://look-later.tif"); assert_eq!(rl.lost_unsaid(), vec!["its colour table is left out".to_string()]); assert!(rl.lost_unsaid().is_empty()); @@ -2988,7 +2988,7 @@ mod tests { assert!(rl.lost_unsaid().is_empty()); // A look applied before they are said is said with them, once. let mut r = dem(); - r.lost.push("its colour table is left out".into()); + r.lost.push("its colour table is left out"); let mut rl = RasterLayer::in_place(r, "test://look-first.tif").with_look(AddressLook { bands: vec![9], range: None }); assert_eq!(rl.lost_unsaid().len(), 2); assert!(rl.lost_unsaid().is_empty()); diff --git a/crates/tiles/src/cog.rs b/crates/tiles/src/cog.rs index 98e788d9ca..2cc900545a 100644 --- a/crates/tiles/src/cog.rs +++ b/crates/tiles/src/cog.rs @@ -2222,7 +2222,7 @@ mod tests { let entry = (0..n).map(|k| 10 + k * 12).find(|&e| bad[e..e + 2] == [0x80, 0xA4]).unwrap(); bad[entry + 8..entry + 12].copy_from_slice(&(len + 1000).to_le_bytes()); let (l, ..) = layout_by_ranges(&bad).expect("read"); - let said: Vec<&String> = l.lost.iter().chain(l.described.iter().flat_map(|d| d.lost.iter())).collect(); + let said: Vec<&str> = l.lost.texts().chain(l.described.iter().flat_map(|d| d.lost.texts())).collect(); assert!(said.iter().any(|x| x.contains("band and class names and wavelengths are left out")), "{said:?}"); } diff --git a/crates/ui-egui/src/geolibreui.rs b/crates/ui-egui/src/geolibreui.rs index e2403adb7a..5a9473470c 100644 --- a/crates/ui-egui/src/geolibreui.rs +++ b/crates/ui-egui/src/geolibreui.rs @@ -53,7 +53,7 @@ pub fn start(app: &mut RustGisApp, p: &Value, claim: Option) -> Result<(), impl Read { /// Polls one batch. Missing chunks retain the format's fill values; other errors stop it. A /// finished slice comes with what reading it said (its coordinate system, what it dropped). - fn poll(&mut self) -> Option, Vec), String>> { + fn poll(&mut self) -> Option, rustgis_engine::data::loss::Notes), String>> { let mut error = self.error.take(); self.waiting.retain(|(key, slot)| match slot.lock().unwrap_or_else(|e| e.into_inner()).take() { Some(Ok(bytes)) => { @@ -168,8 +168,9 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { // An old project's completion must not announce losses in the current project. if app.session.download_continues(id).is_ok() { let layer = params.get("name").and_then(Value::as_str).unwrap_or("Zarr"); + // Each with its code, as a layer's read notices are said. for loss in lost { - app.session.notify(crate::i18n::fmt("{layer}: {notice}", &[("layer", layer), ("notice", &loss)]), false); + app.session.say(loss.map_text(|t| crate::i18n::fmt("{layer}: {notice}", &[("layer", layer), ("notice", &t)]))); } } app.add_landed(crate::serviceui::Landed { id, url, params, origin: None }, bytes); diff --git a/crates/ui-egui/src/workspacepanes.rs b/crates/ui-egui/src/workspacepanes.rs index 4a72e2a041..d8647a8def 100644 --- a/crates/ui-egui/src/workspacepanes.rs +++ b/crates/ui-egui/src/workspacepanes.rs @@ -491,7 +491,7 @@ pub struct Reducing { pub cancel: std::sync::Arc, pub done: std::sync::Arc, /// The summary as a GeoTIFF, and what reading its slices said, which the GeoTIFF doesn't carry. - pub result: std::sync::Arc, Vec), String>>>>, + pub result: std::sync::Arc, rustgis_engine::data::loss::Notes), String>>>>, } /// A point's series read on a thread of its own (opengeos/RustGIS#2282): the steps read and @@ -646,8 +646,9 @@ pub fn land_summary(app: &mut RustGisApp) -> bool { // layer's read notices are said: its GeoTIFF doesn't carry it. if added.is_some() { let layer = app.session.active_layer.and_then(|id| app.session.map().layer(id)).map_or(name, |l| l.name.clone()); + // Each with its code, as a layer's read notices are said. for loss in lost { - app.session.notify(crate::i18n::fmt("{layer}: {notice}", &[("layer", &layer), ("notice", &loss)]), false); + app.session.say(loss.map_text(|t| crate::i18n::fmt("{layer}: {notice}", &[("layer", &layer), ("notice", &t)]))); } } } else { diff --git a/crates/ui-egui/src/zarrui.rs b/crates/ui-egui/src/zarrui.rs index 44f33bf6fa..a94fda66b8 100644 --- a/crates/ui-egui/src/zarrui.rs +++ b/crates/ui-egui/src/zarrui.rs @@ -174,7 +174,7 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { // What a typed system says, when the slice is in it, as for a folder's slice. let note = (!typed.is_empty()).then(|| zarr::typed_crs_note(store, &sel.variable, &r, &typed)).flatten(); if let Some(note) = note - && !r.lost.contains(¬e) + && !r.lost.says(¬e) { r.lost.push(note); } @@ -200,7 +200,7 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let added = app.session.active_layer.and_then(|id| app.session.map().layer(id)).map_or(name, |l| l.name.clone()); for loss in lost { - app.session.notify(i18n::fmt("{layer}: {notice}", &[("layer", &added), ("notice", &loss)]), false); + app.session.say(loss.map_text(|t| i18n::fmt("{layer}: {notice}", &[("layer", &added), ("notice", &t)]))); } app.map.invalidate(); } From cb43cfeea907eb02c60be84c8b640c4e5017dd49 Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 07:39:59 -0600 Subject: [PATCH 2/4] feat(data): a DTED datum named but not read is coded approximated.datum (#2371) --- crates/data/src/raster/dted.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/data/src/raster/dted.rs b/crates/data/src/raster/dted.rs index f4a87513c3..b57c647151 100644 --- a/crates/data/src/raster/dted.rs +++ b/crates/data/src/raster/dted.rs @@ -326,9 +326,14 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize } match field(bytes, DSI + 144, 5) { Some("WGS84") => {} + // A datum it names but isn't read: its places are taken on WGS 84, without the shift. Some(other) if !other.trim().is_empty() => { - lost.push(format!("its horizontal datum is {:?}, not WGS84; it is read as WGS 84", other.trim())); + lost.push(crate::loss::Note::loss( + crate::loss::LossCode::ApproximatedDatum, + format!("its horizontal datum is {:?}, not WGS84; it is read as WGS 84", other.trim()), + )); } + // None named: the standard sets WGS 84, so nothing is assumed past it. _ => lost.push("it doesn't name its horizontal datum; it is read as WGS 84, as MIL-PRF-89020B sets"), } let surface = match field(bytes, DSI + 141, 3) { @@ -606,6 +611,21 @@ mod tests { assert!(!r.lost.iter().any(|l| l.contains("checksum")), "{:?}", r.lost); } + /// A datum the file names that isn't WGS84 is read as WGS 84, without its shift, and said with + /// its code; one the file doesn't name is WGS 84 as the standard sets, said plain. + #[test] + fn a_datum_named_but_not_read_is_coded() { + let b = dted("0000000E", "0000000N", (30, 30), (11, 11), |_, _| Some(1)); + let datum = |name: &[u8; 5]| { + let mut b = b.clone(); + b[DSI + 144..DSI + 149].copy_from_slice(name); + read("x.dt1", &b).unwrap().lost.iter().filter(|l| l.contains("horizontal datum")).map(|l| l.loss).collect::>() + }; + assert_eq!(datum(b"NAD27"), [Some(crate::loss::LossCode::ApproximatedDatum)]); + assert_eq!(datum(b" "), [None]); + assert!(datum(b"WGS84").is_empty()); + } + #[test] fn the_dsi_names_the_level() { // 11 × 11 posts of 3″ is no level's spacing: the notice names the level checked against. From d4fce87bf856c1952b24f197a30b43008126693a Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 10:49:46 -0600 Subject: [PATCH 3/4] style(engine): format the rebased mosaic notes (#2371) --- crates/engine/src/cmd/imagery.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/imagery.rs b/crates/engine/src/cmd/imagery.rs index d6fa02e15f..601fbd4495 100644 --- a/crates/engine/src/cmd/imagery.rs +++ b/crates/engine/src/cmd/imagery.rs @@ -2481,7 +2481,12 @@ impl Tiles { .iter() .skip(1) .filter(|r| r.copyright.is_some() && r.copyright != first.copyright) - .map(|r| (r.name.clone(), rustgis_data::loss::Note::plain("its copyright differs from the first input's and is not kept in the mosaic"))) + .map(|r| { + ( + r.name.clone(), + rustgis_data::loss::Note::plain("its copyright differs from the first input's and is not kept in the mosaic"), + ) + }) .collect(); notes.extend(super::raster::loss_lines(credits).into_iter().map(|n| (n.text, false))); // Cells rounded when an input was read may be among those the mosaic keeps. From 0516f8ffe9850a23175a20fcaf71be4c9b41f27a Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 11:24:03 -0600 Subject: [PATCH 4/4] fix(engine): the mosaic keeps its inputs' loss codes, and a DTED file cut short codes its missing columns (#2371) --- crates/data/src/raster/dted.rs | 13 +++++++++++-- crates/engine/src/cmd/imagery.rs | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/data/src/raster/dted.rs b/crates/data/src/raster/dted.rs index b57c647151..7278f0e105 100644 --- a/crates/data/src/raster/dted.rs +++ b/crates/data/src/raster/dted.rs @@ -456,7 +456,11 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize } let count = |n: usize| if n == 1 { format!("1 of its {cols} columns has") } else { format!("{n} of its {cols} columns have") }; if present < cols { - lost.push(format!("the file is cut short: {} no heights, read as no data", count(cols - present))); + // Heights the file should hold and doesn't: lost. + lost.push(crate::loss::Note::loss( + crate::loss::LossCode::DroppedValue, + format!("the file is cut short: {} no heights, read as no data", count(cols - present)), + )); } else if let Some(extra) = body_len.checked_sub((cols * record) as u64).filter(|n| *n > 0) { lost.push(format!("{extra} bytes after its last column are ignored")); } @@ -773,7 +777,12 @@ mod tests { let cut = &bytes[..at(8, rows) + 7]; let r = read("x.dt2", cut).unwrap(); assert_eq!(r.value(0, 8, 0), None); - assert!(r.lost.iter().any(|l| l == "the file is cut short: 3 of its 11 columns have no heights, read as no data"), "{:?}", r.lost); + assert!( + r.lost.iter().any(|l| l.text == "the file is cut short: 3 of its 11 columns have no heights, read as no data" + && l.loss == Some(crate::loss::LossCode::DroppedValue)), + "{:?}", + r.lost + ); // Bytes past the last column are said. let mut longer = dted("0000000E", "0000000N", (3600, 3600), (11, rows), |_, _| Some(1)); longer.extend([0; 5]); diff --git a/crates/engine/src/cmd/imagery.rs b/crates/engine/src/cmd/imagery.rs index 601fbd4495..7774bcf51e 100644 --- a/crates/engine/src/cmd/imagery.rs +++ b/crates/engine/src/cmd/imagery.rs @@ -2566,8 +2566,11 @@ pub(crate) fn mosaic_rasters_work(s: &Session, p: &Value) -> Result, Vec<_>) = super::raster::loss_lines(lost).into_iter().partition(|n| n.loss.is_some()); + let mut notes: Notes = plain.into_iter().map(|n| (n.text, false)).collect(); + let coded_said: Vec = coded.iter().map(|n| n.text.clone()).collect(); let made = (|| -> Result { // The inputs are let go of once joined, before the file is written. let out = tiles.join(given, &mut notes)?; @@ -2579,9 +2582,12 @@ pub(crate) fn mosaic_rasters_work(s: &Session, p: &Value) -> Result = notes.iter().map(|(n, _)| n.clone()).collect(); + let said: Vec = coded_said.iter().cloned().chain(notes.iter().map(|(n, _)| n.clone())).collect(); let notes = std::mem::take(&mut notes); let then: super::workflows::Then = Box::new(move |s: &mut Session, _: &mut Value| { + for note in coded { + s.say(note); + } say(s, notes); for note in written { s.say_written(note); @@ -2593,7 +2599,11 @@ pub(crate) fn mosaic_rasters_work(s: &Session, p: &Value) -> Result made, }) })(); - made.map_err(|e| with_notes(e, ¬es)) + made.map_err(|e| { + let mut all: Notes = coded_said.iter().map(|n| (n.clone(), false)).collect(); + all.extend(notes); + with_notes(e, &all) + }) })) }