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

Integrating Data Extension and Text Segments into SNIP File #612

Open
samrat-boda opened this issue May 16, 2024 · 0 comments
Open

Integrating Data Extension and Text Segments into SNIP File #612

samrat-boda opened this issue May 16, 2024 · 0 comments

Comments

@samrat-boda
Copy link

We've been exploring the test_make_nitf.py script located in modules/python/nitf/samples to understand how to create NITF files programmatically. While we've successfully managed to incorporate the file header, image segment, and various TREs, we're encountering difficulties integrating Data Extension (DES) and Text Segments into the NITF file.

TEXT SEGMENT
For the text segment, we created a new TextSegment and added the subheaders in the same manner. We then created an instance of SegmentWriter for our text segment.The next issue we face is unclear: how to add our text data into this text segment.

Python script

text_segment= record.newTextSegment()
        
        if 'text' in self.fieldmap:
            for field, value in self.fieldmap['text'].items():
                if field in text_segment.subheader:
                    text_segment.subheader[field] = value 
             
        segmentwritter_0=  SegmentWriter(text_segment)  
        segmentwritter_0.attachSource("Sample String for text segment")
        

Error message

Exception has occurred: AttributeError
'str' object has no attribute 'ref'
  File "/mnt/c/Users/bsamrat/Desktop/test-4/snip/lib/python3.10/site-packages/nitf/__init__.py", line 1254, in attachSource
    val = nitropy.nitf_SegmentWriter_attachSource(self.ref, source.ref, self.error) == 1
  File "/mnt/c/Users/bsamrat/Desktop/test-4/test3.py", line 128, in make_image_nitf
    segmentwritter_0.attachSource("Sample String for text segment")
  File "/mnt/c/Users/bsamrat/Desktop/test-4/test3.py", line 197, in <module>
    generator.make_image_nitf()
AttributeError: 'str' object has no attribute 'ref'

DATA EXTENSION SEGMENT
For the data extension segment, we created a new DESegment and added the subheaders similarly. We then created an instance of SegmentWriter for our data extension segment.Our next challenge is understanding how to correctly add DES. We attempted to add a TRE, such as CSEPHA, into this segment instead of a DES, such as CSEPHB. However, this approach is likely incorrect, as TREs and DESs are fundamentally different.

Python script

 data_extension_segment= record.newDataExtensionSegment()
        if 'data' in self.fieldmap:
            for field, value in self.fieldmap['data'].items():
                if field in data_extension_segment.subheader:
                    data_extension_segment.subheader[field] = value 
             
        data_extensionwritter_0=  SegmentWriter(data_extension_segment)

        Data_xhd_0 = record.header.getUDHD() 
        if "TRE" in self.fieldmap['data']:
            for tre_name, tre_data in self.fieldmap['data']['TRE'].items():
                tre_instance= TRE(tre_name)
                for field, value in tre_data.items():
                    tre_instance.setField(field, value)
                Data_xhd_0.append(tre_instance)

Json file

