atlas multi-pays: binaire atlas, signer etendu, exemple atlas_calage (score + calage, cuvettes, gates cote/glaciaire)
Travail de l agent 4 bis (rapport 27), commite apres coup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
6f2445c8a9
révision
e9e26ebb2e
7 fichiers modifiés
+633
-1
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,8 @@
|
||||
//! atlas <sortie.json> <sig1.json> [sig2.json ...] : archétype (SignatureCible) à partir de signatures mesurées.
|
||||
use signature::{archetype, Signature};
|
||||
fn main() {
|
||||
let a: Vec<String> = std::env::args().skip(1).collect();
|
||||
if a.len() < 2 { eprintln!("usage: atlas <sortie.json> <sig.json>..."); std::process::exit(2) }
|
||||
let sigs: Vec<Signature> = a[1..].iter().map(|f| Signature::from_json(&std::fs::read_to_string(f).unwrap()).unwrap()).collect();
|
||||
std::fs::write(&a[0], serde_json::to_string_pretty(&archetype(&sigs)).unwrap()).unwrap();
|
||||
}
|
||||
@@ -4,10 +4,12 @@ use signature::{lire_geotiff, mesurer, MetaSource};
|
||||
fn main() {
|
||||
let a: Vec<String> = std::env::args().skip(1).collect();
|
||||
let (mut fich, mut out, mut meta) = (vec![], "sig.json".to_string(), MetaSource::default());
|
||||
let mut pas: Option<f32> = None;
|
||||
let mut i = 0;
|
||||
while i < a.len() {
|
||||
match a[i].as_str() {
|
||||
"-o" => { out = a[i + 1].clone(); i += 1 }
|
||||
"--pas" => { pas = a[i + 1].parse().ok(); i += 1 }
|
||||
"--pays" => { meta.pays = a[i + 1].clone(); i += 1 }
|
||||
"--jeu" => { meta.jeu = a[i + 1].clone(); i += 1 }
|
||||
"--biome" => { meta.biome = serde_json::from_str(&format!("\"{}\"", a[i + 1])).unwrap_or(BiomeRelief::Plaine); i += 1 }
|
||||
@@ -16,7 +18,37 @@ fn main() {
|
||||
i += 1;
|
||||
}
|
||||
if fich.is_empty() { eprintln!("usage: signer <mnt.tif> [occ.tif] -o sig.json"); std::process::exit(2) }
|
||||
let mnt = lire_geotiff(&fich[0]).unwrap_or_else(|e| { eprintln!("{e}"); std::process::exit(1) });
|
||||
let mut mnt = lire_geotiff(&fich[0]).unwrap_or_else(|e| { eprintln!("{e}"); std::process::exit(1) });
|
||||
// Les tuiles de donnees/biomes/ n'ont pas de geotag : le pas vient de --pas ou du JSON voisin (pas_m, sinon pas_m_approx).
|
||||
let jpath = std::path::Path::new(&fich[0]).with_extension("json");
|
||||
let mut pas_xy: Option<(f32, f32)> = pas.map(|p| (p, p));
|
||||
if pas_xy.is_none() {
|
||||
if let Ok(t) = std::fs::read_to_string(&jpath) {
|
||||
if let Ok(v) = serde_json::from_str::<serde_json::Value>(&t) {
|
||||
let a = v.get("pas_m").or_else(|| v.get("pas_m_approx")).and_then(|a| a.as_array());
|
||||
if let Some(a) = a { if a.len() == 2 { pas_xy = Some((a[0].as_f64().unwrap_or(1.0) as f32, a[1].as_f64().unwrap_or(1.0) as f32)); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((px, py)) = pas_xy {
|
||||
if (px - py).abs() > 0.01 * py {
|
||||
// pas anisotrope (degres) : reechantillonnage lineaire des colonnes a un pas carre = py
|
||||
let nw = ((mnt.w as f32 * px / py).round() as usize).max(8);
|
||||
let mut z = vec![f32::NAN; nw * mnt.h];
|
||||
for r in 0..mnt.h {
|
||||
for c in 0..nw {
|
||||
let x = (c as f32 + 0.5) * py / px - 0.5;
|
||||
let (i0, t) = (x.floor().max(0.0), (x - x.floor()).clamp(0.0, 1.0));
|
||||
let (i0, i1) = ((i0 as usize).min(mnt.w - 1), ((i0 as usize) + 1).min(mnt.w - 1));
|
||||
let (a, b) = (mnt.z[r * mnt.w + i0], mnt.z[r * mnt.w + i1]);
|
||||
z[r * nw + c] = a + (b - a) * t;
|
||||
}
|
||||
}
|
||||
mnt = signature::Raster::new(nw, mnt.h, py, z);
|
||||
} else {
|
||||
mnt.pas_m = py;
|
||||
}
|
||||
}
|
||||
let occ = fich.get(1).map(|f| lire_geotiff(f).unwrap());
|
||||
let s = mesurer(&mnt, occ.as_ref(), &meta);
|
||||
std::fs::write(&out, s.to_json()).unwrap();
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur