Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kwargs config option to turn off mitiff corner correction #2713

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions satpy/tests/writer_tests/test_mitiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

Check notice on line 1 in satpy/tests/writer_tests/test_mitiff.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 920 to 966, improve code health by reducing it to 600. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in satpy/tests/writer_tests/test_mitiff.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Low Cohesion

The number of different responsibilities increases from 7 to 8, threshold = 4. Cohesion is calculated using the LCOM4 metric. Low cohesion means that the module/class has multiple unrelated responsibilities, doing too many things and breaking the Single Responsibility Principle.
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2020 Satpy developers
#
Expand Down Expand Up @@ -879,6 +879,57 @@
proj4_string = w._add_proj4_string(ds1, ds1)
assert proj4_string == check["proj4"]

def test_correction_proj4_string(self):
"""Test correction of proj4 lower left coordinate."""
import dask.array as da
import xarray as xr
from pyresample.geometry import AreaDefinition

from satpy.writers.mitiff import MITIFFWriter
area_def = AreaDefinition(
"test",
"test",
"test",
"+proj=merc",
100,
200,
(-1000., -1500., 1000., 1500.),
)

ds1 = xr.DataArray(
da.zeros((10, 20), chunks=20),
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'
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

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'
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

def test_save_dataset_palette(self):
"""Test writer operation as palette."""
from satpy.writers.mitiff import MITIFFWriter
Expand Down
24 changes: 16 additions & 8 deletions satpy/writers/mitiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

Check notice on line 1 in satpy/writers/mitiff.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 6.15 to 6.23, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
# -*- coding: utf-8 -*-
# Copyright (c) 2018, 2019 Satpy developers
#
Expand Down Expand Up @@ -220,7 +220,7 @@

return _image_description

def _add_proj4_string(self, datasets, first_dataset):
def _add_proj4_string(self, datasets, first_dataset, **kwargs):
import warnings

proj4_string = " Proj string: "
Expand Down Expand Up @@ -259,31 +259,39 @@
if "units" not in proj4_string:
proj4_string += " +units=km"

proj4_string = self._append_projection_center(proj4_string, datasets, first_dataset, x_0, y_0)
proj4_string = self._append_projection_center(proj4_string, datasets, first_dataset, x_0, y_0, **kwargs)
LOG.debug("proj4_string: %s", proj4_string)
proj4_string += "\n"

return proj4_string

def _append_projection_center(self, proj4_string, datasets, first_dataset, x_0, y_0):
def _append_projection_center(self, proj4_string, datasets, first_dataset, x_0, y_0, **kwargs):
if isinstance(datasets, list):
dataset = first_dataset
else:
dataset = datasets
corner_correction_x = dataset.attrs["area"].pixel_size_x
corner_correction_y = dataset.attrs["area"].pixel_size_y
try:
if kwargs['mitiff_pixel_adjustment'] is False:
corner_correction_x = 0
corner_correction_y = 0
except KeyError:
pass
TAlonglong marked this conversation as resolved.
Show resolved Hide resolved
if "x_0" not in proj4_string:
proj4_string += " +x_0=%.6f" % (
(-dataset.attrs["area"].area_extent[0] +
dataset.attrs["area"].pixel_size_x) + x_0)
corner_correction_x) + x_0)
proj4_string += " +y_0=%.6f" % (
(-dataset.attrs["area"].area_extent[1] +
dataset.attrs["area"].pixel_size_y) + y_0)
corner_correction_y) + y_0)
elif "+x_0=0" in proj4_string and "+y_0=0" in proj4_string:
proj4_string = proj4_string.replace("+x_0=0", "+x_0=%.6f" % (
(-dataset.attrs["area"].area_extent[0] +
dataset.attrs["area"].pixel_size_x) + x_0))
corner_correction_x) + x_0))
proj4_string = proj4_string.replace("+y_0=0", "+y_0=%.6f" % (
(-dataset.attrs["area"].area_extent[1] +
dataset.attrs["area"].pixel_size_y) + y_0))
corner_correction_y) + y_0))

Check notice on line 294 in satpy/writers/mitiff.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Excess Number of Function Arguments

MITIFFWriter._append_projection_center increases from 5 to 6 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
return proj4_string

def _convert_epsg_to_proj(self, proj4_string, x_0):
Expand Down Expand Up @@ -563,7 +571,7 @@

_image_description += " Map projection: Stereographic\n"

_image_description += self._add_proj4_string(datasets, first_dataset)
_image_description += self._add_proj4_string(datasets, first_dataset, **kwargs)
TAlonglong marked this conversation as resolved.
Show resolved Hide resolved

_image_description += " TrueLat: 60N\n"
_image_description += " GridRot: 0\n"
Expand Down
Loading