Reader Module¶
sensingpy.reader provides classes for loading geospatial raster data from
NetCDF and GeoTIFF files, plus a convenience open() function that dispatches
to the right reader automatically.
ImageReader¶
Base class that defines the common interface for all readers.
ImageReader
¶
Base class for reading geospatial images from different file formats.
This is an abstract base class that defines the interface for all image readers.
Concrete subclasses must implement the read method.
Notes
This class follows the Strategy pattern to provide different algorithms for reading various geospatial file formats while maintaining a consistent interface.
Functions¶
read
¶
Read an image file and convert it to an Image object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the image file to be read |
required |
Returns:
| Type | Description |
|---|---|
Image
|
A processed image with spatial reference information |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This is an abstract method that must be implemented by subclasses |
Source code in sensingpy/reader.py
NetCDFReader¶
Reads multidimensional NetCDF files and exposes bands as Image objects.
NetCDFReader
¶
Bases: ImageReader
Reader for NetCDF image files with geospatial metadata.
This class reads NetCDF (.nc, .nc4, .netcdf) files and extracts image data, coordinate systems, and spatial metadata to create an Image object. It handles various CF-convention metadata structures and fallback options for CRS information.
Notes
NetCDF files can store coordinate reference system (CRS) information in several locations according to the CF conventions. This reader searches for CRS information in coordinates, variables, and global attributes, in that order.
Functions¶
read
¶
Read a NetCDF file and convert it to an Image object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the NetCDF file |
required |
Returns:
| Type | Description |
|---|---|
Image
|
An Image object containing the data, coordinates, and CRS information |
Notes
The reader searches for CRS information in the following locations: 1. DataArrays with a 'crs_wkt' attribute in coordinates 2. Variables with a 'crs_wkt' attribute 3. Global attributes ('crs_wkt' or 'proj4_string')
If no CRS information is found, a default grid mapping variable is created.
Source code in sensingpy/reader.py
GeoTIFFReader¶
Reads single- or multi-band GeoTIFF files and exposes bands as Image objects.
GeoTIFFReader
¶
Bases: ImageReader
Reader for GeoTIFF image files with geospatial metadata.
This class reads GeoTIFF (.tif, .tiff, .geotiff) files and extracts image data, coordinate systems, and spatial metadata to create an Image object. It handles conversion from GDAL/rasterio representation to xarray format.
Notes
The class preserves band-specific metadata, nodata values, and coordinates while transforming raster data into xarray's data model with explicit dimensions and coordinates.
Functions¶
read
¶
Read a GeoTIFF file and convert it to an Image object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the GeoTIFF file |
required |
Returns:
| Type | Description |
|---|---|
Image
|
An Image object containing the data, coordinates, and CRS information |
Notes
This method extracts GeoTIFF metadata including: - Spatial reference information (CRS) - Band data and descriptions - Nodata values - TIFF tags and band-specific metadata
Source code in sensingpy/reader.py
open¶
open
¶
Open an image file using the appropriate reader based on file extension.
This factory function determines the correct reader to use based on the file extension and delegates to the appropriate reader class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the image file to be opened |
required |
Returns:
| Type | Description |
|---|---|
Image
|
An Image object containing the data, coordinates, and CRS information |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file format is not supported based on its extension |
Examples: