def generate_scenes(self): # If this upload is not associated with a project, set the scene's # ingest status to TOBEINGESTED so that scene creation will kick off # an ingest. Otherwise, set the status to NOTINGESTED, so that the status # will be updated when the scene is added to this upload's project if self.isProjectUpload: ingest_status = IngestStatus.NOTINGESTED else: ingest_status = IngestStatus.TOBEINGESTED for planet_id in set(self.planet_ids): planet_feature, temp_tif_file = self.copy_asset_to_s3(planet_id) planet_key = self.client.auth.value planet_scene = create_planet_scene(planet_feature, self.datasource, self.organizationId, planet_key, ingest_status, self.visibility, self.tags, self.owner) delete_file(temp_tif_file) yield planet_scene
def get_planet_thumbnail(organization_id, thumbnail_uri, planet_key, scene_id): """Download planet thumbnail, push to S3, create RF thumbnail Args: organization_id (str): organization requiring thumbnail thumbnail_uri (str): source thumbnail planet_key (str): planet API key for authentication scene_id (str): scene to attach thumbnail to Returns: Thumbnail """ _, local_filepath = tempfile.mkstemp() params = {'api_key': planet_key} logger.info('Downloading thumbnail for Planet scene: %s', thumbnail_uri) response = requests.get(thumbnail_uri, params=params, stream=True) with open(local_filepath, 'wb') as filehandle: for chunk in response.iter_content(1024): filehandle.write(chunk) thumbnail_key = '{}.png'.format(scene_id) thumbnail_uri = '/thumbnails/{}.png'.format(scene_id) logger.info('Uploading thumbnails to S3: %s', thumbnail_key) s3_bucket_name = os.getenv('THUMBNAIL_BUCKET') s3_bucket = boto3.resource('s3').Bucket(s3_bucket_name) s3_bucket.upload_file(local_filepath, thumbnail_key, {'ContentType': 'image/png'}) delete_file(local_filepath) return Thumbnail(organization_id, 256, 256, 'SMALL', thumbnail_uri, sceneId=scene_id)