Pierre-Antoine Bouttier
Séminaire iWorms / Décembre 2017 - Chamonix
wget --http-user="${HTTPUSER}" --http-password="${HTTPPASS}"
"http://ws.resif.fr/fdsnws/dataselect/1/queryauth?network=${net}&station=${sta}
&location=${loc}&channel=${chan}&starttime=${NTAGM1}T23:59:00.000000
&endtime=${NTAGP1}T00:01:00.000000" -O - |
python2.7 $PEXE $YEAR $JDAY $RAPATRIE_OPTION $net $sta $loc $chan
Utilisation de la librairie python memory_profiler (v0.47)
from memory_profiler import profile
fp = open('/home/user/iworms_refact/memory_profile.log','w+')
@profile(stream=fp)
def get_input():
# Read stream from input files from input stream from wget -O -
#s = read('tmp.mseed')
try:
s = read(StringIO.StringIO(sys.stdin.read()))
return s
except Exception as e:
print e
sys.exit(0) # cigri should not abort
Sortie memory_profile.log
Line # Mem usage Increment Line Contents
================================================
46 87.6 MiB 0.0 MiB @profile(stream=fp)
47 def get_input():
48 # Read stream from input files from input stream from wget -O -
49 #s = read('tmp.mseed')
50 87.6 MiB 0.0 MiB try:
51 #s = read(StringIO.StringIO(sys.stdin.read()))
52 172.5 MiB 84.9 MiB s = read("tmp.mseed")
53 172.5 MiB 0.0 MiB return s
54 except Exception as e:
55 print e
56 sys.exit(0) # cigri should not abort
Refactorisation obligatoire du script python
Text
bouttier@luke $ /usr/bin/time -f "%M" python2.7...
752556
# Serial code
import numpy as np
def traces_interpolation(traces):
"""
Performs interpolation of an unique trace
- Input : List of 1D arrays (each corresponding to a trace)
- output : List of 1D arrays (interpolated traces)
"""
interp_traces = []
for trace in traces:
interp_traces.append(np.interp(traces[i],...))
return interp_traces
# Parallel code
import numpy as np
from joblib import Parallel, delayed
def parallel_traces_interpolation(traces):
"""
Performs parallel interpolation of multiple traces
- Input : List of 1D arrays (each corresponding to a trace)
- output : List of 1D arrays (interpolated traces)
"""
n_traces = len(traces)
parallelizer = Parallel(n_jobs=n_traces)
# Iterator which returns the function to execute for each task
tasks_iterator = (delayed(np.interp)(trace,...) for trace in traces)
result = parallelizer(tasks_iterator)
return result