Commit 05242550 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed UnicodeEncodeError while writing ENVI headers. Moved scipy imports from...


Fixed UnicodeEncodeError while writing ENVI headers. Moved scipy imports from module level to function level to avoid 'static TLS' ImportError. Fixed gdal_warp call within DEM_Creator class. Fixed issues while overwriting projections.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 51d8c6c2
Pipeline #12557 failed with stage
in 4 minutes and 13 seconds
......@@ -739,8 +739,9 @@ class L1B_object(L1A_object):
# NOTE: mask_nodata and mask_clouds are updated later by L2A_map mapper function (module pipeline)
# update the GeoArray instance without loosing its inherent metadata (nodata, ...)
geoArr.arr, geoArr.gt, geoArr.prj = \
DS.GeoArray_shifted.arr, DS.GeoArray_shifted.gt, DS.GeoArray_shifted.prj
geoArr.arr, geoArr.gt = DS.GeoArray_shifted.arr, DS.GeoArray_shifted.gt
if not geoArr.prj:
geoArr.prj = DS.GeoArray_shifted.prj
# setattr(self,attrname, DS.GeoArray_shifted) # NOTE: don't set array earlier because setter will also
# # update arr.gt/.prj/.nodata from MetaObj
......
......@@ -29,7 +29,6 @@ Level 2B Processor: Spectral homogenization
"""
import numpy as np
from scipy.interpolate import interp1d
from typing import Union # noqa F401 # flake8 issue
from geoarray import GeoArray # noqa F401 # flake8 issue
from spechomo.prediction import SpectralHomogenizer
......@@ -164,6 +163,8 @@ class L2B_object(L2A_object):
#########################################################################################
if self.ac_errors and self.ac_errors.ndim == 3:
from scipy.interpolate import interp1d
self.logger.info("Performing linear interpolation for 'AC errors' array to match target sensor bands "
"number..")
outarr = interp1d(np.array(src_cwls), self.ac_errors,
......
......@@ -42,7 +42,6 @@ import warnings
import numpy as np
from matplotlib import dates as mdates
from scipy.interpolate import RegularGridInterpolator
# custom
try:
......@@ -894,6 +893,8 @@ def get_common_extent(list_extentcoords, alg='outer', return_box=True):
def zoom_2Darray_to_shapeFullArr(arr2D, shapeFullArr, meshwidth=1, subset=None, method='linear'):
from scipy.interpolate import RegularGridInterpolator
assert method in ['linear', 'nearest']
rS, rE, cS, cE = list(get_subsetProps_from_subsetArg(shapeFullArr, subset).values())[3:7]
rowpos = np.linspace(0, shapeFullArr[0] - 1, arr2D.shape[0])
......
......@@ -41,9 +41,9 @@ import logging
import dill
import numpy as np
import scipy.interpolate
import spectral
from spectral.io import envi as envi
from pyproj import CRS
from geoarray import GeoArray
from py_tools_ds.geo.coord_calc import corner_coord_to_minmax
......@@ -258,12 +258,14 @@ def Solar_Irradiance_reader(resol_nm=None, wvl_min_nm=None, wvl_max_nm=None):
:param wvl_max_nm: maximum wavelength of returned irradiances [nanometers]
:return:
"""
from scipy.interpolate import interp1d
sol_irr = np.loadtxt(CFG.path_solar_irr, skiprows=1)
if resol_nm is not None and isinstance(resol_nm, (float, int)):
wvl_min = (np.min(sol_irr[:, 0]) if wvl_min_nm is None else wvl_min_nm)
wvl_max = (np.max(sol_irr[:, 0]) if wvl_max_nm is None else wvl_max_nm)
wvl_rsp = np.arange(wvl_min, wvl_max, resol_nm)
sol_irr = scipy.interpolate.interp1d(sol_irr[:, 0], sol_irr[:, 1], kind='linear')(wvl_rsp)
sol_irr = interp1d(sol_irr[:, 0], sol_irr[:, 1], kind='linear')(wvl_rsp)
return sol_irr
......@@ -482,8 +484,8 @@ class DEM_Creator(object):
merged_prj = GeoArray(tFm.name).prj
t_xmin, t_xmax, t_ymin, t_ymax = corner_coord_to_minmax(cornerCoords_tgt)
self._run_cmd('gdalwarp -r average -of VRT -srcnodata 0 -dstnodata 0 '
'-tr %s %s -s_srs %s -t_srs %s -te %s %s %s %s %s %s'
% (tgt_xgsd, tgt_ygsd, merged_prj, prj,
'-tr %s %s -s_srs EPSG:%s -t_srs EPSG:%s -te %s %s %s %s %s %s'
% (tgt_xgsd, tgt_ygsd, CRS(merged_prj).to_epsg(), CRS(prj).to_epsg(),
t_xmin, t_ymin, t_xmax, t_ymax, tFm.name, tFo.name))
assert os.path.exists(tFo.name)
......
......@@ -80,6 +80,10 @@ def silent_envi_write_image(hdr_file, data, header, **kwargs):
"""
Monkeypatch for spectral.io.envi._write_image in order to silence output stream.
"""
from ..misc.helper_functions import safe_str
# force unicode strings
header = dict((k, v) if not isinstance(v, str) else (k, safe_str(v)) for k, v in header.items())
check_compatibility(header)
force = kwargs.get('force', False)
img_ext = kwargs.get('ext', '.img')
......
......@@ -161,6 +161,11 @@ def sorted_nicely(iterable):
return sorted(iterable, key=alphanum_key)
def safe_str(obj):
"""Return a safe string that will not cause any UnicodeEncodeError issues."""
return obj.encode('ascii', 'ignore').decode('ascii')
def is_proc_level_lower(current_lvl, target_lvl):
# type: (str, str) -> bool
"""Return True if current_lvl is lower than target_lvl.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment