aerofiles icon indicating copy to clipboard operation
aerofiles copied to clipboard

What encoding for IGC files reader?

Open kapitan-iglu opened this issue 5 years ago • 1 comments

Hi, I'm using your lib to read GAC files. GAC files are used by FAI General Aviation Commission and they are in fact regular IGC files (as stated in FAI Sporting code, Annex 4, Section 3.6). I have couple of GAC files generated by AFLOS flight recorder. They contain G record at its end, but it does not complain with IGC G record specification. It has four byte binary payload (ex. 0x7E 0x86 0xCE 0xE4) which causes exception when parsed by igc.Reader():

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x86 in position 4868: invalid start byte

If I try to open GAC file in binary mode, igc reader doesn't recognize any fixes. So the file has to be opened in text mode.

Which codec is recommended to use with igc reader?

If I use codec ascii with error handler replace (maybe ignore?), I'm able to decode GAC files. But I'm not sure, if I don't lose anything else from another records too...

kapitan-iglu avatar Mar 23 '21 23:03 kapitan-iglu

from the IGC file spec:

Bildschirmfoto 2021-03-24 um 00 34 01

it looks like that AFLOS recorder is producing invalid files

Turbo87 avatar Mar 23 '21 23:03 Turbo87

Generally speaking, you should use the right encoding for your file. A good explanation is here: https://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html

As stated there, you should use 'latin-1' encoding, if it is an ASCII variant like yours. This will not lead to any exception. As the G record is not evaluated by aerofiles, you should not loose any important stuff.

Something like:

fp = open(filename, encoding='latin-1')

If you don't know the encoding before reading the file, you can use https://pypi.org/project/chardet/ to detect the right encoding. However, this is an additional library not always present.

bubeck avatar Sep 22 '23 10:09 bubeck