Esempio n. 1
0
    def _prepare_request_data(self, eopatch, bbox, time_interval):
        """ Collects all parameters used for DataRequest, each one is taken either from initialization parameters or
        from EOPatch
        """

        service_type = ServiceType(self._get_parameter('service_type', eopatch))
        if service_type is ServiceType.WMS:
            size_x_name, size_y_name = 'width', 'height'
        else:
            size_x_name, size_y_name = 'resx', 'resy'
        return {
            'layer': self.layer,
            'bbox': bbox if bbox is not None else self._get_parameter('bbox', eopatch),
            'time': time_interval if time_interval is not None else[
                datetime_to_iso(x) if not isinstance(x, str) else x
                for x in self._get_parameter('time_interval', eopatch)],
            'time_difference': self._get_parameter('time_difference', eopatch),
            'maxcc': self._get_parameter('maxcc', eopatch),
            'image_format': self.image_format,
            'custom_url_params': self.custom_url_params,
            'data_source': self.data_source,
            'instance_id': self.instance_id,
            size_x_name: self._get_parameter('size_x', eopatch),
            size_y_name: self._get_parameter('size_y', eopatch)
        }, service_type
Esempio n. 2
0
    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
Esempio n. 3
0
    def _get_rescale_factors(self, reference_shape, meta_info):
        """ Compute the resampling factor for height and width of the input array

        :param reference_shape: Tuple specifying height and width in pixels of high-resolution array
        :type reference_shape: tuple of ints
        :param meta_info: Meta-info dictionary of input eopatch. Defines OGC request and parameters used to create the
                            eopatch
        :return: Rescale factor for rows and columns
        :rtype: tuple of floats
        """
        # Figure out resampling size
        height, width = reference_shape

        service_type = ServiceType(meta_info['service_type'])
        rescale = None
        if service_type == ServiceType.WMS:

            if (self.cm_size_x is None) and (self.cm_size_y is not None):
                rescale = (self.cm_size_y / height, self.cm_size_y / height)
            elif (self.cm_size_x is not None) and (self.cm_size_y is None):
                rescale = (self.cm_size_x / width, self.cm_size_x / width)
            else:
                rescale = (self.cm_size_y / height, self.cm_size_x / width)

        elif service_type == ServiceType.WCS:
            # Case where only one resolution for cloud masks is specified in 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

            hr_res_x, hr_res_y = int(meta_info['size_x'].strip('m')), int(
                meta_info['size_y'].strip('m'))
            lr_res_x, lr_res_y = int(self.cm_size_x.strip('m')), int(
                self.cm_size_y.strip('m'))
            rescale = (hr_res_y / lr_res_y, hr_res_x / lr_res_x)

        return rescale