コード例 #1
0
ファイル: test_sicd.py プロジェクト: ngageoint/sarpy
    def test_sicd_creation(self):
        for fil in sicd_files:
            reader = SICDReader(fil)

            # check that sicd structure serializes according to the schema
            if etree is not None:
                sicd = reader.get_sicds_as_tuple()[0]
                xml_doc = etree.fromstring(sicd.to_xml_bytes())
                xml_schema = etree.XMLSchema(file=the_schema)
                with self.subTest(
                        msg='validate xml produced from sicd structure'):
                    self.assertTrue(
                        xml_schema.validate(xml_doc),
                        msg='SICD structure serialized from file {} is '
                        'not valid versus schema {}'.format(fil, the_schema))

            # create a temp directory
            temp_directory = tempfile.mkdtemp()

            with self.subTest(
                    msg='Test conversion (recreation) of the sicd file {}'.
                    format(fil)):
                conversion_utility(reader, temp_directory)

            # clean up the temporary directory
            shutil.rmtree(temp_directory)
コード例 #2
0
ファイル: convert_to_sicd.py プロジェクト: nyulacska/sarpy
def convert(input_file, output_dir):
    """

    Parameters
    ----------
    input_file : str
        Path to the input file.
    output_dir : str
        Output directory path.
    """

    conversion_utility(input_file, output_dir)
コード例 #3
0
ファイル: convert_to_sicd.py プロジェクト: bombaci-vsc/sarpy
def convert(input_file, output_dir, preserve_nitf_information=False):
    """

    Parameters
    ----------
    input_file : str
        Path to the input file.
    output_dir : str
        Output directory path.
    preserve_nitf_information : bool
        Try to preserve NITF information? This only applies in the case that the
        file being read is actually a NITF file.
    """

    conversion_utility(input_file, output_dir, preserve_nitf_information=preserve_nitf_information)
コード例 #4
0
def convert(input_file, output_dir):
    conversion_utility(input_file, output_dir)
コード例 #5
0
ファイル: sarpy_example.py プロジェクト: johnhhenderson/sarpy
# the image segment index defaults to 0 for multi-segment images

all_data = reader[:, :, 0]  # reads all data from the image segment at index 0
# = reader[:, :], reader[:] - yields same result, since image index defaults to 0

#################
# Show some basic plots of the data
from matplotlib import pyplot
import sarpy.visualization.remap as remap

fig, axs = pyplot.subplots(nrows=1, ncols=3, figsize=(12, 4))
axs[0].imshow(remap.density(reader[::10, ::10]), cmap='gray')
# Reads every other row and column from the first thousand rows and columns:
axs[1].imshow(remap.density(reader[:1000:2, :1000:2]),
              cmap='gray')  # Display subsampled image
# Reads every row and column from the first thousand rows and columns:
axs[2].imshow(remap.density(reader[0:1000, 0:1000]),
              cmap='gray')  # Display subsampled image
pyplot.show()

##############
# Convert a complex dataset (in any format handled by SarPy) to SICD

from sarpy.io.complex.converter import conversion_utility
# to SICD format
conversion_utility('<complex format file>', '<output_directory>')
# to SIO format
conversion_utility('<complex format file>',
                   '<output_directory>',
                   output_format='sio')
# see help(sarpy.io.complex.converter.conversion_utility)
コード例 #6
0
ファイル: chip_sicd.py プロジェクト: ngageoint/sarpy
def create_chip(input_reader,
                out_directory,
                output_file=None,
                row_limits=None,
                col_limits=None,
                check_existence=True,
                check_older_version=False,
                preserve_nitf_information=False):
    """
    Create a chip of the given sicd file. At least one of `row_limits` and
    `col_limits` must be provided.

    Parameters
    ----------
    input_reader : str|SICDReader
    out_directory : str
        The directory of the output.
    output_file : None|str
        If `None`, then the name will mirror the original with row/col details appended.
    row_limits : None|Tuple[int, int]
        The limits for the rows, relative to this actual image, to be included.
    col_limits : None|Tuple[int, int]
        The limits for the columns, relative to this actual image, to be included.
    check_existence : bool
        Check for the existence of the file before overwriting?
    check_older_version : bool
        Try to use a less recent version of SICD (1.1), for possible application compliance issues?
    preserve_nitf_information : bool
        Try to preserve some of the original NITF information?
    """
    def get_suffix(limits, shift):
        if limits is None:
            return 'all'
        else:
            return '{0:d}-{1:d}'.format(shift + limits[0], shift + limits[1])

    if isinstance(input_reader, str):
        input_reader = SICDReader(input_reader)
    if not isinstance(input_reader, SICDReader):
        raise TypeError(
            'We require that the input is a SICD reader or path to a sicd file.'
        )

    row_limits = _verify_limits(row_limits)
    col_limits = _verify_limits(col_limits)

    if row_limits is None and col_limits is None:
        raise ValueError(
            'At least one of row_limits and col_limits must be provided.')

    if output_file is None:
        fname = os.path.split(input_reader.file_name)[1]
        fstem, fext = os.path.splitext(fname)
        fstem += '_{}_{}'.format(
            get_suffix(row_limits, input_reader.sicd_meta.ImageData.FirstRow),
            get_suffix(col_limits, input_reader.sicd_meta.ImageData.FirstCol))
        fname = fstem + fext
    else:
        fname = os.path.split(output_file)[1]

    conversion_utility(input_reader,
                       out_directory,
                       output_files=fname,
                       row_limits=row_limits,
                       column_limits=col_limits,
                       check_existence=check_existence,
                       check_older_version=check_older_version,
                       preserve_nitf_information=preserve_nitf_information)
コード例 #7
0
ファイル: nominal_sicd_noise.py プロジェクト: ngageoint/sarpy
def nominal_sicd_noise(input_reader,
                       out_directory,
                       output_file=None,
                       noise_db_value=-16.0,
                       override=False,
                       check_existence=True,
                       check_older_version=False,
                       preserve_nitf_information=False):
    """
    Create a sicd with the nominal noise value.

    Parameters
    ----------
    input_reader : str|SICDReader
    out_directory : str
        The directory of the output.
    output_file : None|str
        If `None`, then the name will mirror the original with noise details appended.
    noise_db_value : int|float
        The estimate for nesz in decibels.
    override : bool
        If a NoisePoly is already populated, should we override the value? If `False`
        and a NoisePoly is already populated, then an exception will be raised.
    check_existence : bool
        Check for the existence of the file before overwriting?
    check_older_version : bool
        Try to use a less recent version of SICD (1.1), for possible application
        compliance issues?
    preserve_nitf_information : bool
        Try to preserve some of the original NITF information?
    """

    if isinstance(input_reader, str):
        input_reader = SICDReader(input_reader)
    if not isinstance(input_reader, SICDReader):
        raise TypeError(
            'We require that the input is a SICD reader or path to a sicd file.'
        )

    noise_db_value = float(noise_db_value)
    if noise_db_value > -4:
        logger.warning('The noise estimate should be provided in dB,\n\t'
                       'and the provided value is `{}`.\n\t'
                       'Maybe this is an error?'.format(noise_db_value))

    if output_file is None:
        fname = os.path.split(input_reader.file_name)[1]
        fstem, fext = os.path.splitext(fname)
        fstem += '_{}dB_noise'.format(int(noise_db_value))
        fname = fstem + fext
    else:
        fname = os.path.split(output_file)[1]

    sicd = input_reader.sicd_meta
    if sicd.Radiometric is None:
        raise ValueError(
            'The provided sicd does not contain any radiometric information,\n\t'
            'and SigmaZeroSFPoly is required to proceed')

    new_noise = NoiseLevelType_(NoisePoly=[[
        noise_db_value -
        10 * numpy.log10(sicd.Radiometric.SigmaZeroSFPoly[0, 0]),
    ]],
                                NoiseLevelType='ABSOLUTE')

    if sicd.Radiometric.NoiseLevel is None:
        original_noise = None
    else:
        if not override:
            raise ValueError(
                'The provided sicd already contains radiometric noise information,\n\t'
                'set override=True to replace the value')
        original_noise = sicd.Radiometric.NoiseLevel.copy()
    sicd.Radiometric.NoiseLevel = new_noise

    conversion_utility(input_reader,
                       out_directory,
                       output_files=fname,
                       check_existence=check_existence,
                       check_older_version=check_older_version,
                       preserve_nitf_information=preserve_nitf_information)

    # return to the original noise information, so we haven't modified any in memory reader information
    sicd.Radiometric.NoiseLevel = original_noise