-
Notifications
You must be signed in to change notification settings - Fork 0
/
S_PlotNFit.py
137 lines (118 loc) · 3.83 KB
/
S_PlotNFit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 17 14:28:53 2019
@author: Vall
"""
import iv_analysis_module as iva
import iv_plot_module as ivp
import iv_save_module as ivs
import iv_utilities_module as ivu
import numpy as np
#%% PARAMETERS -------------------------------------------------------------------
# Parameters
name = 'M_20191129_01'
home = r'C:\Users\Valeria\OneDrive\Labo 6 y 7'
# Save parameters
autosave = True
overwrite = True
# Plot parameters
plot_params = dict(
plot = False,
interactive = True,
autoclose = True,
extension = '.png'
)
plot_params = ivu.InstancesDict(plot_params)
# Fit parameters
fit_params = dict(
use_full_mean = True,
use_experiments = [1], # First is 0, not 1!
send_tail_to_zero = True,
tail_method = 'mean', # Could also be 'min' or 'max' or any numpy function
use_fraction = .1,
choose_t0 = True,
choose_tf = False,
svalues = None,
max_svalues = 20,
)
fit_params = ivu.InstancesDict(fit_params)
# Create full filename
filename = ivs.filenameToMeasureFilename(name, home=home)
#%% PLOT --------------------------------------------------------------------------
# Plot
if plot_params.plot:
fig, legb, savb = ivp.plotPumpProbe(filename,
interactive=plot_params.interactive,
extension=plot_params.extension,
autosave=False,
overwrite=True,
# loc='upper right'
)
if False: print(
""" TO PLOT SEVERAL MEASUREMENTS
import os
path = os.path.split(filename)[0]
ivp.plotAllPumpProbe(path,
autoclose=plot_params.autoclose,
extension=plot_params.extension,
autosave=autosave,
overwrite=True)
"""
)
#%% LINEAR PREDICTION -------------------------------------------------------------
# Load data
t, V, details = ivs.loadNicePumpProbe(filename)
# Choose time interval to fit
if fit_params.choose_t0: # Choose initial time t0
t0 = ivp.interactiveTimeSelector(filename, autoclose=plot_params.autoclose)
t, V = iva.cropData(t0, t, V)
else:
try:
t, V = iva.cropData(t0, t, V)
except NameError:
t0 = t[0]
if fit_params.choose_tf: # Choose final time tf
tf = ivp.interactiveTimeSelector(filename, autoclose=plot_params.autoclose)
t, V = iva.cropData(tf, t, V, logic='<=')
else:
try:
t, V = iva.cropData(tf, t, V, logic='<=')
except NameError:
tf = t[-1]
fit_params.time_range = (t0, tf)
del t0, tf
# Choose data to fit
if fit_params.use_full_mean:
data = np.mean(V, axis=1)
else:
data = np.mean(V[:, fit_params.use_experiments], axis=1)
# Make a vertical shift
if fit_params.send_tail_to_zero:
function = eval('np.{}'.format(fit_params.tail_method))
V0 = function(data[int( (1-fit_params.use_fraction) * len(data)):])
del function
else:
try:
V0
except NameError:
V0 = 0
data = data - V0
fit_params.voltage_zero = V0
del V0
# Use linear prediction
results, other_results, plot_results = iva.linearPrediction(
t, data, details['dt'],
svalues=fit_params.svalues,
max_svalues=fit_params.max_svalues,
autoclose=plot_params.autoclose)
if autosave:
ivs.linearPredictionSave(filename, results, other_results, fit_params,
overwrite=overwrite)
# Plot linear prediction
ivp.linearPredictionPlot(filename, plot_results,
autosave=autosave,
extension=plot_params.extension,
overwrite=overwrite)
# Generate fit tables
tables = iva.linearPredictionTables(fit_params, results, other_results)
ivu.copy(tables[0])