Skip to content

Commit

Permalink
Fix LASTPIX both in reading and writing skymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Sep 30, 2024
1 parent 5d51c6b commit 963c978
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/nested/map/fits/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn from_fits_skymap_internal<R: BufRead>(mut reader: R) -> Result<SkyMapEnum
_ => unreachable!(),
}?;
let n_hash = n_hash(depth);
skymap_kws.check_lastpix(n_hash)?;
skymap_kws.check_lastpix(n_hash - 1)?;
// Check whether TForm compatible with N bytes per row
let n_hash_2 = coltype_1.n_pack() as u64 * n_rows;
if n_hash != n_hash_2 {
Expand Down
2 changes: 1 addition & 1 deletion src/nested/map/fits/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn write_skymap_fits_header<R: Write, T: SkyMapValue>(
it.next().unwrap()[0..20].copy_from_slice(b"EXTNAME = 'xtension'");
write_uint_mandatory_keyword_record(it.next().unwrap(), b"NSIDE ", nside as u64);
it.next().unwrap()[0..30].copy_from_slice(b"FIRSTPIX= 0");
write_uint_mandatory_keyword_record(it.next().unwrap(), b"LASTPIX ", n_cells);
write_uint_mandatory_keyword_record(it.next().unwrap(), b"LASTPIX ", n_cells - 1);
it.next().unwrap()[0..20].copy_from_slice(b"INDXSCHM= 'IMPLICIT'");
it.next().unwrap()[0..20].copy_from_slice(b"OBJECT = 'FULLSKY '");
it.next().unwrap()[0..28].copy_from_slice(b"CREATOR = 'CDS HEALPix Rust'");
Expand Down
16 changes: 16 additions & 0 deletions src/nested/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,21 @@ mod tests {
false,
)
.unwrap();

let path = "test/resources/skymap/hats_test.fits";
let skymap = SkyMapEnum::from_fits_file(path).unwrap();
skymap
.to_png_file::<Mol, _>(
(1600, 800),
None,
None,
None,
Some(PosConversion::EqMap2GalImg),
None,
Some(ColorMapFunctionType::LinearLog), //Some(ColorMapFunctionType::LinearSqrt)
"test/resources/skymap/hats_tets.png",
false,
)
.unwrap();
}
}
3 changes: 3 additions & 0 deletions src/nested/map/mom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ pub trait Mom<'a> {
}
}

/// # Warning
/// * assumes that the order of the elements returned by `zuniqs()` is the same as the one returned
/// by `entries()`.
fn check_is_mom(&'a self) -> Result<(), String> {
let mut it = self.zuniqs();
if let Some(mut l) = it.next() {
Expand Down
Binary file added test/resources/skymap/hats_test.fits
Binary file not shown.
Binary file added test/resources/skymap/hats_tets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/resources/skymap/skymap.fits
Binary file not shown.

0 comments on commit 963c978

Please sign in to comment.