geographer package¶
Subpackages¶
- geographer.converters package
- Submodules
- geographer.converters.combine_remove_vector_classes module
DSConverterCombineRemoveClassesDSConverterCombineRemoveClasses.class_separatorDSConverterCombineRemoveClasses.classesDSConverterCombineRemoveClasses.label_makerDSConverterCombineRemoveClasses.nameDSConverterCombineRemoveClasses.new_background_classDSConverterCombineRemoveClasses.new_class_namesDSConverterCombineRemoveClasses.remove_rastersDSConverterCombineRemoveClasses.source_data_dirDSConverterCombineRemoveClasses.target_data_dirDSConverterCombineRemoveClasses.create()DSConverterCombineRemoveClasses.from_json_file()DSConverterCombineRemoveClasses.save()DSConverterCombineRemoveClasses.update()DSConverterCombineRemoveClasses.source_connectorDSConverterCombineRemoveClasses.target_connector
- geographer.converters.label_type_soft_to_categorical module
DSConverterSoftCatToCatDSConverterSoftCatToCat.label_makerDSConverterSoftCatToCat.nameDSConverterSoftCatToCat.source_data_dirDSConverterSoftCatToCat.target_data_dirDSConverterSoftCatToCat.create()DSConverterSoftCatToCat.from_json_file()DSConverterSoftCatToCat.save()DSConverterSoftCatToCat.update()DSConverterSoftCatToCat.source_connectorDSConverterSoftCatToCat.target_connector
- geographer.converters.tif_to_npy module
DSConverterGeoTiffToNpyDSConverterGeoTiffToNpy.bandsDSConverterGeoTiffToNpy.channels_first_or_last_in_npyDSConverterGeoTiffToNpy.nameDSConverterGeoTiffToNpy.source_data_dirDSConverterGeoTiffToNpy.squeeze_label_channel_dim_if_single_channelDSConverterGeoTiffToNpy.target_data_dirDSConverterGeoTiffToNpy.create()DSConverterGeoTiffToNpy.from_json_file()DSConverterGeoTiffToNpy.save()DSConverterGeoTiffToNpy.update()DSConverterGeoTiffToNpy.source_connectorDSConverterGeoTiffToNpy.target_connector
- Module contents
- geographer.cutters package
- Submodules
- geographer.cutters.cut_every_raster_to_grid module
- geographer.cutters.cut_iter_over_rasters module
DSCutterIterOverRastersDSCutterIterOverRasters.bandsDSCutterIterOverRasters.cut_rastersDSCutterIterOverRasters.label_makerDSCutterIterOverRasters.nameDSCutterIterOverRasters.raster_cutterDSCutterIterOverRasters.raster_filter_predicateDSCutterIterOverRasters.source_data_dirDSCutterIterOverRasters.target_data_dirDSCutterIterOverRasters.create()DSCutterIterOverRasters.create_or_update()DSCutterIterOverRasters.cut()DSCutterIterOverRasters.from_json_file()DSCutterIterOverRasters.save()DSCutterIterOverRasters.update()DSCutterIterOverRasters.source_connectorDSCutterIterOverRasters.target_connector
- geographer.cutters.cut_iter_over_vectors module
DSCutterIterOverVectorsDSCutterIterOverVectors.bandsDSCutterIterOverVectors.cut_rastersDSCutterIterOverVectors.label_makerDSCutterIterOverVectors.nameDSCutterIterOverVectors.raster_cutterDSCutterIterOverVectors.raster_selectorDSCutterIterOverVectors.source_data_dirDSCutterIterOverVectors.target_data_dirDSCutterIterOverVectors.vector_filter_predicateDSCutterIterOverVectors.create()DSCutterIterOverVectors.create_or_update()DSCutterIterOverVectors.cut()DSCutterIterOverVectors.from_json_file()DSCutterIterOverVectors.save()DSCutterIterOverVectors.update()DSCutterIterOverVectors.source_connectorDSCutterIterOverVectors.target_connector
remove_duplicates()
- geographer.cutters.cut_rasters_around_every_vector module
- geographer.cutters.raster_filter_predicates module
- geographer.cutters.raster_selectors module
- geographer.cutters.single_raster_cutter_around_vector module
- geographer.cutters.single_raster_cutter_base module
- geographer.cutters.single_raster_cutter_bbox module
- geographer.cutters.single_raster_cutter_grid module
- geographer.cutters.type_aliases module
- geographer.cutters.vector_filter_predicates module
- Module contents
- geographer.downloaders package
- Submodules
- geographer.downloaders.base_download_processor module
- geographer.downloaders.base_downloader_for_single_vector module
- geographer.downloaders.downloader_for_vectors module
- geographer.downloaders.eodag_downloader_for_single_vector module
- geographer.downloaders.jaxa_download_processor module
- geographer.downloaders.jaxa_downloader_for_single_vector module
- geographer.downloaders.sentinel2_download_processor module
- geographer.downloaders.sentinel2_safe_unpacking module
- Module contents
- geographer.graph package
- Submodules
- geographer.graph.bipartite_graph module
BipartiteGraphBipartiteGraph.__eq__()BipartiteGraph.__init__()BipartiteGraph.__opposite_color__()BipartiteGraph.__str__()BipartiteGraph.add_edge()BipartiteGraph.add_vertex()BipartiteGraph.colors()BipartiteGraph.delete_edge()BipartiteGraph.delete_vertex()BipartiteGraph.edge_data()BipartiteGraph.exists_edge()BipartiteGraph.exists_vertex()BipartiteGraph.really_undirected()BipartiteGraph.save_to_file()BipartiteGraph.vertices()BipartiteGraph.vertices_opposite()
empty_bipartite_graph()empty_graph_dict()
- geographer.graph.bipartite_graph_class module
BipartiteGraphClassBipartiteGraphClass.__opposite_color__()BipartiteGraphClass.__str__()BipartiteGraphClass.add_edge()BipartiteGraphClass.add_vertex()BipartiteGraphClass.colors()BipartiteGraphClass.delete_edge()BipartiteGraphClass.delete_vertex()BipartiteGraphClass.edge_data()BipartiteGraphClass.exists_edge()BipartiteGraphClass.exists_vertex()BipartiteGraphClass.really_undirected()BipartiteGraphClass.save_to_file()BipartiteGraphClass.vertices()BipartiteGraphClass.vertices_opposite()
- geographer.graph.bipartite_graph_mixin module
BipartiteGraphMixInBipartiteGraphMixIn.does_raster_contain_vector()BipartiteGraphMixIn.does_raster_intersect_vector()BipartiteGraphMixIn.does_vector_intersect_raster()BipartiteGraphMixIn.have_raster_for_vector()BipartiteGraphMixIn.is_vector_contained_in_raster()BipartiteGraphMixIn.rasters_containing_vector()BipartiteGraphMixIn.rasters_intersecting_vector()BipartiteGraphMixIn.rectangle_bounding_raster()BipartiteGraphMixIn.vectors_contained_in_raster()BipartiteGraphMixIn.vectors_intersecting_raster()
- geographer.graph.type_aliases module
- Module contents
- geographer.label_makers package
- Submodules
- geographer.label_makers.label_maker_base module
- geographer.label_makers.label_type_conversion_utils module
- geographer.label_makers.seg_label_maker_base module
- geographer.label_makers.seg_label_maker_categorical module
- geographer.label_makers.seg_label_maker_soft_categorical module
- Module contents
- geographer.testing package
- geographer.utils package
Submodules¶
geographer.add_drop_rasters_mixin module¶
Mixin that implements adding/dropping rasters.
- class geographer.add_drop_rasters_mixin.AddDropRastersMixIn[source]¶
Bases:
objectMix-in that implements methods to add and drop rasters.
- add_to_rasters(new_rasters, label_maker=None)[source]¶
Add rasters to connector’s
rastersattribute.Adds the new_rasters to the connector’s rasters keeping track of which (vector) geometries are contained in which rasters.
- Parameters:
new_rasters (GeoDataFrame) – GeoDataFrame of raster information conforming to the connector’s rasters format
label_maker (LabelMaker | None) – If given generate labels for new rasters.
- drop_rasters(raster_names, remove_rasters_from_disk=True, label_maker=None)[source]¶
Drop rasters from
rastersand from dataset.Remove rows from the connector’s rasters, delete the corresponding vertices in the graph, and delete the raster from disk (unless remove_rasters_from_disk is set to False).
- Parameters:
raster_names (Sequence[str]) – raster_names/ids of rasters to be dropped.
remove_rasters_from_disk (bool) – If true, delete rasters and labels from disk (if they exist). Defaults to True.
label_maker (LabelMaker | None) – If given, will use label_makers delete_labels method. Defaults to None.
geographer.add_drop_vectors_mixin module¶
Mixin that implements adding/dropping vector features.
- class geographer.add_drop_vectors_mixin.AddDropVectorsMixIn[source]¶
Bases:
objectMix-in that implements adding or dropping vector features.
- add_to_vectors(new_vectors, label_maker=None)[source]¶
Add vector features to connector’s
vectorsattribute.Add (or overwrite) vector features in new_vectors and update graph encoding intersection/containment relations.
- Parameters:
new_vectors (GeoDataFrame) – GeoDataFrame of vector features conforming to the connector’s vectors format
label_maker (LabelMaker | None) – If given generate new labels for rasters containing vector features that were added. Defaults to None.
- drop_vectors(vector_names, label_maker=None)[source]¶
Drop vector features from connector’s
vectorsattribute.Drop vector features from connector’s
vectorsattribute and update graph encoding intersection/containment relations.- Parameters:
vector_names (Sequence[str | int]) – vector_names/identifiers of vector features to be dropped.
label_maker (LabelMaker | None) – If given generate new labels for rasters containing vector features that were dropped. Defaults to None.
geographer.connector module¶
The Connector class organizes and handles remote sensing datasets.
- class geographer.connector.Connector(load_from_disk, data_dir, vectors=None, rasters=None, task_vector_classes=None, background_class=None, crs_epsg_code=4326, raster_count_col_name='raster_count', **kwargs)[source]¶
Bases:
AddDropVectorsMixIn,AddDropRastersMixIn,BipartiteGraphMixInDataset class that connects vector features and raster data.
A
Connectorrepresents a remote sensing computer vision dataset composed of vector features and rasters. It connects the vector features and rasters by a bipartite graph encoding the containment or intersection relationships between them and is a container for tabular information about the vector features and rasters as well as for metadata about the dataset.- Parameters:
load_from_disk (bool)
data_dir (Path | str)
vectors (GeoDataFrame | None)
rasters (GeoDataFrame | None)
task_vector_classes (Sequence[str] | None)
background_class (str | None)
crs_epsg_code (int)
raster_count_col_name (str)
kwargs (Any)
- __init__(load_from_disk, data_dir, vectors=None, rasters=None, task_vector_classes=None, background_class=None, crs_epsg_code=4326, raster_count_col_name='raster_count', **kwargs)[source]¶
Initialize Connector.
Note
We advise you to use the following more convenient constructor methods to initialize a
Connectorinstead of using__init__directly.- To initialize a new connector use
the
from_scratch()class method, orthe
empty_connector_same_format_as()method
- To initialize an existing connector use
the
from_data_dir()class method
- Parameters:
load_from_disk (bool) – whether to load an existing connector from disk or create a new one.
task_vector_classes (Sequence[str] | None) – list of vector feature classes for the machine learning task (excluding mask and background classes). Defaults to None, i.e. the single class “object”
vectors (GeoDataFrame | None) – vectors. Defaults to None, i.e. (if not loading from disk) an empty vectors.
rasters (GeoDataFrame | None) – rasters. Defaults to None, i.e. (if not loading from disk) an empty rasters.
crs_epsg_code (int) – EPSG code connector works with. Defaults to STANDARD_CRS_EPSG_CODE
data_dir (Path | str) – data directory containing rasters_dir, labels_dir, connector_dir.
kwargs (Any) – optional keyword args for subclass implementations.
background_class (str | None)
raster_count_col_name (str)
- add_to_rasters(new_rasters, label_maker=None)¶
Add rasters to connector’s
rastersattribute.Adds the new_rasters to the connector’s rasters keeping track of which (vector) geometries are contained in which rasters.
- Parameters:
new_rasters (GeoDataFrame) – GeoDataFrame of raster information conforming to the connector’s rasters format
label_maker (LabelMaker | None) – If given generate labels for new rasters.
- add_to_vectors(new_vectors, label_maker=None)¶
Add vector features to connector’s
vectorsattribute.Add (or overwrite) vector features in new_vectors and update graph encoding intersection/containment relations.
- Parameters:
new_vectors (GeoDataFrame) – GeoDataFrame of vector features conforming to the connector’s vectors format
label_maker (LabelMaker | None) – If given generate new labels for rasters containing vector features that were added. Defaults to None.
- property all_vector_classes¶
All allowed classes in vectors.
Includes those not related to the ML task (e.g. the background class)
- property connector_dir: Path¶
Directory in which the connector files are saved.
- property crs_epsg_code: int¶
EPSG code of connector’s crs.
Setting
crs_epsg_codewill set automatically set the connector’srastersandvectorscrs.
- property data_dir: str¶
Data directory.
- does_raster_contain_vector(raster_name, vector_name)¶
Return whether a raster fully contains a vector feature.
- Return type:
bool- Parameters:
raster_name (str) – Name of raster
vector_name (str) – name of vector feature
- Returns:
True or False depending on whether the raster contains the vector feature or not
- does_raster_intersect_vector(raster_name, vector_name)¶
Return whether a vector feature intersects a raster.
- Return type:
bool- Parameters:
raster_name (str) – Name of raster
vector_name (str) – name of vector feature
- Returns:
True or False depending on whether the raster intersects the vector feature or not
- does_vector_intersect_raster(vector_name, raster_name)¶
Return whether a vector feature intersects a raster.
- Return type:
bool- Parameters:
raster_name (str) – Name of raster
vector_name (str) – name of vector feature
- Returns:
True or False depending on whether the vector feature intersects the raster or not
- drop_rasters(raster_names, remove_rasters_from_disk=True, label_maker=None)¶
Drop rasters from
rastersand from dataset.Remove rows from the connector’s rasters, delete the corresponding vertices in the graph, and delete the raster from disk (unless remove_rasters_from_disk is set to False).
- Parameters:
raster_names (Sequence[str]) – raster_names/ids of rasters to be dropped.
remove_rasters_from_disk (bool) – If true, delete rasters and labels from disk (if they exist). Defaults to True.
label_maker (LabelMaker | None) – If given, will use label_makers delete_labels method. Defaults to None.
- drop_vectors(vector_names, label_maker=None)¶
Drop vector features from connector’s
vectorsattribute.Drop vector features from connector’s
vectorsattribute and update graph encoding intersection/containment relations.- Parameters:
vector_names (Sequence[str | int]) – vector_names/identifiers of vector features to be dropped.
label_maker (LabelMaker | None) – If given generate new labels for rasters containing vector features that were dropped. Defaults to None.
- empty_connector_same_format(data_dir)[source]¶
Return an empty connector of the same format.
Return an empty connector of the same format (i.e. same columns in vectors and rasters).
- Return type:
- Parameters:
data_dir (Path | str) – data directory containing rasters_dir, labels_dir, connector_dir.
rasters_dir – path to directory containing rasters.
labels_dir – path to directory containing labels.
connector_dir – path to directory containing (geo)json connector component files.
- Returns:
new empty connector
- classmethod from_data_dir(data_dir)[source]¶
Initialize a connector from a data directory.
- Return type:
TypeVar(ConnectorType, bound= Connector)- Parameters:
data_dir (Path | str) – data directory containing ‘connector_files’, ‘rasters’, and ‘labels’ subdirectories
- Returns:
initialized connector
- classmethod from_scratch(**kwargs)[source]¶
Initialize a new connector.
- Return type:
- Parameters:
kwargs (Any)
- Ars:
- **kwargs: same keyword arguments as in
__init__() except for load_from_disk
- **kwargs: same keyword arguments as in
- Returns:
initialized connector
- Parameters:
kwargs (Any)
- Return type:
- property graph_str: str¶
Return a string representation of the internal graph.
Note that the representation might change if the internal representation changes.
- have_raster_for_vector(vector_name)¶
Check if there is a raster fully containing the vector feature.
- Return type:
bool- Parameters:
vector_name (str) – Name of vector feature
- Returns:
True if there is a raster in the dataset fully containing the vector feature, False otherwise.
- is_vector_contained_in_raster(vector_name, raster_name)¶
Return True if a vector feature is fully contained in a raster.
- Return type:
bool- Parameters:
raster_name (str) – Name of raster
vector_name (str) – name of vector feature
- Returns:
True or False depending on whether the vector feature contains the raster or not
- property labels_dir: Path¶
Directory containing the segmentation labels.
- property raster_count_col_name: str¶
Name of column in vectors containing raster counts.
- property raster_data_dirs: list[Path]¶
All directories containing raster data.
Includes e.g. segmentation labels.
- rasters_containing_vector(vector_name, mode='names')¶
Return rasters in which a given vector feature is fully contained.
If multiple vector features are given, return raster which contain at least one of the vector features.
- Return type:
list[str]- Parameters:
vector_name (str | list[str]) – name/id (or list of names) of vector feature(s)
mode (Literal['names', 'paths']) – One of ‘names’ or ‘paths’. In the former case the raster names are
'names'. (returned in the latter case paths to the rasters. Defaults to)
- Returns:
raster_names/identifiers of all rasters in connector containing the vector feature(s)
- property rasters_dir: Path¶
Directory containing the rasters.
- rasters_intersecting_vector(vector_name, mode='names')¶
Return rasters intersecting several vector feature(s).
If more than one vector feature is given, return rasters intersecting at least one of the vector features.
- Return type:
list[str]- Parameters:
vector_name (str | list[str]) – name/id (or list) of vector feature(s)
mode (Literal['names', 'paths']) – One of ‘names’ or ‘paths’. In the former case the raster names are
'names'. (returned in the latter case paths to the rasters. Defaults to)
- Returns:
vector_names/identifiers of all vector features in connector with non-empty intersection with the raster.
- rectangle_bounding_raster(raster_name)¶
Return shapely geometry bounding a raster.
The geometry is with respect to the connector’s (standard) crs.
- Return type:
BaseGeometry- Parameters:
raster_name (str) – the raster_name/identifier of the raster
- Returns:
shapely geometry giving the bounds of the raster in the standard crs of the connector
- property set_raster_count_col_name: str¶
Name of column in vectors containing raster counts.
- vectors_contained_in_raster(raster_name)¶
Return vector features fully containing a given raster.
If several rasters are given return vector features fully containing any of the rasters.
- Return type:
list[str]- Parameters:
raster_name (str | list[str]) – name/id of raster or list of names/ids of rasters
- Returns:
vector_names/identifiers of all vector features in connector contained in the raster(s).
- vectors_intersecting_raster(raster_name)¶
Return vector features intersecting one or (any of) several rasters.
- Return type:
list[str]- Parameters:
raster_name (str | list[str]) – name/id of raster or list names/ids
- Returns:
list of vector_names/ids of all vector features in connector which have non-empty intersection with the raster(s)
- geographer.connector.INFERRED_PATH_ATTR_FILENAMES = {'_graph_path': 'graph.json', '_rasters_path': 'rasters.geojson', '_vectors_path': 'vectors.geojson', 'attrs_path': 'attrs.json'}¶
Attribute self.key will be self.connector_dir / val.
geographer.creator_from_source_dataset_base module¶
ABC for creating or updating a dataset from an existing source dataset.
- class geographer.creator_from_source_dataset_base.DSCreatorFromSource(**data)[source]¶
Bases:
ABC,SaveAndLoadBaseModelMixIn,BaseModelABC for creating or updating a dataset from an existing one.
- Parameters:
source_data_dir (Path)
target_data_dir (Path)
name (str)
extra_data (Any)
- Return type:
None
-
field name:
str[Required]¶ Name of dataset creator. Used as part of filename when saving.
- Validated by:
validate_connectors
-
field source_data_dir:
Path[Required]¶ - Validated by:
validate_connectorsvalidate_source_data_dir
-
field target_data_dir:
Path[Required]¶ - Validated by:
validate_connectors
- classmethod from_json_file(json_file_path, constructor_symbol_table=None)¶
Load and return saved BaseModel.
- Return type:
Any- Parameters:
json_file_path (Path | str)
constructor_symbol_table (dict[str, Any] | None)
- property source_connector¶
Connector in source_data_dir.
- property target_connector¶
Connector in target_data_dir.
- class geographer.creator_from_source_dataset_base.DSCreatorFromSourceWithBands(**data)[source]¶
Bases:
DSCreatorFromSource,ABCABC for creating/updating a dataset from an existing one.
Includes a bands field.
- Parameters:
source_data_dir (Path)
target_data_dir (Path)
name (str)
bands (dict[str, list[int] | None] | None)
extra_data (Any)
- Return type:
None
-
field bands:
Optional[dict[str,Optional[list[int]]]] = None¶ keys: raster directory names, values: list of band indices to keep, starting with 1
- Validated by:
validate_connectors
- field name: str [Required]¶
Name of dataset creator. Used as part of filename when saving.
- Validated by:
validate_connectors
- field source_data_dir: Path [Required]¶
- Validated by:
validate_connectorsvalidate_source_data_dir
- field target_data_dir: Path [Required]¶
- Validated by:
validate_connectors
- classmethod from_json_file(json_file_path, constructor_symbol_table=None)¶
Load and return saved BaseModel.
- Return type:
Any- Parameters:
json_file_path (Path | str)
constructor_symbol_table (dict[str, Any] | None)
- save()¶
Save to update folder in source_data_dir.
- property source_connector¶
Connector in source_data_dir.
- property target_connector¶
Connector in target_data_dir.
geographer.errors module¶
Custom Error classes.
- exception geographer.errors.GeoGrapherError[source]¶
Bases:
ExceptionBase class for exceptions.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception geographer.errors.NoRastersForVectorFoundError[source]¶
Bases:
GeoGrapherErrorNo rasters found or none could be downloaded.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception geographer.errors.RasterAlreadyExistsError[source]¶
Bases:
GeoGrapherErrorRaster already exists in dataset.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception geographer.errors.RasterDownloadError[source]¶
Bases:
GeoGrapherErrorError occurs while downloading raster.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
geographer.global_constants module¶
Global constants.
geographer.raster_bands_getter_mixin module¶
Mix-in that provides methods to get raster bands.