Tiff/BigTiff reading methods (sarpy.io.general.tiff)¶
Module providing api consistent with other file types for reading tiff files.
- class sarpy.io.general.tiff.TiffDetails(file_name: str)¶
Bases:
object
For checking tiff metadata, and parsing in the event we are not using GDAL
- property file_name: str¶
READ ONLY. The file name.
- Type:
str
- property endian: str¶
READ ONLY. The numpy dtype style
('>' = big, '<' = little)
endian string for the tiff file.- Type:
str
- property tags: Dict[str, str | ndarray]¶
READ ONLY. The tiff tags dictionary, provided that
parse_tags()
has been called. This dictionary is of the form {<tag name> : str|numpy.ndarray}, even for those tags containing only a single entry (i.e. count=1).- Type:
Dict
- parse_tags() None ¶
Parse the tags from the file, if desired. This sets the tags attribute.
- Return type:
None
- check_compression()¶
Check the Compression tag, and verify uncompressed.
- Return type:
None
- check_tiled()¶
Check if the tiff file is tiled.
- Return type:
None
- class sarpy.io.general.tiff.NativeTiffDataSegment(tiff_details: str | TiffDetails, reverse_axes: None | int | Sequence[int] = None, transpose_axes: None | Tuple[int, ...] = None)¶
Bases:
NumpyMemmapSegment
Direct reading of data from tiff file, failing if compression is present.
This is a very complex SAR specific implementation, and not general.
- property can_write_regular: bool¶
Can this data segment write regular data, which requires a function inverse?
- Type:
bool
- check_fully_written(warn: bool = False) bool ¶
Checks that all expected pixel data is fully written.
- Parameters:
warn (bool) – Log warning with some details if not fully written.
- Return type:
bool
- close()¶
This should perform any necessary clean-up operations, like closing open file handles, deleting any temp files, etc
- property close_file: bool¶
Close the file object when complete?
- Type:
bool
- property closed: bool¶
Is the data segment closed? Reading or writing will result in a ValueError
- Type:
bool
- flush() None ¶
Should perform, if possible, any necessary steps to flush any unwritten data to the file.
- Return type:
None
- property format_function: FormatFunction¶
The format function which will be applied to the raw data.
- Return type:
- property formatted_dtype: dtype¶
The data type of the formatted data, which will be returned by the
read()
function.- Type:
numpy.dtype
- property formatted_ndim: int¶
The number of formatted dimensions.
- Type:
int
- property formatted_shape: Tuple[int, ...]¶
The formatted data shape.
- Type:
Tuple[int, …]
- get_raw_bytes(warn: bool = False) bytes | Tuple ¶
This returns the bytes for the underlying raw data.
Warning
A data segment is conceptually represented in raw data as a single numpy array of appropriate shape and data type. When the data segment is formed from component pieces, then the return of this function may deviate significantly from the raw byte representation of such an array after consideration of data order and pad pixels.
- Parameters:
warn (bool) – If True, then a check will be performed to ensure that the data has been fully written and warnings printed if the answer is no.
- Returns:
The result will be a bytes object, unless the data segment is made up of a collection of child data segments, in which case the result will be a Tuple consisting of their get_raw_bytes returns.
- Return type:
bytes|Tuple
- property mode: str¶
The mode.
- Type:
str
- property raw_dtype: dtype¶
The data type of the data returned by the
read_raw()
function.- Type:
numpy.dtype
- property raw_ndim: int¶
The number of raw dimensions.
- Type:
int
- property raw_shape: Tuple[int, ...]¶
The raw shape.
- Type:
Tuple[int, …]
- read(subscript: None | int | slice | Sequence[int | slice | Tuple[int, ...]], squeeze=True) ndarray ¶
In keeping with data segment mode, read the data slice specified relative to the formatted data coordinates. This requires that mode is ‘r’.
- Parameters:
subscript (None|int|slice|Sequence[int|slice|Tuple[int, ...]]) –
squeeze (bool) – Apply the numpy.squeeze operation, which eliminates dimension of size 1?
- Return type:
numpy.ndarray
- read_raw(subscript: None | int | slice | Sequence[int | slice | Tuple[int, ...]], squeeze=True) ndarray ¶
In keeping with data segment mode, read raw data from the source, without reformatting and or applying symmetry operations. This requires that mode is ‘r’.
- Parameters:
subscript (None|int|slice|Sequence[int|slice|Tuple[int, ...]]) – These arguments are relative to raw data shape and order, no symmetry operations have been applied.
squeeze (bool) – Apply numpy.squeeze, which eliminates any dimensions of size 1?
- Returns:
This will be of data type given by raw_dtype.
- Return type:
numpy.ndarray
- property reverse_axes: Tuple[int, ...] | None¶
The collection of axes (with respect to raw order) along which we will reverse as part of transformation to formatted data order. If not None, then this will be a tuple in strictly increasing order.
- Type:
None|Tuple[int, …]
- property transpose_axes: Tuple[int, ...]¶
The transpose order for switching from raw order to formatted order, prior to applying any format function.
If populated, this must be a permutation of (0, 1, …, raw_ndim-1).
- Type:
None|Tuple[int, …]
- property underlying_array: ndarray¶
The underlying data array.
- Return type:
numpy.ndarray
- verify_formatted_subscript(subscript: None | int | slice | Sequence[int | slice | Tuple[int, ...]]) Tuple[slice, ...] ¶
Verifies that the structure of the subscript is in keeping with the formatted shape, and fills in any missing dimensions.
- Parameters:
subscript (None|int|slice|Sequence[int|slice|Tuple[int, ...]]) –
- Returns:
Guaranteed to be a tuple of slices of length formatted_ndim.
- Return type:
Tuple[slice, …]
- verify_raw_subscript(subscript: None | int | slice | Sequence[int | slice | Tuple[int, ...]]) Tuple[slice, ...] ¶
Verifies that the structure of the subscript is in keeping with the raw shape, and fills in any missing dimensions.
- Parameters:
subscript (None|int|slice|Sequence[int|slice|Tuple[int, ...]]) –
- Returns:
Guaranteed to be a tuple of slices of length raw_ndim.
- Return type:
Tuple[slice, …]
- write(data: ndarray, start_indices: None | int | Tuple[int, ...] = None, subscript: None | Sequence[slice] = None, **kwargs) None ¶
In keeping with data segment mode, write the data provided in formatted form, assuming the slice specified relative to the formatted data coordinates.
This requires that mode is ‘w’, and format_function.has_inverse == True, because we have to apply the format function inverse to the provided data.
Only one of `start_indices` and `subscript` should be specified.
- Parameters:
data (numpy.ndarray) – The data in formatted form, to be transferred to raw form and written.
start_indices (None|int|Tuple[int, ...]) – Assuming a contiguous chunk of data, this provides the starting indices of the chunk. Any missing (tail) coordinates will be filled in with 0’s.
subscript (None|Sequence[slice]) – The subscript definition in formatted coordinates.
kwargs –
- Return type:
None
- write_raw(data: ndarray, start_indices: int | Tuple[int, ...] | None = None, subscript: Sequence[slice] | None = None, **kwargs)¶
In keeping with data segment mode, write the data provided in raw form, assuming the slice specified relative to raw data coordinates. This requires that mode is ‘w’.
Only one of `start_indices` and `subscript` should be specified.
- Parameters:
data (numpy.ndarray) – The data in raw form.
start_indices (None|int|Tuple[int, ...]) – Assuming a contiguous chunk of data, this provides the starting indices of the chunk. Any missing (tail) coordinates will be filled in with 0’s.
subscript (None|Tuple[slice, ...]) – The subscript definition in raw coordinates.
kwargs –
- Return type:
None
- class sarpy.io.general.tiff.TiffReader(tiff_details: str | TiffDetails, reverse_axes: None | int | Sequence[int] = None, transpose_axes: None | Tuple[int, ...] = None)¶
Bases:
BaseReader
- property data_segment: NativeTiffDataSegment¶
The tiff data segment.
- Type:
- property tiff_details: TiffDetails¶
The tiff details object.
- Type:
- property file_name¶
Defined as a convenience property.
- Type:
None|str
- close() None ¶
This should perform any necessary clean-up operations, like closing open file handles, deleting any temp files, etc.
- property closed: bool¶
Is the reader closed? Reading will result in a ValueError
- Type:
bool
- property data_size: Tuple[int, ...] | Tuple[Tuple[int, ...]]¶
the output/formatted data size(s) of the data segment(s). If there is a single data segment, then this will be Tuple[int, …], otherwise it will be Tuple[Tuple, int, …], …].
- Type:
Tuple[int, …]|Tuple[Tuple[int, …], …]
- property files_to_delete_on_close: List[str]¶
A collection of files to delete on the close operation.
- Type:
List[str]
- get_data_segment_as_tuple() Tuple[DataSegment, ...] ¶
Get the data segment collection as a tuple, to avoid the need for redundant checking issues.
- Return type:
Tuple[DataSegment, …]
- get_data_size_as_tuple() Tuple[Tuple[int, ...], ...] ¶
Get the data size collection as a tuple of tuples, to avoid the need for redundant checking issues.
- Return type:
Tuple[Tuple[int, …], …]
- get_raw_data_size_as_tuple() Tuple[Tuple[int, ...], ...] ¶
Get the raw data size collection as a tuple of tuples, to avoid the need for redundant checking issues.
- Return type:
Tuple[Tuple[int, …], …]
- property image_count: int¶
The number of images/data segments from which to read.
- Type:
int
- property raw_data_size: Tuple[int, ...] | Tuple[Tuple[int, ...]]¶
the raw data size(s) of the data segment(s). If there is a single data segment, then this will be Tuple[int, …], otherwise it will be Tuple[Tuple, int, …], …].
- Type:
Tuple[int, …]|Tuple[Tuple[int, …], …]
- read(*ranges: None | int | Tuple[int, ...] | slice, index: int = 0, squeeze: bool = True) ndarray ¶
Read formatted data from the given data segment. Note this is an alias to the
__call__()
called asreader(*ranges, index=index, raw=False, squeeze=squeeze)
.- Parameters:
ranges (Sequence[Union[None, int, Tuple[int, ...], slice]]) – The slice definition appropriate for data_segment[index].read() usage.
index (int) – The data_segment index. This is ignored if image_count== 1.
squeeze (bool) – Squeeze length 1 dimensions out of the shape of the return array?
- Return type:
numpy.ndarray
See also
See
meth:sarpy.io.general.data_segment.DataSegment.read.
- read_chip(*ranges: Sequence[None | int | Tuple[int, ...] | slice], index: int = 0, squeeze: bool = True) ndarray ¶
This is identical to
read()
, and presented for backwards compatibility.- Parameters:
ranges (Sequence[Union[None, int, Tuple[int, ...], slice]]) –
index (int) –
squeeze (bool) –
- Return type:
numpy.ndarray
See also
- read_raw(*ranges: None | int | Tuple[int, ...] | slice, index: int = 0, squeeze: bool = True) ndarray ¶
Read raw data from the given data segment. Note this is an alias to the
__call__()
called asreader(*ranges, index=index, raw=True, squeeze=squeeze)
.- Parameters:
ranges (Sequence[Union[None, int, Tuple[int, ...], slice]]) – The slice definition appropriate for data_segment[index].read() usage.
index (int) – The data_segment index. This is ignored if image_count== 1.
squeeze (bool) – Squeeze length 1 dimensions out of the shape of the return array?
- Return type:
numpy.ndarray
See also
See
meth:sarpy.io.general.data_segment.DataSegment.read_raw.
- property reader_type: str¶
A descriptive string for the type of reader
- Type:
str
- sarpy.io.general.tiff.is_a(file_name: str) None | TiffReader ¶
Tests whether a given file_name corresponds to a tiff file. Returns a tiff reader instance, if so.
- Parameters:
file_name (str) – the file_name to check
- Returns:
TiffReader instance if tiff file, None otherwise
- Return type:
None|TiffReader