sarkit.sidd.NitfWriter

class NitfWriter(file, metadata, jbp_override=None)

Write a SIDD NITF

A NitfWriter object should be used as a context manager in a with statement.

Parameters:
filefile object

SIDD NITF file to write

metadataNitfMetadata

SIDD NITF metadata to write (copied on construction)

jbp_overridejbpy.Jbp or None, optional

Jbp (NITF) object to use. If not provided, one will be created using jbp_from_nitf_metadata.

Methods

write_ded(array)

Write Digital Elevation Data (DED) to a NITF file

write_image(image_number, array)

Write product pixel data to a NITF file

write_legend(image_number, legend_number, array)

Write legend pixel data to a NITF file

See also

NitfReader

Examples

Write a SIDD NITF with a single product image

>>> import sarkit.sidd as sksidd

Build the product image description and pixels

>>> import lxml.etree
>>> sidd_xml = lxml.etree.parse("data/example-sidd-3.0.0.xml")

>>> sec = sksidd.NitfSecurityFields(clas="U")
>>> img_meta = sksidd.NitfProductImageMetadata(
...     xmltree=sidd_xml,
...     im_subheader_part=sksidd.NitfImSubheaderPart(security=sec),
...     de_subheader_part=sksidd.NitfDeSubheaderPart(security=sec),
... )

>>> import numpy as np
>>> img_to_write = np.zeros(
...     sksidd.XmlHelper(sidd_xml).load("{*}Measurement/{*}PixelFootprint"),
...     dtype=sksidd.PIXEL_TYPES[sidd_xml.findtext("{*}Display/{*}PixelType")]["dtype"],
... )

Place the product image in a NITF metadata object

>>> meta = sksidd.NitfMetadata(
...     file_header_part=sksidd.NitfFileHeaderPart(ostaid="my station", security=sec),
...     images=[img_meta],
... )

Write the SIDD NITF to a file

>>> from tempfile import NamedTemporaryFile
>>> outfile = NamedTemporaryFile()
>>> with sksidd.NitfWriter(outfile, meta) as w:
...     w.write_image(0, img_to_write)