sarpy icon indicating copy to clipboard operation
sarpy copied to clipboard

Not clear how to write .sio file - SIOWriter()

Open shckltn opened this issue 1 year ago • 2 comments

Firstly, sorry if this is the wrong place to post this.

I've been bashing my head against trying to figure out how to write an .sio file using SIOWriter(), but I can't seem to find decent example code anywhere. If anyone has a good example of writing a data set to an .sio file using sarpy please let me know.

It seems that many sicd meta data parameters need to be filled before being able to use the SIOwriter() function with the following function signature:

class sarpy.io.complex.sio.SIOWriter(file_object: str | BinaryIO, sicd_meta: SICDType, user_data: Dict[str, str] | None = None, check_older_version: bool = False, check_existence: bool = True)

Basically I just need a way to write an .sio with only knowing the shape of the data and the pixel type.

I'm trying to initialize a new SICDType below, just so I don't hit errors in the SIOWriter when it's trying to initialize the object.

            # Create and populate a SICD metadata object
            sicd_meta = SICDType(
                    ImageData=ImageDataType(
                        NumRows=outData.shape[0],
                        NumCols=outData.shape[1],
                        PixelType=pixel_type,
                        FirstRow=0,
                        FirstCol=0,
                        FullImage=FullImageType(
                            NumRows=outData.shape[0],
                            NumCols=outData.shape[1]
                        ),
                        SCPPixel=RowColType(Row=outData.shape[0] // 2, Col=outData.shape[1] // 2)
                    ),
                Grid=GridType(
                    ImagePlane='SLANT',  # Example value
                    Type='RGAZIM'  # Example value
                ),
                SCPCOA=SCPCOAType(
                    SCPTime=0  # Example value
                ),
                GeoData=GeoDataType(
                    SCP={'ECF': {'X': 0, 'Y': 0, 'Z': 0}}  # Example values
                ),
                Position=PositionType(),
                Timeline=TimelineType(
                    CollectStart='2024-01-01T00:00:00Z',  # Example value
                    IPP=[IPPSetType(
                        TStart=0,  # Example value
                        TEnd=1,  # Example value
                        IPPStart=0,  # Example value
                        IPPEnd=1  # Example value
                    )]
                ),
            )

            output_file = 'python-output.sio'
            sioWriter = SIOWriter(output_file, sicd_meta, outData.shape)
            # Write the data
            sioWriter.write_chip(outData, (0, 0))
            sioWriter.close()
            

But I am currently still getting the following error:

sarpy\io\complex\sio.py", line 449, in __init__ user_data[\'SICDMETA\'] = sicd_meta.to_xml_string(tag='SICD', urn=uh_args['DESSHTN'])
~~~~~~~~~^^^^^^^^^^^^ TypeError: 'tuple' object does not support item assignment'}]

Any thoughts?

shckltn avatar Jun 10 '24 15:06 shckltn

SARPy's SIO writer is not intended to support generic SIO I/O, but only in the context of an SIO with metadata sufficient to populate a SICD structure. If this is still applicable, it is possible nga-six https://github.com/ngageoint/six-library may have such a capability.

pressler-vsc avatar Aug 26 '24 20:08 pressler-vsc

@shckltn, I think I misread your question and wanted to clarify my prior comment. As you noted, SARPy's SIOWriter is currently hardcoded to write SIOs with user-data containing SICD XML and does not support the metadata-free format that the MATLAB_SAR toolbox does.

If SIOs with user-data are acceptable, then what you are attempting should be possible with SARPy, however there are a few issues getting in the way (assuming you are using the latest release):

  • the error you are receiving is due to an incorrect argument while instantiating a SIOWriter; the third positional argument is user_data which should be a dict of str -> str for use when adding userdata (beyond the SICD XML) to the output SIO. If you don't have such userdata, you can remove that arg, e.g. sioWriter = SIOWriter(output_file, sicd_meta)
  • The bigger issue: while trying to add this case in the form of a unittest, we encountered a number of bugs in sarpy/io/complex/sio.py that prevented writing. We plan to address these in a PR shortly.

Thanks for highlighting this issue!

pressler-vsc avatar Aug 27 '24 16:08 pressler-vsc

Included in version 1.3.59

bombaci-vsc avatar Oct 04 '24 16:10 bombaci-vsc