Read polder/parasol L2 data using python 3 and parasolascii

Published: 21 décembre 2017

DMCA.com Protection Status

With python os module

Run parasol ascii using python os module:

#!/usr/bin/env python

import os

filename = 'P3L2TRGB071037KL'
command = 'parasolascii -c ' + filename + ' cc > ' + filename + '.ascii'
os.system(command)

to save polder/parasol data in an ascii file.

With python subprocess module

To read a polder/parasol file, it is not necessary to first save the data in an ascii file, one can use the python subprocess module instead, illustration:

#!/usr/bin/env python

import subprocess

filename = 'P3L2TRGB071037KL'

polder_latitude = []
polder_longitude = []
polder_cc = []

command = ['parasolascii', '-g', filename, 'cc']
process = subprocess.Popen(command, stdout=subprocess.PIPE, encoding='utf8')
count = 0
while True:
    text = process.stdout.readline()
    if text != '':
        latitude, longitude, cc = text.split()
        polder_latitude.append( latitude )
        polder_longitude.append( longitude )
        polder_cc.append( cc )      
        count=count+1
    else:
        break

for i in range(100):
    print(polder_latitude[i],polder_longitude[i],polder_cc[i])

returns:

54.750 -3.323 1
54.750 -3.034 1
54.750 -2.745 1
54.750 -2.456 1
54.750 -2.167 1
54.750 -1.878 1
54.750 -1.589 1
.   .   .
.   .   .
.   .   .

References