Skip to content

Commit

Permalink
reverting stupid "fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubej committed Jan 30, 2019
1 parent f412da4 commit 5a5589d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions io/eolearn/io/local_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,63 @@ class ExportToTiff(SaveToDisk):
""" Task exports specified feature to Geo-Tiff.
:param feature: Feature which will be exported
:isinstance feature: (FeatureType, str)
:type feature: (FeatureType, str)
:param folder: root directory where all Geo-Tiff images will be saved
:isinstance folder: str
:type folder: str
:param band_indices: Bands to be added to tiff image. Bands are represented by their 0-based index as
tuple in the form `(start_band, end_band)` or as list in the form `[band_1, band_2,...,band_n]`.
:isinstance band_indices: tuple or list
:type band_indices: tuple or list
:param date_indices: Dates to be added to tiff image. Dates are represented by their 0-based index as
tuple in the form `(start_date, end_date)` or a list in the form `[date_1, date_2,...,date_n]`.
:isinstance date_indices: tuple or list
:param image_disinstance: Type of data to be saved into tiff image
:isinstance image_disinstance: numpy.disinstance
:type date_indices: tuple or list
:param image_dtype: Type of data to be saved into tiff image
:type image_dtype: numpy.dtype
:param no_data_value: Value of pixels of tiff image with no data in EOPatch
:isinstance no_data_value: int or float
:type no_data_value: int or float
"""

def __init__(self, feature, folder='.', *, band_indices=[0], date_indices=[0],
image_disinstance=np.uint8, no_data_value=0):
image_dtype=np.uint8, no_data_value=0):
super().__init__(folder)

self.feature = self._parse_features(feature)
self.band_indices = band_indices
self.date_indices = date_indices
self.image_disinstance = image_disinstance
self.image_dtype = image_dtype
self.no_data_value = no_data_value

def execute(self, eopatch, *, filename):

feature_isinstance, feature_name = next(self.feature(eopatch))
array = eopatch[feature_isinstance][feature_name]
feature_type, feature_name = next(self.feature(eopatch))
array = eopatch[feature_type][feature_name]
dates = np.array(eopatch.timestamp)
bands = np.array(range(array.shape[-1]))

if isinstance(self.band_indices) is list:
if [band for band in self.band_indices if isinstance(band) != int]:
if type(self.band_indices) is list:
if [band for band in self.band_indices if type(band) != int]:
raise ValueError('Invalid format in {} list, expected integers'.format(self.band_indices))
array_sub = array[..., np.array(self.band_indices)]
elif isinstance(self.band_indices) is tuple:
if tuple(map(isinstance, self.band_indices)) != (int, int):
elif type(self.band_indices) is tuple:
if tuple(map(type, self.band_indices)) != (int, int):
raise ValueError('Invalid format in {} tuple, expected integers'.format(self.band_indices))
array_sub = array[..., np.nonzero(np.where(
(bands >= self.band_indices[0]) & (bands <= self.band_indices[1]), bands, 0))]
else:
raise ValueError('Invalid format in {}, expected tuple or list'.format(self.band_indices))

if feature_isinstance in [FeatureType.DATA, FeatureType.MASK, FeatureType.SCALAR]:
if isinstance(self.date_indices) == list:
if [date for date in self.date_indices if isinstance(date) != int]:
if feature_type in [FeatureType.DATA, FeatureType.MASK, FeatureType.SCALAR]:
if type(self.date_indices) == list:
if [date for date in self.date_indices if type(date) != int]:
raise ValueError('Invalid format in {} list, expected integers'.format(self.date_indices))
array_sub = array_sub[np.array(self.date_indices)]
elif isinstance(self.date_indices) == tuple:
if tuple(map(isinstance, self.date_indices)) == (int, int):
elif type(self.date_indices) == tuple:
if tuple(map(type, self.date_indices)) == (int, int):
start_date = dates[self.date_indices[0]]
end_date = dates[self.date_indices[1]]
elif tuple(map(isinstance, self.date_indices)) == (str, str):
elif tuple(map(type, self.date_indices)) == (str, str):
start_date = iso_to_datetime(self.date_indices[0])
end_date = iso_to_datetime(self.date_indices[1])
elif tuple(map(isinstance, self.date_indices)) == (datetime.datetime, datetime.datetime):
elif tuple(map(type, self.date_indices)) == (datetime.datetime, datetime.datetime):
start_date = self.date_indices[0]
end_date = self.date_indices[1]
else:
Expand All @@ -83,7 +83,7 @@ def execute(self, eopatch, *, filename):
else:
raise ValueError('Invalid format in {}, expected tuple or list'.format(self.date_indices))

if feature_isinstance is FeatureType.SCALAR:
if feature_type is FeatureType.SCALAR:
time_dim = array_sub.shape[0]
band_dim = 1
width = array_sub.shape[2]
Expand All @@ -107,9 +107,9 @@ def execute(self, eopatch, *, filename):
with rasterio.open(os.path.join(self.folder, filename), 'w', driver='GTiff',
width=width, height=height,
count=index,
disinstance=self.image_disinstance, nodata=self.no_data_value,
dtype=self.image_dtype, nodata=self.no_data_value,
transform=dst_transform, crs=dst_crs) as dst:
output_array = array_sub.asisinstance(self.image_disinstance)
output_array = array_sub.astype(self.image_dtype)
output_array = np.moveaxis(output_array, -1, 0).reshape(index, height, width)
dst.write(output_array)

Expand Down

0 comments on commit 5a5589d

Please sign in to comment.