x******************************************************************************

x******************************************************************************** ******************************************************************************** **** **** **** **** **** **** **** **** **** SHELL & LANGAGES PROGRAMMATION **** **** shell octave gnuplot tex **** **** **** **** **** **** PROGRAMMES **** **** **** **** SYSTÈME **** **** **** **** DIVERS **** **** **** **** **** **** **** **** **** ******************************************************************************** ******************************************************************************** /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ SHELL & PROG /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONVERSIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____ imprimer au format booklet 1) pdfbook foo.pdf (paquet de texlive) 2) okular ~> long edges # _____ dos linus iconv -f latin1 -t utf8 fichier.txt find . -type f -exec chmod -x {} \; # _____ images for nom in *; do convert -resize 10\% $nom ../light/$nom ; done #___ la même en une ligne for nom in *; do convert -resize 10\% $nom ../light/$nom ; done # ___ STOP MOTION ffmpeg -f image2 -i image%04d.jpg video.mpg # entrée formattée ffmpeg -f image2 -i foo_9%06d.JPG -t 00:00:05 foo.mpg # durée du film ffmpeg -i video.wmv image%4d.jpg # ___ SON for f in *.flac; do flac -cd "$f" | lame -b 120 - "${f%.*}".120.mp3; done for i in *.ogg; do ogg123 -d wav -f - "$i" | lame -h - > ./"`echo "$i" | sed -e 's/.ogg$/.mp3/'`"; rm "$i"; done for nom in *.wav ; do oggenc $nom ; ffmpeg -i ${nom%wav}ogg ${nom%wav}mp3 ; done for nom in *wav ; do detox $nom ; done; for nom in *.wav ; do oggenc $nom ; ffmpeg -i ${nom%wav}ogg ${nom%wav}mp3 ; done # _____ PDFTK pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf pdftk A=1.pdf B=2.pdf C=3.pdf cat A2-12 B C output 123.pdf pdftk input.pdf cat 1-endsouth output output.pdf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ COMMANDES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____ CALCULATRICE $ bc puis scale=3 dans un script : echo "scale=2; operation arithémtique " | bc sinon $ bc -l # _____ RECHERCHER UNE CHAINE DE CARACTÈRES grep -nri "chaine de caractères" dossier # _____ PRÉFIXES SUFFIXES mv -n $name ${name%suffixe}suffixe2 mv -n $name prefixe2${name#prefixe} # _____ récupérer une extension (sur 3 caractères) echo ${nom: -3} # attention à respecter l'espace # _____ echo sans retour chariot echo -e "jkhkjsdh\c" cf routine_chronometre.sh # _____ UTILITAURE ROUTINES # ___ HORLOGE CPU echo $(date +%Y%m%d_%H:%M:%S) echo $(date +%Y%m%d_%H:%M:%S) date +%s%N ~> tps nanosecondes (max 3 siècles) date +%s%N | cut -b1-13 ~> récupérer 13 premiers caractères # ___ RÉCUPÉRER DATE CRÉATION FICHIER date -r foo.jpg '+%F-%l-%M-%S' date -r foo.jpg '+%s' # ___ incrémenter une variable $ i=$(($i+1)) # _____ AWK -F délimiteur -v variable Variable Description ARGC Nombre d'arguments de la ligne de commandes ARGV Tableau des arguments de la ligne de commandes CONVFMT Format de conversion des nombres en string (chaîne de caractères) ENVIRON Tableau associatif des variables d'environnement FILENAME Nom du fichier courant (et son chemin si précisé) FNR Numéro de l'enregistrement parcouru dans le fichier courant FS Séparateur de champs (par défaut les espaces, tabulations et retours-chariots contigus [ \t\n]+) NF Nombre de champs de l'enregistrement courant NR Numéro de l'enregistrement parcouru (tous fichiers confondus) OFMT Format de sortie des nombres OFS Séparateur de champs en sortie (un espace) ORS Séparateur d'enregistrement en sortie (une nouvelle ligne) RLENGTH Longueur du string trouvé par la fonction match() RS Séparateur d'enregistrement (une nouvelle ligne) RSTART Première position du string trouvé par la fonction match() SUBSEP Caractère de séparation pour les routines internes des tableaux (\034) # _____ syphonner un site oueb ! wget -r http://www.foo.org/ wget -r -l 1 -k http://foo.html -r récursif -l n niveau de récursion -k récursive link # _____ TRAITEMENT D'IMAGE AVEC CONVERT de IMAGEMAGICK convert -crop 10,20 30,40 entree.jpg sortie.jpg # convert -crop WxH+X+Y -resize 50\% input.jpg output.jpg #créer un roi avec mise à l'échelle convert -resize 1x2500! input.jpg output.jpg #changer le rapport d'aspect ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OCTAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____ ÉCRIRE DANS UN FICHIER FILE=fopen("profil_courbure.res","w"); for i=1:rows(C) fprintf(FILE,"%f\t%f\n",sC(i)/L,C(i)*L); endfor; fclose(FILE); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PYTHON ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____________________________________________MANIABILITÉ # _____ IMPORT import numpy as np import matplotlib.pyplot as plt # _____ PREAMUBULE %matplotlib inline np.set_printoptions(precision = 17) np.set_printoptions(formatter={'float': '{: 0.2f}'.format}) # _____ NUMÉRO DE VERSION print np.__version__ # _____ GESTION DES WARNINGS import warnings warnings.filterwarnings('ignore') warnings.filterwarnings(action='once') # _____ ON CHERCHE L'AIDE EN LIGNE DE COMMANDE In [5]: import sys In [6]: sys.path # _____ GESTION des PAQUETS (VERSION etc...) numéro de version >>> import paquet >>> print paquet.__version__ # pip install yolk # pip install --upgrade yolk3k $ yolk -V django # _____ METTRE PROGRAMME EN PAUSE raw_input() time.sleep(1) # _____ CHRONOMÉTRER import datetime TSTART=datetime.datetime.now() # _____ TRADUCTEUR PYTHON2 vs. PYTHON3 python2 python3 exécution execfile('foo.py') exec(open('foo.py').read()) # _____ SORTIE STANDARD FORMATTÉE print "%1.2f" % variable # _____________________________________________COMMANDES SYSTEM import os os.listdir(dossier) os.system('ls') # _____________________________________________ALGORITHMES # _____ FIT AJUSTEMENT from scipy.optimize import curve_fit def func(x, a, b, c): return a * np.exp(-b * x) + c xdata = np.linspace(0, 4, 50) y = func(xdata, 2.5, 1.3, 0.5) ydata = y + 0.5 * np.random.normal(size=len(xdata)) popt, pcov = curve_fit(func, xdata, ydata) #popt, pcov = curve_fit(func, xdata, ydata, bounds=(0, [3., 2., 1.])) print popt,"\n",pcov plt.figure() titre='foo' plt.title(titre) plt.plot(xdata,ydata,'-',color='blue') plt.plot(xdata,func(xdata,popt[0],popt[1],popt[2]),'-',color='red') # _____________________________________________LECTURE DATA # ______________________________ méthode n°1 def read_data(ficid): DATUM=[]e fic = open(ficid,"r") taille_fichier = len(fic.read().split("\n")) fic.close() fic = open(ficid,"r") for i in range (1 , taille_fichier ): datum = fic.readline().split() DATUM.append(datum) fic.close() DATUM=np.transpose(DATUM) DATUM=np.asfarray(DATUM) return DATUM # ______________________________ méthode n°2 : en une ligne DATUM=np.loadtxt('./data.dat',skiprows=0).T # _____________________________________________SAUVEGARDE DATA # ______________________________SAVE SAUVEGARDE ~~~~~~DATA SAVE=np.zeros((NbCOL,NbLIG)) np.savetxt('./foo.dat',np.transpose(SAVE),fmt='%d\t%f\t%f\t%f\t%f') # ______________________________SAVE SAUVEGARDE ~~~~~~FIGURE plt.figure(1) plt.savefig('foobar.pdf') ,bbox_inches = 'tight') # ______________________________SAVE SAUVEGARDE ~~~~~~IMAGE nomsortie=dossier_sortie+'pref'+str(900000+k)+'.jpg' imsave(nomsortie,image/255.) #de la librairie SKIMAGE a priori # ______________________________BO GRAPH PDF # _____ Create a figure of size 8x6 inches, 80 dots per inch plt.figure(figsize=(4, 4), dpi=80) plt.subplot(1, 1, 1) plt.plot(x,f) # _____ M2thode alternative qui joue sur le bounding box plt.figure(33,figsize=(5,4)) plt.xticks(fontsize=15) plt.yticks(fontsize=15) plt.xlabel('$z$ (mm)', fontsize=20) plt.ylabel('$x$ (mm)', fontsize=20) plt.savefig('./foo.pdf',bbox_inches = 'tight') # _____________________________________________GRAPHIQUES # _______________ SYMBOLES ms=2 markersize mew markeredgewidth mec markeredgocolor # type de symbol 1, 2, 3, 4 étoile à trois branche pas mal p pentagone cercles : plt.scatter(DATA[:,0],DATA[:,1],facecolors='none', edgecolors='r') # _______________ AXES plt.ylim([800,2000]) plt.axhline(y=0, color='black', linestyle='-') plt.axvline(x=0, color='black', linestyle='-') # _______________ rapport d'aspect plt.axes().set_aspect('equal') # _______________ GRAPH SUR DEUX AXES # _______________ peut-on éviter le subplot? fig, axe = plt.subplots(figsize=(4, 3)) axe.set_ylabel('P', color='black') axe.plot(P,color='b') axeTWIN = axe.twinx() axeTWIN.set_ylabel('p', color='r') axeTWIN.tick_params('y', colors='r') axeTWIN.plot(p,color='r') # _______________ PLOT INTERACTIF import matplotlib.pyplot as plt plt.ion() plt.draw() # _______________ FAISCEAU DE COURBES # _______________ liste jet, rainbow # _______________ ocean vert->bleu # _______________ perceptually uniform : viridis, plasma import numpy as np import matplotlib.pyplot as plt #from matplotlib.pyplot import cm n=50 x=np.linspace(0,1,100) y=x lesCoeff=np.linspace(-1,1,n) lesCouleurs=plt.cm.rainbow(np.linspace(0,1,n)) lesCouleurs=plt.cm.ocean(np.linspace(0,1,n)) plt.figure() for i in range(len(lesCoeff)): plt.plot(x,x+lesCoeff[i],color=lesCouleurs[i],linewidth=6) plt.ylim([0,1]) plt.show() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RACCOURCIS JUPYTER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alt+enter exécute insère en dessous suite cf. ~/RACCOURCIS_JUPYTER.png ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LATEX ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____ CONVERTIR LES ANCIENNES FIGURES EPS EN PDF ~> UTILISER PDFLATEX suite à un soucis d'exporter de ODG: pdf: pas d'export de la sélection eps: export de la sélection mais soucis de bounding box...pour epstopdf il faut recréer une bounding (epstool) avant de convertir en pdf (epstopdf) #shell fic=$1 epstool --copy --bbox $fic --output foo.eps epstopdf foo.eps -o ${fic%.eps}.pdf rm foo.eps routine écrite dans le /home/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GNUPLOT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # _____ CREER UN PNG RAPIDO AVEC GNUPLOT set terminal png large #taille de la police set output './gnuplot.png' set size 1.0,1.0 set key box lt 1 lc -2 lw 3 set border linewidth 2 replot set term wxt set terminal jpeg large #taille de la police set output './gnuplot.jpg' set key box lt 1 lc -2 lw 3 set border linewidth 2 replot set term wxt # _____ CONDITIONNAL PLOTTING plot 'foo.dat' 1:($3==0?$2:1/0) # _____ TERMINAL set term postscript eps enhanced color font "Helvetica,30" lw 1.5 # _____ AJUSTEMENT f(x)=a+b*x fit f(x) 'datafile' via a,b set label GPFUN_f at graph .05,.95 set label sprintf("a = %g", a) at graph .05,.90 set label sprintf("b = %g", b) at graph .05,.85 # _____ AXES et TICS set format y "%g" set xtics <start>, <increment>, <end> set mxtics 5 # _____ AXES DATE (série temporelle) #!/gnuplot ----- attention %y!=%Y set timefmt '%d/%m/%Y' set xdata time set format x '%m/%y' # _____ KEYS set key reverse left Left option: above horizontal maxrows n spacing n (vertical) font "<name>,<size>" # _____ COMMANDES SUR PLUSIEURS LIGNES plot ’superposition.dat’ index 4 w l,\ ’superposition_1.dat’ index 9 w l,\ 8*cos(5*x)**2 w p pt 5 # l’anti-slash indique que la commande pause -1 # continue `a la ligne suivante # _____ POLICE set termoption enhance {/Symbol m} # _____ STYLES DE TRAÇAGE test ~> imprime toutes les car du terminal t: type s: size w: width lc: color pour les points et les lignes lc 7 lc rgb 'black' pt point type ps point size lt line type ls line size # _____ MONTRER LES OPTIONS DU TERMINAL test # _____ COULEURS exemple : lc '#fff...' This file is generated by Gnuplot 4.2 List of known color names: white #ffffff = 255 255 255 black #000000 = 0 0 0 gray0 #000000 = 0 0 0 grey0 #000000 = 0 0 0 gray10 #1a1a1a = 26 26 26 grey10 #1a1a1a = 26 26 26 gray20 #333333 = 51 51 51 grey20 #333333 = 51 51 51 gray30 #4d4d4d = 77 77 77 grey30 uploads/Litterature/ notes-commandes.pdf

  • 10
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager