Commit 7eef0bac authored by caveenj's avatar caveenj

Modifier odf2csv pour que la moyenne ne soit pas calculee automatiquement

Correction d'un bogue lors du moyennage ou on traitait les QQQQ ou QFFF pour les
moyennes
Ajout du fichier setup.py servant a faire une distribution (setup.py bdist)
parent 9c3dc88c
...@@ -6,5 +6,5 @@ cd ../test_data ...@@ -6,5 +6,5 @@ cd ../test_data
for ficin in *.ODF for ficin in *.ODF
do do
ficout=`basename ${ficin} .ODF` ficout=`basename ${ficin} .ODF`
../src/odf2csv.py -i ${ficin} -o ${ficout}_all.csv --all ../src/odf2csv.py -i ${ficin} -o ${ficout}all.csv
done done
#!/bin/sh #!/bin/sh
#Convertir tous les fichiers odf en conservant #Convertir tous les fichiers odf en
# toutes les donnees #moyennant au 10 metres en eliminitant douteux et erreurs
cd ../test_data cd ../test_data
for ficin in *.ODF for ficin in *.ODF
do do
ficout=`basename ${ficin} .ODF` ficout=`basename ${ficin} .ODF`
../src/odf2csv.py -i ${ficin} -o ${ficout}_mean.csv --mean 10 ../src/odf2csv.py -i ${ficin} -o ${ficout}mean.csv --doubtfull --error --mean 10
done done
#!/usr/bin/env python #!/usr/bin/env python
#! python
##################################### #####################################
# #
...@@ -17,18 +18,18 @@ import math ...@@ -17,18 +18,18 @@ import math
from class_variable import variable from class_variable import variable
import odf_fcns import odf_fcns
RemplacerDouteux = True RemplacerDouteux = False
RemplacerErreur = True RemplacerErreur = False
CalculerMoyenne = True CalculerMoyenne = False
intervalle = 1.0 intervalle = 1.0
#On recupere les parametres d'appel #On recupere les parametres d'appel
try: try:
opts,args = getopt.getopt(sys.argv[1:], \ opts,args = getopt.getopt(sys.argv[1:], \
'i:o:m:deah',\ 'i:o:m:deh',\
['input=','output=',\ ['input=','output=',\
'mean=','all','error',\ 'mean=','error',\
'douteux','help']) 'doubtfull','help'])
except getopt.error, msg: except getopt.error, msg:
print msg print msg
odf_fcns.usage() odf_fcns.usage()
...@@ -42,35 +43,31 @@ for o , a in opts: ...@@ -42,35 +43,31 @@ for o , a in opts:
elif o in ("-i","--input"): elif o in ("-i","--input"):
if a in ("-i","--input","-o","--output","-d",\ if a in ("-i","--input","-o","--output","-d",\
"--douteux","-e","--error","-h","--help","--mean","-m",\ "--doubtfull","-e","--error","-h","--help","--mean","-m"):
"-a","--all"):
odf_fcns.usage() odf_fcns.usage()
sys.exit(2) sys.exit(2)
fnomin = a fnomin = a
elif o in ("-o","--output"): elif o in ("-o","--output"):
if a in ("-i","--input","-o","--output","-d",\ if a in ("-i","--input","-o","--output","-d",\
"--douteux","-e","--error","-h","--help","--mean","-m",\ "--doubtfull","-e","--error","-h","--help","--mean","-m"):
"-a","--all"):
odf_fcns.usage() odf_fcns.usage()
sys.exit(2) sys.exit(2)
fnomout = a fnomout = a
elif o in ("-m","--mean"): elif o in ("-m","--mean"):
if a in ("-i","--input","-o","--output","-d",\ if a in ("-i","--input","-o","--output","-d",\
"--douteux","-e","--error","-h","--help","--mean","-m",\ "--doubtfull","-e","--error","-h","--help","--mean","-m"):
"-a","--all"):
odf_fcns.usage() odf_fcns.usage()
sys.exit(2) sys.exit(2)
intervalle = float(a) intervalle = float(a)
CalculerMoyenne = True
elif o in ("-d","--douteux"): elif o in ("-d","--doubtfull"):
RemplacerDouteux = False RemplacerDouteux = True
elif o in ("-e","--error"): elif o in ("-e","--error"):
RemplacerErreur = False RemplacerErreur = True
elif o in ("-a","--all"):
CalculerMoyenne = False
else: else:
print "Option inconnue" print "Option inconnue"
odf_fcns.usage() odf_fcns.usage()
...@@ -354,34 +351,40 @@ if (CalculerMoyenne): ...@@ -354,34 +351,40 @@ if (CalculerMoyenne):
# Ici, on traite toutes les variables sauf PRES et DEPTH # Ici, on traite toutes les variables sauf PRES et DEPTH
for var in varlist: for var in varlist:
if not DEPTH.search(var.getcode()) and not PRES.search(var.getcode()):
if not DEPTH.search(var.getcode()) and not PRES.search(var.getcode()) and \
not QCFF.search(var.getcode()) and not QQQQ.search(var.getcode()):
print "On traite:", var.getcode() print "On traite:", var.getcode()
if(var_q.has_key(var)): if(var_q.has_key(var)):
qualite = var_q.get(var) qualite = var_q.get(var)
mean_dat = []
qualite_dat = [] qualite_dat = []
for k in range(num_depth): mean_dat = []
sum_dat=0
n_dat=0
for i in range(var.getnbval()): for k in range(num_depth):
if float(profondeur.getvaleur(i)) > (depth[k]-intervalle/2.0) and \ sum_dat=0
float(profondeur.getvaleur(i)) <= (depth[k]+intervalle/2.0) and \ n_dat=0
float(var.getvaleur(i)) > -99 : for i in range(var.getnbval()):
sum_dat=sum_dat+ float(var.getvaleur(i)) if float(profondeur.getvaleur(i)) > (depth[k]-intervalle/2.0) and \
n_dat=n_dat+1 float(profondeur.getvaleur(i)) <= (depth[k]+intervalle/2.0) and \
float(var.getvaleur(i)) > -99 :
if n_dat == 0 : sum_dat=sum_dat+ float(var.getvaleur(i))
mean_dat.append(-99.0) n_dat=n_dat+1
else:
mean_dat.append(sum_dat/n_dat)
if n_dat == 0 :
mean_dat.append(-99.0)
else:
mean_dat.append(sum_dat/n_dat)
if(var_q.has_key(var)):
if mean_dat[k] == -99: if mean_dat[k] == -99:
qualite_dat.append(9) qualite_dat.append(9)
elif mean_dat[k] > -99: elif mean_dat[k] > -99:
qualite_dat.append(1) qualite_dat.append(1)
var.replaceallvaleurs(mean_dat) var.replaceallvaleurs(mean_dat)
if(var_q.has_key(var)):
qualite.replaceallvaleurs(qualite_dat) qualite.replaceallvaleurs(qualite_dat)
...@@ -391,31 +394,35 @@ if (CalculerMoyenne): ...@@ -391,31 +394,35 @@ if (CalculerMoyenne):
print "On traite:", var.getcode() print "On traite:", var.getcode()
if(var_q.has_key(var)): if(var_q.has_key(var)):
qualite = var_q.get(var) qualite = var_q.get(var)
mean_dat = []
qualite_dat = [] qualite_dat = []
for k in range(num_depth):
sum_dat=0
n_dat=0
for i in range(var.getnbval()):
if DEPTH.search(var.getcode()):
sum_dat=sum_dat+depth[k]
n_dat=n_dat+1
elif PRES.search(var.getcode()):
sum_dat=sum_dat+odf_fcns.depth2pres(depth[k],float(init_lat))
n_dat=n_dat+1
if n_dat == 0 :
mean_dat.append(-99.0)
else:
mean_dat.append(sum_dat/n_dat)
mean_dat = []
for k in range(num_depth):
sum_dat=0
n_dat=0
for i in range(var.getnbval()):
if DEPTH.search(var.getcode()):
sum_dat=sum_dat+depth[k]
n_dat=n_dat+1
elif PRES.search(var.getcode()):
sum_dat=sum_dat+odf_fcns.depth2pres(depth[k],float(init_lat))
n_dat=n_dat+1
if n_dat == 0 :
mean_dat.append(-99.0)
else:
mean_dat.append(sum_dat/n_dat)
if(var_q.has_key(var)):
if mean_dat[k] == -99: if mean_dat[k] == -99:
qualite_dat.append(9) qualite_dat.append(9)
elif mean_dat[k] > -99: elif mean_dat[k] > -99:
qualite_dat.append(1) qualite_dat.append(1)
var.replaceallvaleurs(mean_dat) var.replaceallvaleurs(mean_dat)
if(var_q.has_key(var)):
qualite.replaceallvaleurs(qualite_dat) qualite.replaceallvaleurs(qualite_dat)
...@@ -485,9 +492,11 @@ fout.write(chaine) ...@@ -485,9 +492,11 @@ fout.write(chaine)
for i in range(varlist[0].getnbval()): for i in range(varlist[0].getnbval()):
chaine ='' chaine =''
for var in varlist: for var in varlist:
print "var = ", var.getcode()
if CalculerMoyenne and QCFF.search(var.getcode()): if CalculerMoyenne and QCFF.search(var.getcode()):
pass pass
else: else:
print "i = ", i
chaine = chaine + var.getvaleur(i) + '\t' chaine = chaine + var.getvaleur(i) + '\t'
chaine = chaine + '\n' chaine = chaine + '\n'
fout.write(chaine) fout.write(chaine)
......
...@@ -56,10 +56,8 @@ def usage(): ...@@ -56,10 +56,8 @@ def usage():
print "ficout: fichier sortie (output file" print "ficout: fichier sortie (output file"
print "interval : intervale de profondeurs pour donnees moyennees" print "interval : intervale de profondeurs pour donnees moyennees"
print " (depth interval for mean data)" print " (depth interval for mean data)"
print "-a : toutes les donnees : ne pas moyenner" print "-d : eliminer donnees douteuses (discard data flaged as doubtfull)"
print " (all data : do not average)" print "-e : eliminer donnees erronnees (discard data flaged as erroneous)"
print "-d : conserver donnees douteuses (keep data flaged as doubtfull)"
print "-e : conserver donnees erronnees (keep data flaged as erroneous)"
from distutils.core import setup
auteur = "James Caveen"
nom="odf2csv"
ver="1.0"
modules = ["class_variable","odf_fcns"]
script = ["odf2csv.py"]
setup(name=nom,author=auteur,version=ver,py_modules = modules,scripts=script)
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment