def _make_request(self, bbox, meta_info, timestamps): """ Make OGC request to create input for cloud detector classifier :param bbox: Bounding box :param meta_info: Meta-info dictionary of input eopatch :return: Requested data """ service_type = ServiceType(meta_info['service_type']) # Raise error if resolutions are not specified if self.cm_size_x is None and self.cm_size_y is None: raise ValueError("Specify size_x and size_y for data request") # If WCS request, make sure both resolutions are set if service_type == ServiceType.WCS: if self.cm_size_y is None: self.cm_size_y = self.cm_size_x elif self.cm_size_x is None: self.cm_size_x = self.cm_size_y custom_url_params = { CustomUrlParam.SHOWLOGO: False, CustomUrlParam.TRANSPARENT: False, CustomUrlParam.EVALSCRIPT: self.model_evalscript } build_request = { ServiceType.WMS: self._get_wms_request, ServiceType.WCS: self._get_wcs_request }[service_type] request = build_request(bbox, meta_info['time_interval'], self.cm_size_x, self.cm_size_y, meta_info['maxcc'], meta_info['time_difference'], custom_url_params) request_dates = request.get_dates() download_frames = get_common_timestamps(request_dates, timestamps) request_return = request.get_data(raise_download_errors=False, data_filter=download_frames) bad_data = [ idx for idx, value in enumerate(request_return) if value is None ] for idx in reversed(sorted(bad_data)): LOGGER.warning('Data from %s could not be downloaded for %s!', str(request_dates[idx]), self.data_feature) del request_return[idx] del request_dates[idx] return np.asarray(request_return), request_dates
def execute(self, eopatch=None, bbox=None, time_interval=None): """ Creates OGC (WMS or WCS) request, downloads requested data and stores it together with valid data mask in newly created EOPatch. Returns the EOPatch. :param eopatch: :type eopatch: EOPatch or None :param bbox: specifies the bounding box of the requested image. Coordinates must be in the specified coordinate reference system. Required. :type bbox: BBox :param time_interval: time or time range for which to return the results, in ISO8601 format (year-month-date, for example: ``2016-01-01``, or year-month-dateThours:minuts:seconds format, i.e. ``2016-01-01T16:31:21``). When a single time is specified the request will return data for that specific date, if it exists. If a time range is specified the result is a list of all scenes between the specified dates conforming to the cloud coverage criteria. Most recent acquisition being first in the list. For the latest acquisition use ``latest``. Examples: ``latest``, ``'2016-01-01'``, or ``('2016-01-01', ' 2016-01-31')`` :type time_interval: str, or tuple of str """ if eopatch is None: eopatch = EOPatch() request_params, service_type = self._prepare_request_data(eopatch, bbox, time_interval) request = {ServiceType.WMS: WmsRequest, ServiceType.WCS: WcsRequest}[service_type](**request_params) request_dates = request.get_dates() if not eopatch.timestamp: eopatch.timestamp = request_dates download_frames = None if self.feature_type.is_time_dependent(): download_frames = get_common_timestamps(request_dates, eopatch.timestamp) images = request.get_data(raise_download_errors=self.raise_download_errors, data_filter=download_frames) if not self.raise_download_errors: bad_data = [idx for idx, value in enumerate(images) if value is None] for idx in reversed(bad_data): LOGGER.warning('Data from %s could not be downloaded for %s!', str(request_dates[idx]), self.layer) del images[idx] del request_dates[idx] for removed_frame in eopatch.consolidate_timestamps(request_dates): LOGGER.warning('Removed data for frame %s from EOPatch ' 'due to unavailability of %s!', str(removed_frame), self.layer) self._add_data(eopatch, np.asarray(images)) self._add_meta_info(eopatch, request_params, service_type) return eopatch
def execute(self, eopatch): """ Add requested feature to this existing EOPatch. """ size_x = eopatch.meta_info['size_x'] size_y = eopatch.meta_info['size_y'] maxcc = eopatch.meta_info['maxcc'] time_difference = eopatch.meta_info['time_difference'] service_type = eopatch.meta_info['service_type'] time_interval = (eopatch.timestamp[0].isoformat(), eopatch.timestamp[-1].isoformat()) request = {ServiceType.WMS: self._get_wms_request, ServiceType.WCS: self._get_wcs_request}[service_type](eopatch.bbox, time_interval, size_x, size_y, maxcc, time_difference) # check timestamp consistency between request and this eopatch request_dates = request.get_dates() download_frames = get_common_timestamps(request_dates, eopatch.timestamp) request_return = request.get_data(raise_download_errors=False, data_filter=download_frames) bad_data = [idx for idx, value in enumerate(request_return) if value is None] for idx in reversed(sorted(bad_data)): LOGGER.warning('Data from %s could not be downloaded for %s!', str(request_dates[idx]), self.layer) del request_return[idx] del request_dates[idx] request_data = np.asarray(request_return) removed_frames = eopatch.consolidate_timestamps(request_dates) for rm_frame in removed_frames: LOGGER.warning('Removed data for frame %s from eopatch ' 'due to unavailability of %s!', str(rm_frame), self.layer) request_data = self._check_dimensionality(request_data, eopatch.ndims) eopatch.add_feature(self.feature_type, self.feature_name, request_data) return eopatch