Skip to content
Snippets Groups Projects
Commit e613f4b5 authored by jacques Grelet's avatar jacques Grelet
Browse files

Merge branch 'master' of /m/git/pirata

parents f44d5847 6e921369
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,31 @@ L[:-1]
[1, 2, 3]
L[::-1]
[4, 3, 2, 1]
L.method() avec method = append, sort,index,reverse
L.method() avec method = append, sort,index,reverse, extend
We see that extend() is semantically clearer, and that it can run much faster than append(),
when you intend to append each element in an iterable to a list.
If you only have a single element (not in an iterable) to add to the list, use append.
The following two snippets are semantically equivalent:
for item in iterator:
a_list.append(item)
and
a_list.extend(iterator)
The latter may be faster as the loop is implemented in C.
List comprehensions:
------------------------------------------
new_list = [expression for_loop_one_or_more condtions]
numbers = [1, 2, 3, 4]
squares = [n**2 for n in numbers]
print(squares) # Output: [1, 4, 9, 16]
list_a = [1, 2, 3]
square_cube_list = [ [a**2, a**3] for a in list_a]
print(square_cube_list) # Output: [[1, 1], [4, 8], [9, 27]]
Tuples:
-------
......@@ -527,6 +551,9 @@ Successfully installed basemap-1.1.0 pyproj-2.1.2 pyshp-2.1.0
Pour utiliser QT au lieu de Tk
> pip install PySimpleGUIQt
> pip install PySide2
> pip install PyAstronomy
> pip install sciPy
> pip install basemap
Puis remplacer le :
import PySimpleGUI as gs
......@@ -589,4 +616,4 @@ From https://github.com/jgrelet/oceano2python
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
\ No newline at end of file
create mode 100644 README.md
import netCDF4 as nc
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as dplt
from pylab import *
import os, sys
mask =
Dataset('/ccc/scratch/cont005/legos/nivertfl/VALIDATION_F01/INPUT_SAISON/HOFF-MULLER/total.nc',
mode='r')
trop =
Dataset('/ccc/scratch/cont005/legos/nivertfl/VALIDATION_F01/INPUT_SAISON/HOFF-MULLER/sst_tropflux_1d_2000-regrid.nc',
mode='r')
mask1 = mask.variables['votemper'][:,0,:,:]
trop1 = trop.variables['sst'][:,:,:]
zbla=np.zeros(shape=(301,1))
zblo=np.zeros(shape=(301,1))
zbla2=np.zeros(shape=(301,366))
zblo2=np.zeros(shape=(301,366))
time = mask.variables['time_counter'][:]
lon = mask.variables['nav_lon'][0,:]
mask1[mask1 == 0] = np.NaN
for y in range(0,365):
for x in range(0,300):
result1= np.nanmean(mask1[y,78:86,x])
zbla[x,:]=result1
zbla3=np.squeeze(zbla)
zbla2[:,y]=zbla3
zbla2=transpose(zbla2)
for y in range(0,365):
for x in range(0,300):
result2= np.nanmean(trop1[y,78:86,x])
zblo[x,:]=result2
zblo3=np.squeeze(zblo)
zblo2[:,y]=zblo3
zblo2=transpose(zblo2)
plt.clf()
units=mask.variables['time_counter'].units
from datetime import datetime
buf=mask.variables['time_centered'][:];
time=list()
time.extend(buf.tolist())
dates=nc.num2date(time,units,'gregorian').tolist()
nt=len(dates)
im1 = plt.figure(figsize=(6, 18))
im1 = plt.contourf(lon,dates,zbla2, np.linspace(23,30,21),
extend='both', cmap=cm.RdBu_r)
plt.colorbar(im1,orientation='horizontal')
im1 = plt.title("Modele annee 2000")
plt.savefig('modele2000.png')
plt.clf()
im2 = plt.figure(figsize=(6, 18))
im2 = plt.contourf(lon,dates,zblo2, np.linspace(23,30,21),
extend='both', cmap=cm.RdBu_r)
plt.colorbar(im2,orientation='horizontal')
im2 = plt.title("TropFlux annee 2000")
plt.savefig('obs2000.png')
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
file1 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/grid_T_saison.nc'
file2 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/grid_U_saison.nc'
file3 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/grid_V_saison.nc'
file4 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/MYWRF3D_regrid-saison.nc'
trop1 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/sst_tropflux_1d_2000-regrid-saison.nc'
trop2 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/taux_tropflux_1d_2000-regrid-saison.nc'
trop3 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/tauy_tropflux_1d_2000-regrid-saison.nc'
trop4 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/swr_tropflux_1d_2000-regrid-saison.nc'
trop5 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/lwr_tropflux_1d_2000-regrid-saison.nc'
pluie1 =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/precip-2000-regrid-saison.nc'
meshmask =
'/ccc/scratch/cont005/legos/nivertfl/TEST_VALIDATION_TROPFLUX/MOYENNE-SAISON/mesh_mask.nc'
mask = Dataset(file1, mode='r')
masku = Dataset(file2, mode='r')
maskv = Dataset(file3, mode='r')
wrf = Dataset(file4, mode='r')
pluie = Dataset(pluie1, mode='r')
meshmask1 = Dataset(meshmask, mode='r')
tropsst= Dataset(trop1, mode='r')
troptaux= Dataset(trop2, mode='r')
troptauy= Dataset(trop3, mode='r')
tropswr= Dataset(trop4, mode='r')
troplwr= Dataset(trop5, mode='r')
lat = mask.variables['nav_lat'][:]
lon = mask.variables['nav_lon'][:]
lat1 = mask.variables['nav_lat'][:,0]
meshmask2 = meshmask1.variables['tmask'][:,0,:,:]
mask1 = mask.variables['votemper'][:,0,:,:]
mask11 = tropsst.variables['sst'][:,:,:]
vari2 = mask.variables['qsr'][:,:,:]
vari22 = tropswr.variables['swr'][:,:,:]
vari31 = wrf.variables['RAIN'][:,:,:]
vari3 = vari31[:,:,:] * 40 * 24
vari33 = pluie.variables['precipitation'][:,:,:]
vari4 = masku.variables['utau'][:,:,:]
vari44 = troptaux.variables['taux'][:,:,:]
vari51 = wrf.variables['GLW'][:,:,:]
vari5 = vari51[:,:,:] * meshmask2[:,:,:]
vari555 = troplwr.variables['lwr'][:,:,:]
mask112 = mask11[:,:,:] + 273.15
vari55 = vari555[:,:,:] +
5.67e-8*(mask112[:,:,:])*(mask112[:,:,:])*(mask112[:,:,:])*(mask112[:,:,:])
vari6 = maskv.variables['vtau'][:,:,:]
vari6[vari6 == 0] = np.NaN
vari66 = troptauy.variables['tauy'][:,:,:]
list1 = ['JFM' , 'AMJ' , 'JAS' , 'OND']
'''Difference modele'''
for x in range(0,4):
print "We're on time %d" % (x)
plt.clf()
result1 = mask1[x,:,:] - mask11[x,:,:]
result2 = vari2[x,:,:] - vari22[x,:,:]
result3 = vari3[x,:,:] - vari33[x,:,:]
result4 = vari4[x,:,:] - vari44[x,:,:]
result5 = vari5[x,:,:] - vari55[x,:,:]
result6 = vari6[x,:,:] - vari66[x,:,:]
fig, cs = plt.subplots(3, 2, figsize=(9, 6))
fig.subplots_adjust(left=0.125, bottom=0.1, right=0.9, top=0.9,
wspace=0.3, hspace=0.3)
im1 = cs[0, 0].contourf(lon,lat,result1, np.linspace(-2.5,2.5,21),
extend='both', cmap=cm.RdBu_r)
cs[0, 0].set_title('Difference VOTEMPER MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im1, ax=cs[0, 0], orientation='horizontal')
im2 = cs[0, 1].contourf(lon,lat,result2, np.linspace(-100,100,21),
extend='both', cmap=cm.RdBu_r)
cs[0, 1].set_title('Difference QSR MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im2, ax=cs[0, 1], orientation='horizontal')
im3 = cs[1, 0].contourf(lon,lat,result3, np.linspace(-16,16,21),
extend='both', cmap=cm.RdBu_r)
cs[1, 0].set_title('Difference PRECIP MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im3, ax=cs[1, 0], orientation='horizontal')
im4 = cs[1, 1].contourf(lon,lat,result4, np.linspace(-0.1,0.1,21),
extend='both', cmap=cm.RdBu_r)
cs[1, 1].set_title('Difference U TAU MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im4, ax=cs[1, 1], orientation='horizontal', format='%.0e')
im5 = cs[2, 0].contourf(lon,lat,result5, np.linspace(-50,50,21),
extend='both', cmap=cm.RdBu_r)
cs[2, 0].set_title('Difference LW MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im5, ax=cs[2, 0], orientation='horizontal')
im6 = cs[2, 1].contourf(lon,lat,result6, np.linspace(-0.1,0.1,21),
extend='both', cmap=cm.RdBu_r)
cs[2, 1].set_title('Difference V TAU MODELE - OBS Saison ' +
list1[x],fontsize=10)
fig.colorbar(im6, ax=cs[2, 1], orientation='horizontal')
plt.savefig('all_var_diff_saison_' + list1[x] + '.png')
'''plot modele'''
for x in range(0,4):
print "We're on time %d" % (x)
plt.clf()
result1 = mask1[x,:,:]
result2 = vari2[x,:,:]
result3 = vari3[x,:,:]
result4 = vari4[x,:,:]
result5 = vari5[x,:,:]
result6 = vari6[x,:,:]
fig, cs = plt.subplots(3, 2, figsize=(9, 6))
fig.subplots_adjust(left=0.125, bottom=0.1, right=0.9, top=0.9,
wspace=0.3, hspace=0.3)
im1 = cs[0, 0].contourf(lon,lat,result1, np.linspace(20,30,21),
extend='both', cmap=cm.jet)
cs[0, 0].set_title('VOTEMPER MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im1, ax=cs[0, 0], orientation='horizontal')
im2 = cs[0, 1].contourf(lon,lat,result2, np.linspace(100,380,15),
extend='both', cmap=cm.jet)
cs[0, 1].set_title('QSR MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im2, ax=cs[0, 1], orientation='horizontal')
im3 = cs[1, 0].contourf(lon,lat,result3, np.linspace(0,20,21),
extend='both', cmap=cm.jet)
cs[1, 0].set_title('PRECIP MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im3, ax=cs[1, 0], orientation='horizontal')
im4 = cs[1, 1].contourf(lon,lat,result4,
np.linspace(-0.13,0.05,21), extend='both', cmap=cm.jet)
cs[1, 1].set_title('U TAU MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im4, ax=cs[1, 1], orientation='horizontal', format='%.0e')
im5 = cs[2, 0].contourf(lon,lat,result5, np.linspace(300,460,21),
extend='both', cmap=cm.jet)
cs[2, 0].set_title('GLW MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im5, ax=cs[2, 0], orientation='horizontal')
im6 = cs[2, 1].contourf(lon,lat,result6,
np.linspace(-0.15,0.13,21), extend='both', cmap=cm.jet)
cs[2, 1].set_title('V TAU MODELE Saison ' + list1[x],fontsize=10)
fig.colorbar(im6, ax=cs[2, 1], orientation='horizontal')
plt.savefig('all_var_modele_saison_' + list1[x] + '.png')
'''plot obs Trop et TRMM'''
for x in range(0,4):
print "We're on time %d" % (x)
plt.clf()
result1 = mask11[x,:,:]
result2 = vari22[x,:,:]
result3 = vari33[x,:,:]
result4 = vari44[x,:,:]
result5 = vari55[x,:,:]
result6 = vari66[x,:,:]
fig, cs = plt.subplots(3, 2, figsize=(9, 6))
fig.subplots_adjust(left=0.125, bottom=0.1, right=0.9, top=0.9,
wspace=0.3, hspace=0.3)
im1 = cs[0, 0].contourf(lon,lat,result1, np.linspace(20,30,21),
extend='both', cmap=cm.jet)
cs[0, 0].set_title('VOTEMPER OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im1, ax=cs[0, 0], orientation='horizontal')
im2 = cs[0, 1].contourf(lon,lat,result2, np.linspace(100,380,15),
extend='both', cmap=cm.jet)
cs[0, 1].set_title('QSR OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im2, ax=cs[0, 1], orientation='horizontal')
im3 = cs[1, 0].contourf(lon,lat,result3, np.linspace(0,20,21),
extend='both', cmap=cm.jet)
cs[1, 0].set_title('PRECIP OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im3, ax=cs[1, 0], orientation='horizontal')
im4 = cs[1, 1].contourf(lon,lat,result4,
np.linspace(-0.13,0.05,21), extend='both', cmap=cm.jet)
cs[1, 1].set_title('U TAU OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im4, ax=cs[1, 1], orientation='horizontal', format='%.0e')
im5 = cs[2, 0].contourf(lon,lat,result5, np.linspace(300,460,21),
extend='both', cmap=cm.jet)
cs[2, 0].set_title('LW OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im5, ax=cs[2, 0], orientation='horizontal')
im6 = cs[2, 1].contourf(lon,lat,result6,
np.linspace(-0.15,0.13,21), extend='both', cmap=cm.jet)
cs[2, 1].set_title('V TAU OBS Saison ' + list1[x],fontsize=10)
fig.colorbar(im6, ax=cs[2, 1], orientation='horizontal')
plt.savefig('all_var_obs_saison_' + list1[x] + '.png')
zbla=np.zeros(shape=(165,1))
zbla2=np.zeros(shape=(165,1))
zbla3=np.zeros(shape=(165,1))
zbla4=np.zeros(shape=(165,1))
zbla5=np.zeros(shape=(165,1))
zbla6=np.zeros(shape=(165,1))
zbla7=np.zeros(shape=(165,1))
zbla8=np.zeros(shape=(165,1))
zbla9=np.zeros(shape=(165,1))
zbla10=np.zeros(shape=(165,1))
zbla11=np.zeros(shape=(165,1))
zbla12=np.zeros(shape=(165,1))
mask1[mask1 == 0] = np.NaN
vari2[vari2 == 0] = np.NaN
vari4[vari4 == 0] = np.NaN
vari5[vari5 == 0] = np.NaN
'''Coupe zonale'''
for y in range(0,4):
print "We're on time %d" % (y)
for x in range(0,165):
result1= np.nanmean(mask1[y,x,80:160])
result2= np.nanmean(mask11[y,x,80:160])
zbla[x,:]=result1
zbla2[x,:]=result2
for z in range(0,165):
result3= np.nanmean(vari2[y,z,80:160])
result4= np.nanmean(vari22[y,z,80:160])
zbla3[z,:]=result3
zbla4[z,:]=result4
for ii in range(0,165):
result5= np.nanmean(vari3[y,ii,80:160])
result6= np.nanmean(vari33[y,ii,80:160])
zbla5[ii,:]=result5
zbla6[ii,:]=result6
for jj in range(0,165):
result7= np.nanmean(vari4[y,jj,80:160])
result8= np.nanmean(vari44[y,jj,80:160])
zbla7[jj,:]=result7
zbla8[jj,:]=result8
for zz in range(0,165):
result9= np.nanmean(vari5[y,zz,80:160])
result10= np.nanmean(vari55[y,zz,80:160])
zbla9[zz,:]=result9
zbla10[zz,:]=result10
for hh in range(0,165):
result11= np.nanmean(vari6[y,hh,80:160])
result12= np.nanmean(vari66[y,hh,80:160])
zbla11[hh,:]=result11
zbla12[hh,:]=result12
fig, cs = plt.subplots(3, 2, figsize=(9, 6))
fig.subplots_adjust(left=0.125, bottom=0.1, right=0.9, top=0.9,
wspace=0.3, hspace=0.3)
im1 = cs[0, 0].plot(lat1,zbla)
im1 = cs[0, 0].plot(lat1,zbla2)
cs[0, 0].set_title('Comparaison SST MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[0, 0].set_ylim([18,30])
cs[0, 0].set_xlim([-20,20])
im2 = cs[0, 1].plot(lat1,zbla3)
im2 = cs[0, 1].plot(lat1,zbla4)
cs[0, 1].set_title('Comparaison QSR MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[0, 1].set_ylim([100,380])
cs[0, 1].set_xlim([-20,20])
im3 = cs[1, 0].plot(lat1,zbla5)
im3 = cs[1, 0].plot(lat1,zbla6)
cs[1, 0].set_title('Comparaison PRECIP MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[1, 0].set_ylim([0, 20])
cs[1, 0].set_xlim([-20,20])
im4 = cs[1, 1].plot(lat1,zbla7)
im4 = cs[1, 1].plot(lat1,zbla8)
cs[1, 1].set_title('Comparaison U TAU MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[1, 1].set_ylim([-0.13,0.05])
cs[1, 1].set_xlim([-20,20])
im5 = cs[2, 0].plot(lat1,zbla9)
im5 = cs[2, 0].plot(lat1,zbla10)
cs[2, 0].set_title('Comparaison LW MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[2, 0].set_ylim([300,430])
cs[2, 0].set_xlim([-20,20])
im6 = cs[2, 1].plot(lat1,zbla11)
im6 = cs[2, 1].plot(lat1,zbla12)
cs[2, 1].set_title('Comparaison V TAU MODELE et OBS Saison ' +
list1[y],fontsize=10)
cs[2, 1].set_ylim([-0.15,0.13])
cs[2, 1].set_xlim([-20,20])
plt.savefig('coupe_zonale_saison_' + list1[y] + '.png')
import argparse
import sys
import myPySimpleGUI as sg
# import PySimpleGUIQt as sg
# import myPySimpleGUI as sg
import PySimpleGUI as sg
import toml
import logging
from file_extractor import FileExtractor
......@@ -14,6 +14,8 @@ import distutils.util as du
typeInstrument = {'CTD': ('cnv', 'CNV'), 'XBT': (
'EDF', 'edf'), 'LADCP': ('lad', 'LAD'), 'TSG': 'COLCOR'}
ti = typeInstrument # an alias
filesBrowsePosition_row = 2
filesBrowsePosition_column = 1
def processArgs():
......@@ -22,45 +24,62 @@ def processArgs():
following ROSCOP codification at the given column, fill arrays, write header file ',
usage='\npython oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -d\n'
'python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -k PRES TEMP PSAL DOX2 DENS\n'
'python oceano.py data/CTDcnv/dfr29*.cnv -d\n'
'python oceano.py data/CTDcnv/dfr29*.cnv -i CTD -d\n'
'python oceano.py data/XBT/T7_0000*.EDF -i XBT -k DEPTH TEMP SVEL\n'
"python oceano.py data/LADCP/*.lad -i LADCP -k DEPTH EWCT NSCT",
'python oceano.py data/LADCP/*.lad - i LADCP - k DEPTH EWCT NSCT\n'
' \n',
epilog='J. Grelet IRD US191 - March 2019')
parser.add_argument('-d', '--debug', help='display debug informations',
action='store_true')
parser.add_argument('--demo', nargs='?', default='CTD',
help='specify the commande line for instrument, eg CTD, XBT, TSG, LADCP (default: %(default)s)')
parser.add_argument('--demo', nargs='?', choices=ti.keys(),
help='specify the commande line for instrument, eg CTD, XBT, TSG, LADCP')
parser.add_argument('-c', '--config', help="toml configuration file, (default: %(default)s)",
default='tests/test.toml')
parser.add_argument('-i', '--instrument', nargs='?', default='CTD',
help='specify the instrument that produce files, eg CTD, XBT, TSG, LADCP (default: %(default)s)')
parser.add_argument('-i', '--instrument', nargs='?', choices=ti.keys(),
help='specify the instrument that produce files, eg CTD, XBT, TSG, LADCP')
parser.add_argument('-k', '--key', nargs='+', default=['PRES', 'TEMP', 'PSAL'],
help='display dictionary for key(s), (default: %(default)s)')
parser.add_argument('-g', '--gui', action='store_true',
help='use GUI interface')
parser.add_argument('files', nargs='*',
help='cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)')
parser.add_argument('files', nargs='*', type=argparse.FileType('r', encoding='ISO-8859-1'),
help='ASCII file(s) to parse')
return parser
# TODOS:
# DEPTH is missing
# file name is not clear at startup
# if no file selected, don't leave the program
def defineGUI():
# get all devices
devices = list(ti.keys())
# change look and feel color scheme
sg.ChangeLookAndFeel('SandyBeach')
frameLayout = {}
# define a frame layout for each instrument (device)
for d in devices:
keys = cfg['split'][d.lower()].keys()
# List comprehensions
frameLayout[d] = [[sg.Checkbox(k, key=k,
tooltip='Select the extract the physical parameter {}'.format(k))] for k in keys]
# define GUI layout
layout = ([[sg.Text('File(s) to read and convert')],
[sg.Multiline(size=(40, 5), key='_IN_'),
sg.Input(key='_HIDDEN_', visible=False,
layout = ([[sg.Text('File(s) to read and convert')], # row 0
[sg.Multiline(size=(40, 5), key='_IN_'), # row 1, col 0
sg.Input(key='_HIDDEN_', visible=False, # row 1, col 1
enable_events=True),
sg.FilesBrowse(key='_HIDDEN_',
tooltip='Choose one or more files',
initial_folder='data/{}'.format(ti[device][0]))],
[sg.Combo(list(ti.keys()), enable_events=True, size=(8, 1),
sg.FilesBrowse(key='_HIDDEN_', initial_folder=None, # row 1, col 2
tooltip='Choose one or more files')],
[sg.Combo(list(ti.keys()), enable_events=True, size=(8, 1), # row 2
key='_COMBO_', tooltip='Select the instrument')],
* [[sg.Checkbox(k, key=k,
tooltip='Select the extract the physical parameter {}'.format(k))] for k in keys],
[sg.OK(), sg.CloseButton('Cancel')]])
# [sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
[sg.Frame(d, frameLayout[d], key='_FRAME_{:s}'.format(d) , visible=True) # row 3
for d in devices],
[sg.OK(), sg.CloseButton('Cancel')]]) # row 4
# [sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
# create a local instance windows used to reload the saved config from file
window = sg.Window('Oceano converter').Layout(layout)
......@@ -69,11 +88,16 @@ def defineGUI():
return window
def updateFilesBrowseCombo(extentions):
e = window.Rows[1][2] # hardcoded
e.FileTypes = [] # init to empty list
def updateFilesBrowseCombo(extentions, x, y):
'''# special function used to update the FilesBrowseCombo with canvas poisition
# instead of key because the same key is assign to shadow input object
'''
e = window.Rows[x][y] # hardcoded
e.FileTypes = [] # init to empty list
for ext in extentions:
e.FileTypes.append(("{} files".format(ext), "*.{}".format(ext)))
e.initial_folder = 'data/{}'.format(extentions[0])
window.Finalize
......@@ -131,8 +155,8 @@ if __name__ == "__main__":
# read config Toml file and get the physical parameter list (Roscop code) for the specified instrument
cfg = toml.load(args.config)
# this the select device from command line !
device = str(args.instrument) # convert one element list to str
keys = cfg['split'][device.lower()].keys()
# test arguements from sys.argv, args is never to None with default option set
if args.gui or len(sys.argv) == 1:
......@@ -140,24 +164,48 @@ if __name__ == "__main__":
# setup the GUI windows Layout
window = defineGUI()
device = window.FindElement('_COMBO_').DefaultValue
updateFilesBrowseCombo(ti[device])
keys = cfg['split'][device.lower()].keys()
# can't update combo with FindElement('_HIDDEN_').Update(), we use this function
# with hardcoded FilesBrowseCombo position
updateFilesBrowseCombo(
ti[device], filesBrowsePosition_column, filesBrowsePosition_row)
# set the rigth frame for device visible, dosn't work
# File "C:\git\python\PySimpleGUI\PySimpleGUI.py", line 2362, in Update
# self.TKFrame.pack()
# AttributeError: 'NoneType' object has no attribute 'pack'
# for d in list(ti.keys()):
# print(d)
# if d == device:
# window.FindElement(
# '_FRAME_{:s}'.format(d)).Update(visible=True)
# main GUI loop
while True:
# display the main windows
event, values = window.Read()
# print(event, values)
print(event, values)
if event is 'Cancel' or event == None:
raise SystemExit("Cancelling: user exit")
if event is 'OK': # end of initialization, process data now
# values['_HIDDEN_'] is a string with files separated by ';' and fileExtractor need a list
files = values['_HIDDEN_'].split(';')
args.files = files
# test if a or more file are selected
if not all(args.files):
sg.Popup("Cancel", "No filename supplied")
# raise SystemExit("Cancelling: no filename supplied")
continue
break
if event is '_COMBO_':
# you have to go into the bowels of the pygi code, to get the instance of the Combo
# by the line and column number of the window to update its "fileType" property.
updateFilesBrowseCombo(ti[values['_COMBO_']])
updateFilesBrowseCombo(
ti[values['_COMBO_']], filesBrowsePosition_column, filesBrowsePosition_row)
# update the Multilines instance from FilesBrowse return
if event is '_HIDDEN_':
......@@ -177,15 +225,6 @@ if __name__ == "__main__":
del new_values[k]
args.key = new_values.keys()
# values['_HIDDEN_'] is a string with files separated by ';' and fileExtractor need a list
files = values['_HIDDEN_'].split(';')
args.files = files
# test if a or more file are selected
if not all(args.files):
sg.Popup("Cancel", "No filename supplied")
raise SystemExit("Cancelling: no filename supplied")
# process of files start here
fe, n, m = process(args, cfg, values['_COMBO_'])
......@@ -200,11 +239,29 @@ if __name__ == "__main__":
# print = sg.Print(size=(80,40))
else:
# demo mode, only in command line
if args.demo != None:
print('demo mode: {}'.format(args.demo))
sys.exit(1)
# test if a or more file are selected
if args.files == []:
print('You need to specify one or more files to process !!!', end='\n\n')
else:
if args.files == []:
print(
'Error, you need to specify one or more files to process !!!', end='\n\n')
parser.print_help(sys.stderr)
sys.exit(1)
else:
files = []
for f in args.files:
files.append(f.name)
args.files = files
if device == 'None':
print(
'Error: missing option -i or --instrument, instrument = {}\n'.format(device))
parser.print_help(sys.stderr)
sys.exit(1)
keys = cfg['split'][device.lower()].keys()
# in command line mode (console)
fe, n, m = process(args, cfg, device)
print("Dimensions: {} x {}".format(m, n))
......
......@@ -158,4 +158,10 @@ comment = "Extract from .lad files"
[split.ladcp]
DEPTH = 0
EWCT = 1
NSCT = 2
\ No newline at end of file
NSCT = 2
[split.tsg]
DEPTH = 0
SSJT = 1
SSTP = 2
SSPS = 3
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment