Tuesday, 6 April 2021

Fix special characters with closest equivalent without map

I'm getting output from a sensor (GPS) in Python and for some reason, the output is not entirely clean. I'm already using pynmea2 and its checksum to filter out the bad rows but I want to improve the acceptance rate.

If you look at some sample data from the sensor, you see that many characters are replaced with something that could be corrected by a human, such as ® = . or ³ = 3. Some on the other hand, are less clear, such as ¶ or ± or Ç = G and not C.

I've tried to research how I could fix this but short of creating a hardcoded map or search and replace, I can't come up with anything. Is there a library or a way to "clean up" my input to solve at least the obvious one and thus boost my acceptance rate?

nmea = [
    "$GNRMC,175230.00,A,5231.08575,N,01324.94302,E,0.099,,300321,,,A,V*17",
    "$GNRMC,175211.00,A,5231.08495,N,01324.94370,E,2.771,348.30,300321,,,A,V*0F",
    "$GNGGA,175140.00,5231.06514,N,01325.03302,E,1,11,1.22,33.9,M,42.1,Í,,*7F",
    "$GNRMC,175141.00,A,5231.06307,N,01³25.02563,E,16.734,234.24,300³21,,,A,V*3A",
    "$GNGÇA,175141.00,5231.06307,N,01325.02563,E,1,11,1®22,33.6,M,42.1,M,,*75",
    "$GNRMC,175142.00,A,5231.°6059,N,01325.01869,E,17.220,235.29,300321,,,A,V*38",
    "$GNGGA,175142.00,5231.06059,N,01325.01869,E,1,11,±.22,33.5,M,42.1,M,,*79",
    "$GNRMC,175143.00,A,5231.05861,N,01325.01218,E,16.¶45,238.31,300321,,,A,V*37",
    "$GNGGA,175143.00,5231.05861,N,013²5.01218,E,1,11,1.22,34.7,M,42.1,M,,*71",
    "$GNRMC,175144.00,A,5231.05689,N,01325.00574,E,16.090,241.36,300321,,,A,V*33",
    "$GNGGA,175144.00,5231.05689,N,01325.00574,E,1,11,1.28,36.0,M,42.1,M,,*7D",
    "$GNRMC,175145.00,A,5231.05478,N,01324.99957,E,16.045,240.96,300321,,,A,V*31",
    "$GNGGA,175145.00,5231.05478,N,01324.99957,E,1,11,1.22,36.8,M,42.1,M,,*7E",
    "$GNRMC,175146®00,A,5231.05277,N,01324.99327,E,15.832,241.30,300321,,,A,V*30",
    "$GNGGA,175146.00,5231.05277,N,01324.99327,E,1,11,1.22,37.3,M,42.1,M,,*73",
    "$GNGGA,175230.00,5231.08575,N,01324.94302,E,1,12,0.96,56.7,M,42.1,M,,*7D"]


from Fix special characters with closest equivalent without map

No comments:

Post a Comment