Skip to content

Commit

Permalink
Update tests after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Aspenes committed Jan 5, 2024
1 parent 33aeb19 commit c189f21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
33 changes: 8 additions & 25 deletions satpy/tests/writer_tests/test_mitiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,34 +901,17 @@ def test_correction_proj4_string(self):
dims=("y", "x"),
attrs={"area": area_def}
)
default_expected_proj4_string = ' Proj string: +init=EPSG:3395 +towgs84=0,0,0 +units=km +x_0=1020.000000 +y_0=1515.000000\n'
default_expected_correction = (20.0, 15.0)
w = MITIFFWriter(filename="dummy.tif", base_dir=self.base_dir)
proj4_string = w._add_proj4_string(ds1, ds1)
assert proj4_string == default_expected_proj4_string
mitiff_pixel_adjustment = True
correction = w._set_correction_size(ds1, mitiff_pixel_adjustment)
assert correction == default_expected_correction

kwargs = {'mitiff_pixel_adjustment': False}
new_expected_proj4_string = ' Proj string: +init=EPSG:3395 +towgs84=0,0,0 +units=km +x_0=1000.000000 +y_0=1500.000000\n'
mitiff_pixel_adjustment = False
new_expected_correction = (0, 0)
w = MITIFFWriter(filename="dummy.tif", base_dir=self.base_dir)
proj4_string = w._add_proj4_string(ds1, ds1, **kwargs)
assert proj4_string == new_expected_proj4_string

area_def2 = AreaDefinition(
"test",
"test",
"test",
"+proj=merc +x_0=0 +y_0=0",
100,
200,
(-1000., -1500., 1000., 1500.),
)
ds2 = xr.DataArray(
da.zeros((10, 20), chunks=20),
dims=("y", "x"),
attrs={"area": area_def2}
)
w = MITIFFWriter(filename="dummy.tif", base_dir=self.base_dir)
proj4_string = w._add_proj4_string(ds2, ds2, **kwargs)
assert proj4_string == new_expected_proj4_string
correction = w._set_correction_size(ds1, mitiff_pixel_adjustment)
assert correction == new_expected_correction

def test_save_dataset_palette(self):
"""Test writer operation as palette."""
Expand Down
6 changes: 3 additions & 3 deletions satpy/writers/mitiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _add_proj4_string(self, datasets, first_dataset, **kwargs):
_dataset = first_dataset
else:
_dataset = datasets
mitiff_pixel_adjustment = kwargs.get("mitiff_pixel_adjustment", False)
mitiff_pixel_adjustment = kwargs.get("mitiff_pixel_adjustment", True)
proj4_string = self._append_projection_center(proj4_string, _dataset, x_0, y_0, mitiff_pixel_adjustment)
LOG.debug("proj4_string: %s", proj4_string)
proj4_string += "\n"
Expand Down Expand Up @@ -292,10 +292,10 @@ def _append_projection_center(self, proj4_string, dataset, x_0, y_0, mitiff_pixe
corner_correction_y) + y_0))
return proj4_string

def _set_correction_size(self, dataset, kwargs):
def _set_correction_size(self, dataset, mitiff_pixel_adjustment):
corner_correction_x = dataset.attrs["area"].pixel_size_x
corner_correction_y = dataset.attrs["area"].pixel_size_y
if kwargs.get("mitiff_pixel_adjustment", False):
if not mitiff_pixel_adjustment:
corner_correction_x = 0
corner_correction_y = 0
return corner_correction_x,corner_correction_y
Expand Down

0 comments on commit c189f21

Please sign in to comment.