Skip to content

Commit

Permalink
♻️ Refactor unit test to be non-square (#6)
Browse files Browse the repository at this point in the history
* 🐛 Fix array dimension order to be y (height), x (width)

Classic mistake of getting the wrong order when mixing geographic xy with image yx. Corrected to use y (height), x (width) order, and updated unit test to be non-square so that this won't happen again.

* ⏪ Dimensions in TIFF decoder and writer is actually width height

Getting confused with the `tiff` crate using (width, height), while `ndarray` uses (height, width)...

* 🍻 More height and width swapping

Need to get my head straight on these ordering issues...
  • Loading branch information
weiji14 authored Mar 8, 2024
1 parent fefa543 commit 76e31be
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/io/geotiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ mod tests {
fn test_read_geotiff() {
// Generate some data
let mut image_data = Vec::new();
for x in 0..20 {
for y in 0..20 {
let val = x + y;
for y in 0..10 {
for x in 0..20 {
let val = y + x;
image_data.push(val as f32);
}
}
Expand All @@ -49,13 +49,16 @@ mod tests {
let mut file = tempfile().unwrap();
let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap();
bigtiff
.write_image::<colortype::Gray32Float>(20, 20, &image_data)
.write_image::<colortype::Gray32Float>(20, 10, &image_data) // width, height, data
.unwrap();
file.seek(SeekFrom::Start(0)).unwrap();

// Read a BigTIFF file
let arr = read_geotiff(file).unwrap();
assert_eq!(arr.dim(), (20, 20));
assert_eq!(arr.mean(), Some(19.0));
assert_eq!(arr.ndim(), 2);
assert_eq!(arr.dim(), (10, 20)); // (height, width)
assert_eq!(arr.nrows(), 10); // y-axis
assert_eq!(arr.ncols(), 20); // x-axis
assert_eq!(arr.mean(), Some(14.0));
}
}

0 comments on commit 76e31be

Please sign in to comment.