Skip to content

Commit

Permalink
refactor a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Aspenes committed Jan 5, 2024
1 parent c3eb0ec commit 33aeb19
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions satpy/writers/mitiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ def _add_proj4_string(self, datasets, first_dataset, **kwargs):
# FUTURE: Use pyproj 2.0+ to convert EPSG to PROJ4 if possible
proj4_string, x_0 = self._convert_epsg_to_proj(proj4_string, x_0)

proj4_string = self._special_correction_of_proj_string(proj4_string)

if isinstance(datasets, list):
_dataset = first_dataset
else:
_dataset = datasets
mitiff_pixel_adjustment = kwargs.get("mitiff_pixel_adjustment", False)
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"

return proj4_string

def _special_correction_of_proj_string(self, proj4_string):
if "geos" in proj4_string:
proj4_string = proj4_string.replace("+sweep=x ", "")
if "+a=6378137.0 +b=6356752.31414" in proj4_string:
Expand All @@ -258,19 +272,10 @@ def _add_proj4_string(self, datasets, first_dataset, **kwargs):

if "units" not in proj4_string:
proj4_string += " +units=km"

if isinstance(datasets, list):
_dataset = first_dataset
else:
_dataset = datasets
proj4_string = self._append_projection_center(proj4_string, _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, dataset, x_0, y_0, **kwargs):
corner_correction_x, corner_correction_y = self._set_correction_size(dataset, kwargs)
def _append_projection_center(self, proj4_string, dataset, x_0, y_0, mitiff_pixel_adjustment):
corner_correction_x, corner_correction_y = self._set_correction_size(dataset, mitiff_pixel_adjustment)
if "x_0" not in proj4_string:
proj4_string += " +x_0=%.6f" % (
(-dataset.attrs["area"].area_extent[0] +
Expand All @@ -290,12 +295,9 @@ def _append_projection_center(self, proj4_string, dataset, x_0, y_0, **kwargs):
def _set_correction_size(self, dataset, kwargs):
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
if kwargs.get("mitiff_pixel_adjustment", False):
corner_correction_x = 0
corner_correction_y = 0
return corner_correction_x,corner_correction_y

def _convert_epsg_to_proj(self, proj4_string, x_0):
Expand Down

0 comments on commit 33aeb19

Please sign in to comment.