def test_invalid_request(self): request = DownloadRequest( save_response=True, data_folder=None, ) with self.assertRaises(ValueError): request.raise_if_invalid()
def test_filename_warnings(self): request = DownloadRequest( save_response=True, data_folder='', filename='a' * 256 + '.jpg' ) with self.assertWarns(SHRuntimeWarning): request.get_storage_paths()
def _collect_data(self, mask_list): download_list = [ DownloadRequest(url=mask_props['objectPath'], save_response=False, data_type=MimeType.PNG) for mask_props in mask_list ] images = [ future.result(timeout=60) for future in download_data(download_list) ] image_names = [mask_props['niceName'] for mask_props in mask_list] # TODO: Change this hardcoded part data_dict = {} for image, image_name in zip(images, image_names): class_name = image_name.rsplit('_', 1)[1].split('.')[0] layer_name = { 'Opaque clouds': 'Clouds', 'Thick clouds': 'Clouds', 'Thin clouds': 'Clouds', 'Shadows': 'Shadows', 'Land': 'Surface', 'Water': 'Surface', 'Snow': 'Surface' }[class_name] data_dict[layer_name] = data_dict.get(layer_name, {}) data_dict[layer_name][class_name] = image return self._join_data_dict(data_dict)
def execute(self, eopatch=None, bbox=None, time_interval=None): """ Main execute method for the Processing API tasks """ if eopatch is not None and (bbox or time_interval): raise ValueError( 'Either an eopatch must be provided or bbox and time interval, not both.' ) if eopatch is None: eopatch = EOPatch() eopatch.bbox = bbox if self.size is not None: size_x, size_y = self.size elif self.resolution is not None: size_x, size_y = bbox_to_dimensions(eopatch.bbox, self.resolution) if time_interval: time_interval = parse_time_interval(time_interval) timestamp = self._get_timestamp(time_interval, bbox) else: timestamp = None if eopatch.timestamp: self.check_timestamp_difference(timestamp, eopatch.timestamp) elif timestamp: eopatch.timestamp = timestamp payloads = self._build_payloads(bbox, size_x, size_y, timestamp, time_interval) requests = [ DownloadRequest(post_values=payload, **self.request_args) for payload in payloads ] LOGGER.debug('Downloading %d requests of type %s', len(requests), str(self.data_source)) client = SentinelHubDownloadClient(config=self.config) images = client.download(requests, max_threads=self.max_threads) LOGGER.debug('Downloads complete') temporal_dim = len(timestamp) if timestamp else 1 shape = temporal_dim, size_y, size_x self._extract_data(eopatch, images, shape) eopatch.meta_info['size_x'] = size_x eopatch.meta_info['size_y'] = size_y eopatch.meta_info['time_interval'] = time_interval eopatch.meta_info['service_type'] = 'processing' self._add_meta_info(eopatch) return eopatch
def setUp(cls): super().setUpClass() cls.request = DownloadRequest( url='https://roda.sentinel-hub.com/sentinel-s2-l1c/tiles/1/C/CV/2017/1/14/0/tileInfo.json', headers={'Content-Type': MimeType.JSON.get_string()}, data_type='json', save_response=True, data_folder=cls.OUTPUT_FOLDER, filename=None, return_data=True )
def _collect_data(self, url): download_list = [ DownloadRequest(url=url, save_response=False, data_type=MimeType.RAW) ] raw_image = download_data(download_list)[0].result(timeout=60) bbox = self.get_bbox(BytesIO(raw_image)) image = np.array(Image.open(BytesIO(raw_image))) return image, bbox
def test_general(self): data_folder = './data' request = DownloadRequest( url='www.sentinel-hub.com', headers={'Content-Type': MimeType.JSON.get_string()}, request_type='POST', post_values={'test': 'test'}, data_type='png', save_response=True, data_folder=data_folder, filename=None, return_data=True, additional_param=True ) self.assertTrue(isinstance(request.get_request_params(include_metadata=True), dict)) hashed_name = request.get_hashed_name() self.assertEqual(hashed_name, '3908682090daba44fca620fc09cc7cfe') request_path, response_path = request.get_storage_paths() self.assertEqual(request_path, os.path.join(data_folder, hashed_name, 'request.json')) self.assertEqual(response_path, os.path.join(data_folder, hashed_name, 'response.png'))
{ "identifier": "default", "format": { 'type': MimeType.TIFF.get_string() } } ] }, "evalscript": evalscript_true_colour } # create request download_request = DownloadRequest( request_type='POST', url="https://services.sentinel-hub.com/api/v1/process", post_values=request_raw_dict, data_type=MimeType.TIFF, headers={'content-type': 'application/json'}, use_session=True ) # execute request client = SentinelHubDownloadClient(config=config) img = client.download(download_request) fig, ax = plt.subplots(figsize=(10, 10)) ax.imshow(change_brightness(image, 3.5, 0)) ax.set_title("Raw dictionary request") # Example 8: Multiple timestamps data_type """