def draw_1D_positive_roots(self, ax, function, p_vals, slice_variable, range_slice, resolution=100, ylim=None, line_dict=None, **kwargs): lines = self.line_1D_positive_roots(function, p_vals, slice_variable, range_slice, resolution=int(resolution)) line_styles = ['-', '--', '..'] colors = ['k', 'r', 'y'] unique_R = {i[2] for i in lines} if line_dict == None: line_dict = {0:{'ls':'-','c':'k','lw':2.}, 1:{'ls':':','c':'r','lw':2.}, 2:{'ls':'--','c':'y','lw':2.} } j = 0 for i in unique_R: if i in line_dict: continue line_dict[i] = {'c':mt.cm.Spectral_r(j/len(unique_R)), 'ls':'--'} for i in lines: x = i[0] y = i[1] r = i[2] ax.plot(x, y, **line_dict[r]) if slice_variable in self._latex: slice_variable = '$'+self._latex[slice_variable]+'$' if ylim is not None: ax.set_ylim(ylim) ax.set_xlabel(r'$\log_{10}$(' + slice_variable + ')') if isinstance(function, Expression): expr = function else: expr = Expression(function) ax.set_ylabel('$'+expr.latex(self._latex)+'$') return lines
def _vertex_equations_2D_slice(self, p_vals, x_variable, y_variable, range_x, range_y, log_out): lower = p_vals.copy() upper = p_vals.copy() lower[x_variable] = min(range_x) upper[x_variable] = max(range_x) lower[y_variable] = min(range_y) upper[y_variable] = max(range_y) stack = DSCaseVertexEquationsFor2DSlice(self._swigwrapper, lower._swigwrapper, upper._swigwrapper, x_variable, y_variable, log_out) vertices = [] for i in xrange(DSStackCount(stack)): expressions = DSExpressionArrayFromVoid(DSStackPop(stack)) expr0 = Expression(None) expr0._swigwrapper = DSExpressionAtIndexOfExpressionArray(expressions, 0) expr1 = Expression(None) expr1._swigwrapper = DSExpressionAtIndexOfExpressionArray(expressions, 1) vertices.append(Equations([str(expr0), str(expr1)], latex_symbols=self._latex)) DSSecureFree(expressions) DSStackFree(stack) vertices.reverse() return vertices
def steady_state_function(self, function, parameter_values): if isinstance(function, Expression): expr = function else: expr = Expression(function) p_vals = parameter_values.copy() p_vals.update(self.steady_state(parameter_values, log_out=False)) p_vals.update(self.steady_state_flux(parameter_values, log_out=False)) for i in self.dependent_variables: for j in self.independent_variables: p_vals["$L_" + i + "_" + j] = self.log_gain(i, j) value = expr.eval_with_values(p_vals=p_vals) return value
def steady_state_function(self, function, parameter_values): if isinstance(function, Expression): expr = function else: expr = Expression(function) p_values = VariablePool(names=self.independent_variables) for key in p_values: p_values[key] = parameter_values[key] ss = self.steady_state(p_values, log_out=False) flux = self.steady_state_flux(p_values, log_out=False) values = dict() for subcase in ss: p_values.update(ss[subcase]) p_values.update(flux[subcase]) value = expr.eval_with_values(p_vals=p_values) values[subcase] = value return values
def draw_1D_ss_function(self, ax, function, p_vals, slice_variable, range_slice, resolution=100, colors=None, included_cases=None, ylim = None, **kwargs): p_bounds = dict(p_vals) p_bounds[slice_variable] = range_slice if included_cases is not None: included_cases = [i.case_number for i in self(included_cases)] if self.number_of_cases < 1e5: valid_cases = self.valid_cases(p_bounds=p_bounds) valid_nonstrict = self.valid_cases(p_bounds=p_bounds, strict=False) hatched_cases = [i for i in valid_cases if i not in included_cases] valid_nonstrict = [i for i in valid_cases if i in included_cases] valid_cases = [i for i in valid_cases if i in included_cases] valid_nonstrict = [i for i in valid_cases if i not in valid_cases] else: valid_cases = [i for i in included_cases if self(i).is_valid(p_bounds=p_bounds)] valid_nonstrict = [] else: valid_cases = self.valid_cases(p_bounds=p_bounds) valid_nonstrict = self.valid_cases(p_bounds=p_bounds, strict=False) valid_nonstrict = [i for i in valid_nonstrict if i not in valid_cases] if len(valid_cases)+len(valid_nonstrict) == 0: # fill black return valid_cases = valid_cases + valid_nonstrict#self.valid_cases(p_bounds=p_bounds) lines = list() ylim_t = None if 'color' not in kwargs: kwargs['color'] = 'k' for case in valid_cases: if colors is not None: if case in colors: kwargs['color'] = colors[case] else: kwargs.pop('color') pt = self(case).draw_1D_ss_function(ax, function, p_vals, slice_variable, range_slice, resolution=resolution, **kwargs) if pt is None: continue lines.append(pt) ydata = pt[0].get_ydata() miny = min(ydata) maxy = max(ydata) if ylim is None: if ylim_t is None: ylim_t = [min(ydata), max(ydata)] else: ylim_t = [min((ylim_t[0], miny)), max((ylim_t[1], maxy))] if ylim is None: ylim = ylim_t ax.set_ylim([ylim[0]-(ylim[1]-ylim[0])*0.1, ylim[1]+(ylim[1]-ylim[0])*0.1]) ax.set_xlim(np.log10(range_slice)) if slice_variable in self._latex: slice_variable = '$'+self._latex[slice_variable]+'$' ax.set_xlabel(r'$\log_{10}$(' + slice_variable + ')') if isinstance(function, Expression): expr = function else: expr = Expression(function) ax.set_ylabel('$'+expr.latex(self._latex)+'$') return lines