Skip to content

Commit

Permalink
Merge pull request #65 from sentinel-hub/bugfix/sh-py2.5.0
Browse files Browse the repository at this point in the history
Bugfix/sh py2.5.0
  • Loading branch information
devisperessutti committed Feb 4, 2019
2 parents 14cce4f + 6d932b1 commit a113739
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ before_install:
install:
- pip install -r requirements-dev.txt --upgrade
- python install_all.py
- pip install pandas==0.23.4 # This is temporal solution

script:
- pylint core/eolearn/core/*.py
Expand Down
2 changes: 1 addition & 1 deletion core/eolearn/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
from .utilities import deep_eq, negate_mask, constant_pad, get_common_timestamps


__version__ = '0.4.1'
__version__ = '0.4.2'
49 changes: 47 additions & 2 deletions core/eolearn/core/eodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
"""

import os
import sys
import logging
import pickle
import gzip
import shutil
import warnings
import copy
import datetime
import pickletools

import attr
import dateutil.parser
import numpy as np
Expand All @@ -20,11 +23,16 @@
from .constants import FeatureType, FileFormat, OverwritePermission
from .utilities import deep_eq, FeatureParser

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

MAX_DATA_REPR_LEN = 100


if sentinelhub.__version__ >= '2.5.0':
sys.modules['sentinelhub.common'] = sentinelhub.geometry


@attr.s(repr=False, cmp=False, kw_only=True)
class EOPatch:
"""The basic data object for multi-temporal remotely sensed data, such as satellite imagery and its derivatives.
Expand Down Expand Up @@ -875,9 +883,38 @@ def get_file_path(self):
"""
return os.path.join(self.patch_path, self.filename)

@staticmethod
def _correctly_load_bbox(bbox, path, is_zipped=False):
""" Helper method for loading old version of pickled BBox object
:param bbox: BBox object which was incorrectly loaded with pickle
:type bbox: sentinelhub.BBox
:param path: Path to file where BBox object is stored
:type path: str
:param is_zipped: `True` if file is zipped and `False` otherwise
:type is_zipped: bool
:return: Correctly loaded BBox object
:rtype: sentinelhub.BBox
"""
warnings.warn("Bounding box of your EOPatch is saved in old format which in the future won't be supported "
"anymore. Please save bounding box again, you can overwrite the existing one", DeprecationWarning,
stacklevel=4)

with open(gzip.open(path) if is_zipped else path, 'rb') as pickle_file:
crs_cnt = -1
for _, arg, _ in pickletools.genops(pickle_file):
if arg == 'sentinelhub.constants CRS':
crs_cnt = 2
if crs_cnt == 0:
return sentinelhub.BBox(tuple(bbox), sentinelhub.CRS(arg))
crs_cnt -= 1

raise ValueError('Failed to correctly load BBox object, try downgrading sentinelhub package to <=2.4.7')

def load(self):
""" Method which loads data from the file
"""
# pylint: disable=too-many-return-statements
if not os.path.isdir(self.patch_path):
raise OSError('EOPatch does not exist in path {} anymore'.format(self.patch_path))

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

if not file_formats or file_formats[-1] is FileFormat.PICKLE:
with open(path, "rb") as infile:
return pickle.load(infile)
data = pickle.load(infile)

if isinstance(data, sentinelhub.BBox) and not hasattr(data, 'crs'):
return self._correctly_load_bbox(data, path)
return data

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

if len(file_formats) == 1 or file_formats[-2] is FileFormat.PICKLE:
return pickle.load(gzip.open(path))
data = pickle.load(gzip.open(path))

if isinstance(data, sentinelhub.BBox) and not hasattr(data, 'crs'):
return self._correctly_load_bbox(data, path, is_zipped=True)
return data

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

Expand Down
2 changes: 1 addition & 1 deletion core/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ graphviz>=0.10.1
matplotlib
jinja2
pygments
sentinelhub>=2.4.7
sentinelhub>=2.5.0
geopandas
tqdm>=4.27
2 changes: 1 addition & 1 deletion coregistration/eolearn/coregistration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .coregistration import RegistrationTask, InterpolationType, ECCRegistration, PointBasedRegistration, \
ThunderRegistration

__version__ = '0.4.0'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion features/eolearn/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
from .local_binary_pattern import LocalBinaryPatternTask


__version__ = '0.4.1'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion geometry/eolearn/geometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .utilities import ErosionTask, VectorToRaster, RasterToVector
from .sampling import PointSamplingTask, PointSampler, PointRasterSampler

__version__ = '0.4.0'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion io/eolearn/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .geopedia import AddGeopediaFeature
from .local_io import ExportToTiff

__version__ = '0.4.1'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion mask/eolearn/mask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .masking import AddValidDataMaskTask, MaskFeature


__version__ = '0.4.1'
__version__ = '0.4.2'
2 changes: 1 addition & 1 deletion ml_tools/eolearn/ml_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from .postprocessing import MorphologicalOperations, MorphologicalStructFactory, PostprocessingTask,\
MorphologicalFilterTask

__version__ = '0.4.1'
__version__ = '0.4.2'
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse_requirements(file):
setup(
name='eo-learn',
python_requires='>=3.5',
version='0.4.1',
version='0.4.2',
description='Earth observation processing framework for machine learning in Python',
long_description=get_long_description(),
long_description_content_type='text/markdown',
Expand All @@ -32,13 +32,13 @@ def parse_requirements(file):
packages=[],
include_package_data=True,
install_requires=[
'eo-learn-core>=0.4.1',
'eo-learn-coregistration>=0.4.0',
'eo-learn-features>=0.4.1',
'eo-learn-geometry>=0.4.0',
'eo-learn-io>=0.4.1',
'eo-learn-mask>=0.4.1',
'eo-learn-ml-tools>=0.4.1'
'eo-learn-core>=0.4.2',
'eo-learn-coregistration>=0.4.2',
'eo-learn-features>=0.4.2',
'eo-learn-geometry>=0.4.2',
'eo-learn-io>=0.4.2',
'eo-learn-mask>=0.4.2',
'eo-learn-ml-tools>=0.4.2'
],
extras_require={
'DEV': parse_requirements('requirements-dev.txt'),
Expand Down

0 comments on commit a113739

Please sign in to comment.