Skip to content

Commit a113739

Browse files
Merge pull request #65 from sentinel-hub/bugfix/sh-py2.5.0
Bugfix/sh py2.5.0
2 parents 14cce4f + 6d932b1 commit a113739

File tree

11 files changed

+64
-18
lines changed

11 files changed

+64
-18
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ before_install:
1717
install:
1818
- pip install -r requirements-dev.txt --upgrade
1919
- python install_all.py
20+
- pip install pandas==0.23.4 # This is temporal solution
2021

2122
script:
2223
- pylint core/eolearn/core/*.py

core/eolearn/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
from .utilities import deep_eq, negate_mask, constant_pad, get_common_timestamps
1616

1717

18-
__version__ = '0.4.1'
18+
__version__ = '0.4.2'

core/eolearn/core/eodata.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"""
44

55
import os
6+
import sys
67
import logging
78
import pickle
89
import gzip
910
import shutil
1011
import warnings
1112
import copy
1213
import datetime
14+
import pickletools
15+
1316
import attr
1417
import dateutil.parser
1518
import numpy as np
@@ -20,11 +23,16 @@
2023
from .constants import FeatureType, FileFormat, OverwritePermission
2124
from .utilities import deep_eq, FeatureParser
2225

26+
# pylint: disable=too-many-lines
2327
LOGGER = logging.getLogger(__name__)
2428

2529
MAX_DATA_REPR_LEN = 100
2630

2731

32+
if sentinelhub.__version__ >= '2.5.0':
33+
sys.modules['sentinelhub.common'] = sentinelhub.geometry
34+
35+
2836
@attr.s(repr=False, cmp=False, kw_only=True)
2937
class EOPatch:
3038
"""The basic data object for multi-temporal remotely sensed data, such as satellite imagery and its derivatives.
@@ -875,9 +883,38 @@ def get_file_path(self):
875883
"""
876884
return os.path.join(self.patch_path, self.filename)
877885

886+
@staticmethod
887+
def _correctly_load_bbox(bbox, path, is_zipped=False):
888+
""" Helper method for loading old version of pickled BBox object
889+
890+
:param bbox: BBox object which was incorrectly loaded with pickle
891+
:type bbox: sentinelhub.BBox
892+
:param path: Path to file where BBox object is stored
893+
:type path: str
894+
:param is_zipped: `True` if file is zipped and `False` otherwise
895+
:type is_zipped: bool
896+
:return: Correctly loaded BBox object
897+
:rtype: sentinelhub.BBox
898+
"""
899+
warnings.warn("Bounding box of your EOPatch is saved in old format which in the future won't be supported "
900+
"anymore. Please save bounding box again, you can overwrite the existing one", DeprecationWarning,
901+
stacklevel=4)
902+
903+
with open(gzip.open(path) if is_zipped else path, 'rb') as pickle_file:
904+
crs_cnt = -1
905+
for _, arg, _ in pickletools.genops(pickle_file):
906+
if arg == 'sentinelhub.constants CRS':
907+
crs_cnt = 2
908+
if crs_cnt == 0:
909+
return sentinelhub.BBox(tuple(bbox), sentinelhub.CRS(arg))
910+
crs_cnt -= 1
911+
912+
raise ValueError('Failed to correctly load BBox object, try downgrading sentinelhub package to <=2.4.7')
913+
878914
def load(self):
879915
""" Method which loads data from the file
880916
"""
917+
# pylint: disable=too-many-return-statements
881918
if not os.path.isdir(self.patch_path):
882919
raise OSError('EOPatch does not exist in path {} anymore'.format(self.patch_path))
883920

@@ -889,7 +926,11 @@ def load(self):
889926

890927
if not file_formats or file_formats[-1] is FileFormat.PICKLE:
891928
with open(path, "rb") as infile:
892-
return pickle.load(infile)
929+
data = pickle.load(infile)
930+
931+
if isinstance(data, sentinelhub.BBox) and not hasattr(data, 'crs'):
932+
return self._correctly_load_bbox(data, path)
933+
return data
893934

894935
if file_formats[-1] is FileFormat.NPY:
895936
if self.mmap:
@@ -901,7 +942,11 @@ def load(self):
901942
return np.load(gzip.open(path))
902943

903944
if len(file_formats) == 1 or file_formats[-2] is FileFormat.PICKLE:
904-
return pickle.load(gzip.open(path))
945+
data = pickle.load(gzip.open(path))
946+
947+
if isinstance(data, sentinelhub.BBox) and not hasattr(data, 'crs'):
948+
return self._correctly_load_bbox(data, path, is_zipped=True)
949+
return data
905950

906951
raise ValueError('Could not load data from unsupported file format {}'.format(file_formats[-1]))
907952

core/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ graphviz>=0.10.1
77
matplotlib
88
jinja2
99
pygments
10-
sentinelhub>=2.4.7
10+
sentinelhub>=2.5.0
1111
geopandas
1212
tqdm>=4.27

coregistration/eolearn/coregistration/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from .coregistration import RegistrationTask, InterpolationType, ECCRegistration, PointBasedRegistration, \
66
ThunderRegistration
77

8-
__version__ = '0.4.0'
8+
__version__ = '0.4.2'

features/eolearn/features/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
from .local_binary_pattern import LocalBinaryPatternTask
1818

1919

20-
__version__ = '0.4.1'
20+
__version__ = '0.4.2'

geometry/eolearn/geometry/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from .utilities import ErosionTask, VectorToRaster, RasterToVector
66
from .sampling import PointSamplingTask, PointSampler, PointRasterSampler
77

8-
__version__ = '0.4.0'
8+
__version__ = '0.4.2'

io/eolearn/io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
from .geopedia import AddGeopediaFeature
99
from .local_io import ExportToTiff
1010

11-
__version__ = '0.4.1'
11+
__version__ = '0.4.2'

mask/eolearn/mask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from .masking import AddValidDataMaskTask, MaskFeature
77

88

9-
__version__ = '0.4.1'
9+
__version__ = '0.4.2'

ml_tools/eolearn/ml_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
from .postprocessing import MorphologicalOperations, MorphologicalStructFactory, PostprocessingTask,\
1010
MorphologicalFilterTask
1111

12-
__version__ = '0.4.1'
12+
__version__ = '0.4.2'

0 commit comments

Comments
 (0)