"data": {
        "filePartType": "DE",
        "typeID": "CSEPHB",
        "version": "1",
        "securityClass": "U",
        "dataLength": "85",
        "TRE": {
            "CSEPHA": {
                "EPHEM_FLAG": "0", 
                "DT_EPHEM": "001.000000000",
                "DATE_EPHEM": "20050407",
                "T0_EPHEM": "072405.889000000",
                "NUM_EPHEM": "24",
                "EPHEM_X[0]": "+04148444.25",
                "EPHEM_Y[0]": "+04182009.84",
                "EPHEM_Z[0]": "+03923573.87",
                "EPHEM_X[1]": "+04152554.53",
                "EPHEM_Y[1]": "+04183714.33",
                "EPHEM_Z[1]": "+03917422.66",
                "EPHEM_X[2]": "+04156660.33",
                "EPHEM_Y[2]": "+04185413.51",
                "EPHEM_Z[2]": "+03911266.95",
                "EPHEM_X[3]": "+04160761.72",
                "EPHEM_Y[3]": "+04187107.49",
                "EPHEM_Z[3]": "+03905106.93",
                "EPHEM_X[4]": "+04164858.71",
                "EPHEM_Y[4]": "+04188796.18",
                "EPHEM_Z[4]": "+03898942.43",
                "EPHEM_X[5]": "+04168951.29",
                "EPHEM_Y[5]": "+04190479.57",
                "EPHEM_Z[5]": "+03892773.61",
                "EPHEM_X[6]": "+04173039.48",
                "EPHEM_Y[6]": "+04192157.66",
                "EPHEM_Z[6]": "+03886600.40",
                "EPHEM_X[7]": "+04177123.27",
                "EPHEM_Y[7]": "+04193830.44",
                "EPHEM_Z[7]": "+03880422.78",
                "EPHEM_X[8]": "+04181202.57",
                "EPHEM_Y[8]": "+04195498.02",
                "EPHEM_Z[8]": "+03874240.87",
                "EPHEM_X[9]": "+04185277.46",
                "EPHEM_Y[9]": "+04197160.32",
                "EPHEM_Z[9]": "+03868054.46",
                "EPHEM_X[10]": "+04189347.95",
                "EPHEM_Y[10]": "+04198817.21",
                "EPHEM_Z[10]": "+03861863.83",
                "EPHEM_X[11]": "+04193413.95",
                "EPHEM_Y[11]": "+04200468.89",
                "EPHEM_Z[11]": "+03855668.73",
                "EPHEM_X[12]": "+04197475.54",
                "EPHEM_Y[12]": "+04202115.28",
                "EPHEM_Z[12]": "+03849469.30",
                "EPHEM_X[13]": "+04201532.64",
                "EPHEM_Y[13]": "+04203756.37",
                "EPHEM_Z[13]": "+03843265.58",
                "EPHEM_X[14]": "+04205585.33",
                "EPHEM_Y[14]": "+04205392.15",
                "EPHEM_Z[14]": "+03837057.56",
                "EPHEM_X[15]": "+04209633.53",
                "EPHEM_Y[15]": "+04207022.73",
                "EPHEM_Z[15]": "+03830845.14",
                "EPHEM_X[16]": "+04213677.22",
                "EPHEM_Y[16]": "+04208647.93",
                "EPHEM_Z[16]": "+03824628.51",
                "EPHEM_X[17]": "+04217716.52",
                "EPHEM_Y[17]": "+04210267.81",
                "EPHEM_Z[17]": "+03818407.50",
                "EPHEM_X[18]": "+04221751.22",
                "EPHEM_Y[18]": "+04211882.50",
                "EPHEM_Z[18]": "+03812182.18",
                "EPHEM_X[19]": "+04225781.51",
                "EPHEM_Y[19]": "+04213491.80",
                "EPHEM_Z[19]": "+03805952.55",
                "EPHEM_X[20]": "+04229807.31",
                "EPHEM_Y[20]": "+04215095.78",
                "EPHEM_Z[20]": "+03799718.72",
                "EPHEM_X[21]": "+04233828.61",
                "EPHEM_Y[21]": "+04216694.56",
                "EPHEM_Z[21]": "+03793480.51",
                "EPHEM_X[22]": "+04237845.41",
                "EPHEM_Y[22]": "+04218287.96",
                "EPHEM_Z[22]": "+03787238.07",
                "EPHEM_X[23]": "+04241857.72",
                "EPHEM_Y[23]": "+04219876.04",
                "EPHEM_Z[23]": "+03780991.35"
            } 
        }
    }

Error message

sam@DESKTOP-5VCCDB4:/mnt/c/Users/bsamrat/Desktop/test-4$ /usr/bin/python3 /mnt/c/Users/bsamrat/Desktop/test-4/test3.py
swig/python detected a memory leak of type 'nitf_Uint64 *', no destructor found.
Write Failed: (No raw_data in default!)
2024-05-16 15:29:51,252 DEBUG destruct Record
2024-05-16 15:29:51,254 DEBUG destruct ImageSource
2024-05-16 15:29:51,254 DEBUG destruct BandSource
2024-05-16 15:29:51,254 DEBUG destruct BandSource
2024-05-16 15:29:51,254 DEBUG destruct BandSource
2024-05-16 15:29:51,254 DEBUG destruct SegmentWriter
Exception ignored in: <function SegmentWriter.__del__ at 0x7f19ced456c0>
Traceback (most recent call last):
  File "/mnt/c/Users/bsamrat/Desktop/test-4/snip/lib/python3.10/site-packages/nitf/__init__.py", line 1251, in __del__
    if self.ref: nitropy.nitf_SegmentWriter_destruct(self.ref)
AttributeError: module 'nitf.nitropy' has no attribute 'nitf_SegmentWriter_destruct'
2024-05-16 15:29:51,260 DEBUG destruct Writer
2024-05-16 15:29:51,261 DEBUG destruct ImageWriter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant