Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shckltn opened this issue Jun 10, 2024 · 2 comments
Open

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

shckltn opened this issue Jun 10, 2024 · 2 comments
Labels
bug Something isn't working in integration merged into integration branch question Further information is requested

Comments

@shckltn
Copy link

shckltn commented Jun 10, 2024

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?

@pressler-vsc pressler-vsc added the question Further information is requested label Aug 26, 2024
@pressler-vsc
Copy link
Collaborator

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
Copy link
Collaborator

@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 pressler-vsc added the bug Something isn't working label Aug 27, 2024
@pressler-vsc pressler-vsc added the in integration merged into integration branch label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in integration merged into integration branch question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants