def setUp(self): builder = GraphBuilder() id = builder.process("get_collection", {'name': 'S1'}) connection = MagicMock(spec=Connection) capabilities = MagicMock(spec=Capabilities) connection.capabilities.return_value = capabilities capabilities.version.return_value = "0.4.0" self.img = ImageCollectionClient(id, builder, connection) builder = GraphBuilder() mask_id = builder.process("get_collection", {'name': 'S1_Mask'}) self.mask = ImageCollectionClient(mask_id, builder, connection)
def create_collection(cls, collection_id: str, session: Connection = None, spatial_extent: Union[Dict, None] = None, temporal_extent: Union[List, None] = None, bands: Union[List, None] = None): """ Create a new Image Collection/Raster Data cube. :param collection_id: A collection id, should exist in the backend. :param session: The session to use to connect with the backend. :param spatial_extent: limit data to specified bounding box or polygons :param temporal_extent: limit data to specified temporal interval :param bands: only add the specified bands :return: """ # TODO: rename function to load_collection for better similarity with corresponding process id? builder = GraphBuilder() if session.capabilities().api_version_check.at_least('0.4.0'): process_id = 'load_collection' arguments = { 'id': collection_id, 'spatial_extent': spatial_extent, 'temporal_extent': temporal_extent, } if bands: arguments['bands'] = bands else: process_id = 'get_collection' arguments = {'name': collection_id} id = builder.process(process_id, arguments) return ImageCollectionClient(id, builder, session)
def load_disk_collection(cls, session: 'Connection', file_format: str, glob_pattern: str, **options) -> 'ImageCollection': """ Loads image data from disk as an ImageCollection. :param session: The session to use to connect with the backend. :param file_format: the file format, e.g. 'GTiff' :param glob_pattern: a glob pattern that matches the files to load from disk :param options: options specific to the file format :return: the data as an ImageCollection """ assert session.capabilities().api_version_check.at_least('0.4.0') builder = GraphBuilder() process_id = 'load_disk_data' arguments = { 'format': file_format, 'glob_pattern': glob_pattern, 'options': options } node_id = builder.process(process_id, arguments) return cls(node_id, builder, session, metadata={})
def load_collection(cls, collection_id: str, session: 'Connection' = None, spatial_extent: Union[Dict[str, float], None] = None, temporal_extent: Union[List[str], None] = None, bands: Union[List[str], None] = None, fetch_metadata=True): """ Create a new Image Collection/Raster Data cube. :param collection_id: A collection id, should exist in the backend. :param session: The session to use to connect with the backend. :param spatial_extent: limit data to specified bounding box or polygons :param temporal_extent: limit data to specified temporal interval :param bands: only add the specified bands :return: """ # TODO: rename function to load_collection for better similarity with corresponding process id? assert session.capabilities().api_version_check.at_least('0.4.0') builder = GraphBuilder() process_id = 'load_collection' arguments = { 'id': collection_id, 'spatial_extent': spatial_extent, 'temporal_extent': temporal_extent, } if bands: arguments['bands'] = bands node_id = builder.process(process_id, arguments) metadata = session.collection_metadata( collection_id) if fetch_metadata else None return cls(node_id, builder, session, metadata=metadata)
def image_collection(): builder = GraphBuilder() id = builder.process("get_collection", {'name': 'S1'}) connection = MagicMock(spec=Connection) capabilities = MagicMock(spec=Capabilities) connection.capabilities.return_value = capabilities capabilities.version.return_value = "0.4.0" return ImageCollectionClient(id, builder, connection)
def graph_add_process(self, process_id, args) -> 'ImageCollection': """ Returns a new restimagery with an added process with the given process id and a dictionary of arguments :param process_id: String, Process Id of the added process. :param args: Dict, Arguments of the process. :return: imagery: Instance of the RestImagery class """ #don't modify in place, return new builder newbuilder = GraphBuilder(self.builder.processes) id = newbuilder.process(process_id, args) newCollection = ImageCollectionClient(id, newbuilder, self.session) newCollection.bands = self.bands return newCollection
def test_create_empty(self): builder = GraphBuilder() builder.process("sum", {}) self.assertEqual(1, len(builder.processes))