General NITF reading and writing base implementations (sarpy.io.general.nitf)¶
Module laying out basic functionality for reading and writing NITF files.
Updated extensively in version 1.3.0.
- sarpy.io.general.nitf.extract_image_corners(img_header: ImageSegmentHeader | ImageSegmentHeader0) None | ndarray ¶
Extract the image corner point array for the image segment header.
- Parameters:
img_header (ImageSegmentHeader) –
- Return type:
numpy.ndarray
- sarpy.io.general.nitf.find_jpeg_delimiters(the_bytes: bytes) List[Tuple[int, int]] ¶
Finds regular jpeg delimiters from the image segment bytes.
- Parameters:
the_bytes (bytes) –
- Return type:
List[Tuple[int, int]]
- Raises:
ValueError – If the bytes doesn’t start with the beginning jpeg delimiter and end with the end jpeg delimiter.
- class sarpy.io.general.nitf.NITFDetails(file_object: str | BinaryIO)¶
Bases:
object
This class allows for somewhat general parsing of the header information in a NITF 2.0 or 2.1 file.
- property file_name: str | None¶
the file name, which may not be useful if the input was based on a file like object
- Type:
None|str
- property file_object: BinaryIO¶
The binary file object
- Type:
BinaryIO
- property nitf_header: NITFHeader | NITFHeader0¶
the nitf header object
- Type:
- property img_headers: None | List[ImageSegmentHeader] | List[ImageSegmentHeader0]¶
The image segment headers.
- Returns:
Only None in the unlikely event that there are no image segments.
- Return type:
None|List[ImageSegmentHeader]|List[ImageSegmentHeader0]
- property nitf_version: str¶
The NITF version number.
- Type:
str
- get_image_subheader_bytes(index: int) bytes ¶
Fetches the image segment subheader at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- parse_image_subheader(index: int) ImageSegmentHeader | ImageSegmentHeader0 ¶
Parse the image segment subheader at the given index.
- Parameters:
index (int) –
- Return type:
- get_image_bytes(index: int) bytes ¶
Fetches the image bytes at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- get_text_subheader_bytes(index: int) bytes ¶
Fetches the text segment subheader at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- get_text_bytes(index: int) bytes ¶
Fetches the text extension segment bytes at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- parse_text_subheader(index: int) TextSegmentHeader | TextSegmentHeader0 ¶
Parse the text segment subheader at the given index.
- Parameters:
index (int) –
- Return type:
- get_graphics_subheader_bytes(index: int) bytes ¶
Fetches the graphics segment subheader at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
bytes
- get_graphics_bytes(index: int) bytes ¶
Fetches the graphics extension segment bytes at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
bytes
- parse_graphics_subheader(index: int) GraphicsSegmentHeader ¶
Parse the graphics segment subheader at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
- get_symbol_subheader_bytes(index: int) bytes ¶
Fetches the symbol segment subheader at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
bytes
- get_symbol_bytes(index: int) bytes ¶
Fetches the symbol extension segment bytes at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
bytes
- parse_symbol_subheader(index: int) SymbolSegmentHeader ¶
Parse the symbol segment subheader at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
- get_label_subheader_bytes(index: int) bytes ¶
Fetches the label segment subheader at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
bytes
- get_label_bytes(index: int) bytes ¶
Fetches the label extension segment bytes at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
bytes
- parse_label_subheader(index: int) LabelSegmentHeader ¶
Parse the label segment subheader at the given index (only version 2.0).
- Parameters:
index (int) –
- Return type:
- get_des_subheader_bytes(index: int) bytes ¶
Fetches the data extension segment subheader bytes at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- get_des_bytes(index: int) bytes ¶
Fetches the data extension segment bytes at the given index.
- Parameters:
index (int) –
- Return type:
bytes
- parse_des_subheader(index: int) DataExtensionHeader | DataExtensionHeader0 ¶
Parse the data extension segment subheader at the given index.
- Parameters:
index (int) –
- Return type:
- get_res_subheader_bytes(index: int) bytes ¶
Fetches the reserved extension segment subheader bytes at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
bytes
- get_res_bytes(index: int) bytes ¶
Fetches the reserved extension segment bytes at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
bytes
- parse_res_subheader(index: int) ReservedExtensionHeader | ReservedExtensionHeader0 ¶
Parse the reserved extension subheader at the given index (only version 2.1).
- Parameters:
index (int) –
- Return type:
- get_headers_json() dict ¶
Get a json (i.e. dict) representation of the NITF header elements.
- Return type:
dict
- class sarpy.io.general.nitf.NITFReader(nitf_details: str | BinaryIO | NITFDetails, reader_type='OTHER', reverse_axes: None | int | Sequence[int] = None, transpose_axes: None | Tuple[int, ...] = None)¶
Bases:
BaseReader
A reader implementation based around array-type image data fetching for NITF 2.0 or 2.1 files.
Significantly revised in version 1.3.0 to accommodate the new data segment paradigm. General NITF support is improved from previous version, but there remain unsupported edge cases.
- property nitf_details: NITFDetails¶
The NITF details object.
- Type:
- get_image_header(index: int) ImageSegmentHeader | ImageSegmentHeader0 ¶
Gets the image subheader at the specified index.
- Parameters:
index (int) –
- Return type:
- property file_name: str | None¶
Defined as a convenience property.
- Type:
None|str
- property file_object: BinaryIO¶
the binary file like object from which we are reading
- Type:
BinaryIO
- property unsupported_segments: Tuple[int, ...]¶
The image segments deemed not supported.
- Type:
Tuple[int, …]
- property image_segment_collections: Tuple[Tuple[int, ...]]¶
The definition for how image segments are grouped together to form the output image collection.
Each entry corresponds to a single output image, and the entry defines the image segment indices which are combined to make up the output image.
- Return type:
Tuple[Tuple[int, …]]
- can_use_memmap() bool ¶
Can a memmap be used? This is only supported and/or sensible in the case that the file-like object represents a local file.
- Return type:
bool
- check_for_compliance() Tuple[int, ...] ¶
Gets indices of image segments that cannot (or should not) be opened.
- Return type:
Tuple[int, …]
- find_image_segment_collections() Tuple[Tuple[int, ...]] ¶
Determines the image segments, other than those specifically excluded in unsupported_segments property value. It is implicitly assumed that the elements of a given entry are ordered so that IALVL values are sensible.
Note that in the default implementation, every image segment is simply considered separately.
- Return type:
Tuple[Tuple[int]]
- verify_collection_compliance() None ¶
Verify that image segments collections are compatible.
- Raises:
ValueError –
- create_data_segment_for_image_segment(image_segment_index: int, apply_format: bool) DataSegment ¶
Creates the data segment for the given image segment.
For consistency of simple usage, any bands will be presented in the final formatted/output dimension, regardless of the value of apply_format or IMODE.
For compressed image segments, the IMODE has been abstracted away, and the data segment will be consistent with the raw shape having bands in the final dimension (analogous to IMODE=P).
Note that this also stores a reference to the produced data segment in the _image_segment_data_segments dictionary.
- Parameters:
image_segment_index (int) –
apply_format (bool) – Leave data raw (False), or apply format function and global reverse_axes and transpose_axes values?
- Return type:
- create_data_segment_for_collection_element(collection_index: int) DataSegment ¶
Creates the data segment overarching the given segment collection.
- Parameters:
collection_index (int) –
- Return type:
- get_data_segments() List[DataSegment] ¶
Gets a data segment for each of these image segment collection.
- Return type:
List[DataSegment]
- 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_segment: DataSegment | Tuple[DataSegment, ...]¶
The data segment collection.
- Type:
DataSegment|Tuple[DataSegment, …]
- 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.nitf.is_a(file_name: str | BinaryIO) NITFReader | None ¶
Tests whether a given file_name corresponds to a nitf file. Returns a nitf reader instance, if so.
- Parameters:
file_name (str|BinaryIO) – the file_name to check
- Returns:
NITFReader instance if nitf file, None otherwise
- Return type:
None|NITFReader
- sarpy.io.general.nitf.interpolate_corner_points_string(entry: ndarray, rows: int, cols: int, icp: ndarray)¶
Interpolate the corner points for the given subsection from the given corner points. This supplies entries for the NITF headers. :param entry: The corner pints of the form (row_start, row_stop, col_start, col_stop) :type entry: numpy.ndarray :param rows: The number of rows in the parent image. :type rows: int :param cols: The number of cols in the parent image. :type cols: int :param icp: The parent image corner points in geodetic coordinates. :type icp: numpy.ndarray
- Returns:
suitable for IGEOLO entry.
- Return type:
str
- sarpy.io.general.nitf.default_image_segmentation(rows: int, cols: int, row_limit: int) Tuple[Tuple[int, ...], ...] ¶
Determine the appropriate segmentation for the image. This is driven by the SICD/SIDD standard, and not the only generally feasible segmentation scheme for other NITF file types.
- Parameters:
rows (int) –
cols (int) –
row_limit (int) – It is assumed that this follows the NITF guidelines
- Returns:
Of the form ((row start, row end, column start, column end))
- Return type:
Tuple[Tuple[int, …], …]
- class sarpy.io.general.nitf.SubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
object
Simple manager object for a NITF subheader, and it’s associated information in the NITF writing process.
Introduced in version 1.3.0.
- item_bytes_required = True¶
Are you required to provide the item bytes?
- subheader_type = None¶
What is the type for the subheader?
- property subheader¶
The subheader.
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_size: int | None¶
The item size
- Type:
int
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_written: bool¶
Has the item been written?
- Type:
bool
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- class sarpy.io.general.nitf.ImageSubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
SubheaderManager
- item_bytes_required = False¶
Are you required to provide the item bytes?
- subheader_type¶
alias of
ImageSegmentHeader
- property subheader: ImageSegmentHeader¶
The image subheader. Any image mask subheader should be populated in the mask_subheader property. The size of this will be handled independently of the image bytes.
- Type:
- property item_size: int | None¶
The item size.
- Type:
int
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_written: bool¶
Has the item been written?
- Type:
bool
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- class sarpy.io.general.nitf.GraphicsSubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
SubheaderManager
- item_bytes_required = True¶
Are you required to provide the item bytes?
- subheader_type¶
alias of
GraphicsSegmentHeader
- property subheader: GraphicsSegmentHeader¶
The subheader.
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_size: int | None¶
The item size
- Type:
int
- property item_written: bool¶
Has the item been written?
- Type:
bool
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- class sarpy.io.general.nitf.TextSubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
SubheaderManager
- item_bytes_required = True¶
Are you required to provide the item bytes?
- subheader_type¶
alias of
TextSegmentHeader
- property subheader: TextSegmentHeader¶
The subheader.
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_size: int | None¶
The item size
- Type:
int
- property item_written: bool¶
Has the item been written?
- Type:
bool
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- class sarpy.io.general.nitf.DESSubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
SubheaderManager
- item_bytes_required = True¶
Are you required to provide the item bytes?
- subheader_type¶
alias of
DataExtensionHeader
- property subheader: DataExtensionHeader¶
The subheader.
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_size: int | None¶
The item size
- Type:
int
- property item_written: bool¶
Has the item been written?
- Type:
bool
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- class sarpy.io.general.nitf.RESSubheaderManager(subheader, item_bytes: bytes | None = None)¶
Bases:
SubheaderManager
- item_bytes_required = True¶
Are you required to provide the item bytes?
- subheader_type¶
alias of
DataExtensionHeader
- property subheader: ReservedExtensionHeader¶
The subheader.
- property end_of_item: int | None¶
The position of the end of respective item. This will be the offset for the next element.
- Type:
int
- property item_bytes: bytes | None¶
The item bytes.
- Type:
None|bytes
- property item_offset: int | None¶
The item offset.
- Type:
int
- property item_size: int | None¶
The item size
- Type:
int
- property item_written: bool¶
Has the item been written?
- Type:
bool
- property subheader_offset: int | None¶
The subheader offset.
- Type:
int
- property subheader_size: int¶
The subheader size
- Type:
int
- property subheader_written: bool¶
Has this subheader been written?
- Type:
bool
- write_item(file_object: BinaryIO) None ¶
Write the item bytes (if populated), at its specified offset, to the file. This requires that the subheader has previously be written. If writing occurs, the file location will be advanced to the end of the item location.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- write_subheader(file_object: BinaryIO) None ¶
Write the subheader, at its specified offset, to the file. If writing occurs, the file location will be advanced to the end of the subheader location.
- Parameters:
file_object (BinaryIO) –
- class sarpy.io.general.nitf.NITFWritingDetails(header: NITFHeader, image_managers: Tuple[ImageSubheaderManager, ...] | None = None, image_segment_collections: Tuple[Tuple[int, ...], ...] | None = None, image_segment_coordinates: Tuple[Tuple[Tuple[int, ...], ...], ...] | None = None, graphics_managers: Tuple[GraphicsSubheaderManager, ...] | None = None, text_managers: Tuple[TextSubheaderManager, ...] | None = None, des_managers: Tuple[DESSubheaderManager, ...] | None = None, res_managers: Tuple[RESSubheaderManager, ...] | None = None)¶
Bases:
object
Manager for all the NITF subheader information.
Note that doing anything which modified the size of the headers after initialization (i.e. adding TREs) will not be reflected
Introduced in version 1.3.0.
- property header: NITFHeader¶
The main NITF header. Note that doing anything that changes the size of that header (i.e. adding TREs) after initialization will result in a broken state.
- Type:
- property image_segment_collections: Tuple[Tuple[int, ...]]¶
The definition for how image segments are grouped together to form the aggregate images.
Each entry corresponds to a single aggregate image, and the entry defines the image segment indices which are combined to make up the aggregate image.
This must be an ordered partitioning of the set (0, …, len(image_managers)-1).
- Return type:
Tuple[Tuple[int, …]]
- property image_segment_coordinates: Tuple[Tuple[Tuple[int, ...], ...], ...]¶
The image bounds for the segment collection. This is associated with the image_segment_collection property.
Entry image_segment_coordinates[i] is associated with the ith aggregate image. We have image_segment_coordinates[i] is a tuple of tuples of the form `((row_start, row_end, col_start, col_end)_j,
(row_start, row_end, col_start, col_end)_{j+1}, …)`.
This indicates that the first image segment associated with ith aggregate image is at index j covering the portion of the aggregate image determined by bounds (row_start, row_end, col_start, col_end)_j, the second image segment is at index j+1 covering the portion of the aggregate determined by bounds (row_start, row_end, col_start, col_end)_{j+1}, and so on.
- Return type:
Tuple[Tuple[Tuple[int, …], …], …]
- set_first_image_offset() None ¶
Sets the first image offset from the header length.
- Return type:
None
- verify_images_have_no_compression() bool ¶
Verify that there is no compression set for every image manager. That is, we are going to directly write a NITF file.
- Return type:
bool
- set_all_sizes(require: bool = False) None ¶
This sets the nominal size information in the nitf header, and optionally verifies that all the item_size values are set.
- Parameters:
require (bool) – Require all sizes to be set? 0 will be used as a placeholder for header information population.
- Return type:
None
- verify_all_offsets(require: bool = False) bool ¶
This sets and/or verifies all offsets.
- Parameters:
require (bool) – Require all offsets to be set?
- Return type:
bool
- set_header_clevel() None ¶
Sets the appropriate CLEVEL. This requires that header.FL (file size) has been previously populated correctly (using
verify_all_offsets()
).- Return type:
None
- write_header(file_object: BinaryIO, overwrite: bool = False) None ¶
Write the main NITF header.
- Parameters:
file_object (BinaryIO) –
overwrite (bool) – Overwrite, if previously written?
- Return type:
None
- write_all_populated_items(file_object: BinaryIO) None ¶
Write everything populated. This assumes that the header will start at the beginning (position 0) of the file-like object.
- Parameters:
file_object (BinaryIO) –
- Return type:
None
- class sarpy.io.general.nitf.NITFWriter(file_object: str | BinaryIO, writing_details: NITFWritingDetails, check_existence: bool = True)¶
Bases:
BaseWriter
- property closed: bool¶
Is the writer closed? Reading file after writing can result in a ValueError if writer was not closed.
- Type:
bool
- property data_segment: Tuple[DataSegment, ...]¶
The data segment collection.
- Type:
Tuple[DataSegment, …]
- property data_size: Tuple[Tuple[int, ...]]¶
the formatted data sizes of the data segments.
- Type:
Tuple[Tuple[int, …], …]
- property file_name: str | None¶
Defined as a convenience property.
- Type:
None|str
- property image_count: int¶
The number of overall images/data segments.
- Type:
int
- property raw_data_size: Tuple[int, ...] | Tuple[Tuple[int, ...]]¶
the raw data sizes of the data segments.
- Type:
Tuple[Tuple[int, …], …]
- write(data: ndarray, start_indices: int | Tuple[int, ...] | None = None, subscript: Tuple[slice, ...] | None = None, index: int = 0) None ¶
Write the data to the appropriate data segment. This is an alias to
writer(data, start_indices=start_indices, subscript=subscript, index=index, raw=False)
.Only one of `start_indices` and `subscript` should be specified.
- Parameters:
data (numpy.ndarray) – The data to write.
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, ...]) – In contrast to providing start_indices, the slicing definition in formatted coordinates pertinent to the specified data segment.
index (int) – The index of the
See also
See
meth:sarpy.io.general.data_segment.DataSegment.write.
- write_chip(data: ndarray, start_indices: int | Tuple[int, ...] | None = None, subscript: Tuple[slice, ...] | None = None, index: int = 0) None ¶
This is identical to
write()
, and presented for backwards compatibility.- Parameters:
data (numpy.ndarray) –
start_indices (None|int|Tuple[int, ...]) –
subscript (None|Tuple[slice, ...]) –
index (int) –
See also
See
meth:sarpy.io.general.data_segment.DataSegment.write.
- write_raw(data: ndarray, start_indices: int | Tuple[int, ...] | None = None, subscript: Tuple[slice, ...] | None = None, index: int = 0) None ¶
Write the raw data to the file(s). This is an alias to
writer(data, start_indices=start_indices, subscript=subscript, index=index, raw=True)
.Only one of `start_indices` and `subscript` should be specified.
- Parameters:
data (numpy.ndarray) – The data to write.
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, ...]) – In contrast to providing start_indices, the slicing definition in raw coordinates pertinent to the specified data segment.
index (int) –
See also
See
meth:sarpy.io.general.data_segment.DataSegment.write_raw.
- property nitf_writing_details: NITFWritingDetails¶
The NITF subheader details.
- Type:
- property image_segment_collections: Tuple[Tuple[int, ...]]¶
The definition for how image segments are grouped together to form the aggregate image.
Each entry corresponds to a single output image, and the entry defines the image segment indices which are combined to make up the output image.
- Return type:
Tuple[Tuple[int, …]]
- get_image_header(index: int) ImageSegmentHeader ¶
Gets the image subheader at the specified index.
- Parameters:
index (int) –
- Return type:
- verify_collection_compliance() None ¶
Verify that image segments collections are compatible.
- Raises:
ValueError –
- create_data_segment_for_image_segment(image_segment_index: int, apply_format: bool) DataSegment ¶
Creates the data segment for the given image segment.
For consistency of simple usage, any bands will be presented in the final formatted/output dimension, regardless of the value of apply_format or IMODE.
For compressed image segments, the IMODE has been abstracted away, and the data segment will be consistent with the raw shape having bands in the final dimension (analogous to IMODE=P).
Note that this also stores a reference to the produced data segment in the _image_segment_data_segments list.
This will raise an exception if not performed in the order presented in the writing manager.
- Parameters:
image_segment_index (int) –
apply_format (bool) – Leave data raw (False), or apply format function and global reverse_axes and transpose_axes values?
- Return type:
- create_data_segment_for_collection_element(collection_index: int) DataSegment ¶
Creates the data segment overarching the given segment collection.
- Parameters:
collection_index (int) –
- Return type:
- get_data_segments() List[DataSegment] ¶
Gets a data segment for each of these image segment collection.
- Return type:
List[DataSegment]
- flush(force: bool = False) None ¶
Try to perform any necessary steps to flush written data to the disk/buffer.
- Parameters:
force (bool) – Try force flushing, even for incompletely written data.
- Return type:
None
- close() None ¶
This should perform any necessary final steps, like closing open file handles, deleting any temp files, etc. Trying to read newly created file without closing may raise a ValueError.