Beispiel #1
0
		def get_interped_y(label, data, x, x_to):
			run_y = lfu.grab_mobj_by_name(label, data)
			run_interped = lgeo.scalars(
				label = 'interpolated best result - ' + label, 
				scalars = lm.linear_interpolation(
					x.scalars, run_y.scalars, 
					x_to.scalars, 'linear'))
			return run_interped
Beispiel #2
0
	def show_plot_lines(self, *args, **kwargs):

		#interpolate y so that it covers domain x
		def fill_via_interpolation(x, y):
			print 'interpolation for incorrectly '+\
				'structured data is not supported'

		def plot_(x, y, label, col):
			if not x.size == y.size: x, y = fill_via_interpolation(x, y)
			try:
				line = matplotlib.lines.Line2D(
					#x, y, color = self.colors.pop())
					x, y, color = self.colors[col])
			except IndexError: print 'too many lines!'; return
			except: pdb.set_trace()
			line.set_label(label)
			ax.add_line(line)

		self.resolve_x_domain()
		ax = self.add_plot()
		ax.grid(True)
		if type(self._data_.data[0]) is types.ListType:
			self._data_.data = lfu.flatten(self._data_.data)

		x_ax = lfu.grab_mobj_by_name(self.x_ax_title, self._data_.data)
		y_axes = [dater for dater in self._data_.data if dater.label 
			in self._plot_targets_ and not dater.label is x_ax.label]
			#in self._plot_targets_]
		if not y_axes:
			print 'incorrect plot targets...reconciling...'
			y_axes = [dater for dater in self._data_.data]
			self.colors = [self.colormap(i) for i in np.linspace(
				0, 0.9, min([self.max_line_count, len(y_axes)]))]

		x = np.array(x_ax.scalars)
		ys = [np.array(y_ax.scalars) for y_ax in y_axes 
							if hasattr(y_ax, 'scalars')]
		[plot_(x, y, label, col_dex) for x, y, label, col_dex in 
			zip([x]*len(ys), ys, [dater.label for dater in y_axes], 
				range(len(ys)))]
		ax.axis([x.min(), x.max(), min([y.min() for y in ys]), 
								max([y.max() for y in ys])])
		ax.legend()
		#pylab.gca().set_xscale('log',basex=2)
		#ax.set_yscale('log')
		if self.x_log: ax.set_xscale('log')
		if self.y_log: ax.set_yscale('log')
		self.canvas.draw()
Beispiel #3
0
	def make_surface(self, x_ax = '', y_ax = '', surf_target = ''):

		data = self.data_scalars
		daters = [dater.label for dater in data]
		are_ax = [label in self.axis_labels for label in daters]
		axes = [copy(dater) for dater, is_ax in 
					zip(data, are_ax) if is_ax]
		ax_labs = [ax.label for ax in axes]
		if not (x_ax in ax_labs and y_ax in ax_labs and 
				not x_ax == y_ax and surf_target in self.surf_targets):
			print 'chosen axes do not correspond to surface'
			print 'axes:\n', ax_labs, '\nsurfaces:\n', self.surf_targets
			return False

		surf = lfu.grab_mobj_by_name(surf_target, data)
		x_ax_dex = ax_labs.index(x_ax)
		y_ax_dex = ax_labs.index(y_ax)
		ax_slices = copy(self.axis_defaults)
		ax_slices[x_ax_dex] = None
		ax_slices[y_ax_dex] = None

		reduced = (axes, surf)
		in_slices = []
		for ax_dex, ax in enumerate(axes):
			if ax_slices[ax_dex] is None:
				in_slices.append([True for val in ax.scalars])

			else:
				in_slices.append([(val == ax_slices[ax_dex]) 
									for val in ax.scalars])

		in_every_slice = [(False not in row) for row in zip(*in_slices)]
		sub_surf = scalars_from_labels([surf_target])[0]
		sub_surf.scalars = [sur for sur, in_ in 
			zip(surf.scalars, in_every_slice) if in_]
		sub_axes = scalars_from_labels(self.axis_labels)
		for sub_ax, ax in zip(sub_axes, axes):
			sub_ax.scalars = lfu.uniqfy([val for val, in_ 
				in zip(ax.scalars, in_every_slice) if in_])

		self.reduced = (sub_axes, sub_surf)
		return True
	def postproc(self, *args, **kwargs):
		#pool should invariably be a list of 
		#	lists of data objects for each trajectory
		#a method must always be provided by a superclass
		#	a pool and a p_space are optional, default
		#	is to use the ensemble
		self.determine_regime(args[0])
		pool = []
		sources = self.get_source_reference(1, *args, **kwargs)
		from_always = self.parent.parent._children_[0].data
		for inp in self.input_regime:
			inpmobj = lfu.grab_mobj_by_name(inp, from_always)
			lfu.zip_list(pool, [inpmobj.data.data])
		for src in sources: lfu.zip_list(pool, src.data)
		if self.regime == 'all trajectories':
			self.handle_all_trajectories(kwargs['method'], pool)
		elif self.regime == 'manual grouping':
			self.handle_manual_grouping(kwargs['method'], pool)
		elif self.regime == 'per trajectory':
			self.handle_per_trajectory(kwargs['method'], pool)
Beispiel #5
0
 def postproc(self, *args, **kwargs):
     #pool should invariably be a list of
     #	lists of data objects for each trajectory
     #a method must always be provided by a superclass
     #	a pool and a p_space are optional, default
     #	is to use the ensemble
     self.determine_regime(args[0])
     pool = []
     sources = self.get_source_reference(1, *args, **kwargs)
     from_always = self.parent.parent._children_[0].data
     for inp in self.input_regime:
         inpmobj = lfu.grab_mobj_by_name(inp, from_always)
         lfu.zip_list(pool, [inpmobj.data.data])
     for src in sources:
         lfu.zip_list(pool, src.data)
     if self.regime == 'all trajectories':
         self.handle_all_trajectories(kwargs['method'], pool)
     elif self.regime == 'manual grouping':
         self.handle_manual_grouping(kwargs['method'], pool)
     elif self.regime == 'per trajectory':
         self.handle_per_trajectory(kwargs['method'], pool)
Beispiel #6
0
	def finalize(self, *args, **kwargs):

		def get_interped_y(label, data, x, x_to):
			run_y = lfu.grab_mobj_by_name(label, data)
			run_interped = lgeo.scalars(
				label = 'interpolated best result - ' + label, 
				scalars = lm.linear_interpolation(
					x.scalars, run_y.scalars, 
					x_to.scalars, 'linear'))
			return run_interped

		self.best_fits = [(met.best_measure, 
			met.data[0].scalars[met.best_measure]) 
			for met in self.metrics]
		self.handle_fitting_key()
		self.parameter_space.set_current_position(
			self.p_sp_trajectory[self.best_fits[
						self.prime_metric][0]])
		best_run_data = lis.run_system(self.ensemble)
		best_run_data = [lgeo.scalars(label = lab, scalars = dat) 
			for lab, dat in zip(self.run_targets, best_run_data)]
		best_run_data_x = lfu.grab_mobj_by_name(
			self.data_to_fit_to[0].label, best_run_data)
		best_run_data_ys = [get_interped_y(
			lab, best_run_data, best_run_data_x, self.data_to_fit_to[0]) 
				for lab in lfu.grab_mobj_names(self.data_to_fit_to[1:])]

		print 'fit routine:', self.label, 'best fit:', self.best_fits
		print '\tran using regime:', self.regime
		best_data = self.data_to_fit_to + best_run_data_ys
		lgd.quick_plot_display(best_data[0], best_data[1:], delay = 5)
		self.ensemble.data_pool.pool_names =\
			[dat.label for dat in best_data]
		self.ensemble.data_pool.batch_pool.append(best_data)
		if self.regime.startswith('coarse'):
			self.impose_coarse_result_to_p_space()
			self.ensemble.cartographer_plan.parameter_space.\
				set_current_position(self.p_sp_trajectory[
					self.best_fits[self.prime_metric][0]])
Beispiel #7
0
	def show_plot_surface(self, *args, **kwargs):
		self.resolve_x_domain()
		self.resolve_y_domain()
		self.resolve_surf_target()
		self.figure.clf()
		ax = Axes3D(self.figure)
		self.newest_ax = ax
		ax.cla()
		ax.grid(False)
		#color = (0.1843, 0.3098, 0.3098)
		#ax.set_axis_bgcolor(color)
		try:
			surf_vector_dex = [hasattr(dater, 'reduced') 
				for dater in self._data_.data].index(True)

		except ValueError:
			print 'no surface_vector found!'; return

		surf_vect = self._data_.data[surf_vector_dex]
		made_surf = surf_vect.make_surface(
			x_ax = self.x_ax_title, y_ax = self.y_ax_title, 
							surf_target = self.surf_target)
		if not made_surf:
			print 'surface was not resolved'
			return

		ax.set_xlabel(self.x_ax_title, fontsize = 18)
		ax.set_ylabel(self.y_ax_title, fontsize = 18)
		ax.set_zlabel(self.surf_target, fontsize = 18)
		self.title = self.surf_target
		ax.set_title(self.title)
		x_ax = lfu.grab_mobj_by_name(self.x_ax_title, 
								surf_vect.axis_values)
		y_ax = lfu.grab_mobj_by_name(self.y_ax_title, 
								surf_vect.axis_values)
		x = np.array(x_ax.scalars, dtype = float)
		y = np.array(y_ax.scalars, dtype = float)
		try:
			surf = np.array(surf_vect.reduced[1].scalars, 
					dtype = float).reshape(len(x), len(y))

		except ValueError:
			print 'not organized properly to colorplot...'
			return

		surf = surf.transpose()
		x_min, x_max = x.min(), x.max()
		y_min, y_max = y.min(), y.max()
		z_min, z_max = surf.min(), surf.max()

		x, y = np.meshgrid(x, y)
		ax.set_zlim(z_min, z_max)
		ax.axis([x_min, x_max, y_min, y_max])
		surf = ax.plot_surface(x, y, surf, cmap = plt.get_cmap('jet'), 
		#surf = ax.plot_surface(x, y, surf, cmap = plt.cm.gist_heat, 
			shade = True, rstride = 1, cstride = 1, 
			linewidth = 0, antialiased = False, zorder = 1.0)

		#ax.zaxis.set_major_locator(LinearLocator(10))
		#ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

		self.figure.colorbar(surf, shrink = 0.75)
		#ax.set_axisbelow()
		self.canvas.draw()
Beispiel #8
0
	def show_plot_color(self, *args, **kwargs):
		self.resolve_x_domain()
		self.resolve_y_domain()
		self.resolve_surf_target()
		ax = self.add_plot()
		try:
			surf_vector_dex = [hasattr(dater, 'reduced') 
				for dater in self._data_.data].index(True)

		except ValueError:
			print 'no surface_vector found!'; return

		surf_vect = self._data_.data[surf_vector_dex]
		made_surf = surf_vect.make_surface(
			x_ax = self.x_ax_title, y_ax = self.y_ax_title, 
							surf_target = self.surf_target)
		if not made_surf:
			print 'surface was not resolved'
			return

		self.title = self.surf_target
		ax.set_title(self.title)
		x_ax = lfu.grab_mobj_by_name(self.x_ax_title, 
								surf_vect.axis_values)
		y_ax = lfu.grab_mobj_by_name(self.y_ax_title, 
								surf_vect.axis_values)
		x = np.array(x_ax.scalars, dtype = float)
		y = np.array(y_ax.scalars, dtype = float)
		try:
			surf = np.array(surf_vect.reduced[1].scalars, 
					dtype = float).reshape(len(x), len(y))

		except ValueError:
			print 'not organized properly to colorplot...'
			return

		surf = surf.transpose()
		x_min, x_max = x.min(), x.max()
		y_min, y_max = y.min(), y.max()
		z_min, z_max = surf.min(), surf.max()
		#plt.xscale('log')
		#plt.yscale('log')

		delx = [x[i+1] - x[i] for i in range(len(x) - 1)]
		dely = [y[i+1] - y[i] for i in range(len(y) - 1)]
		xdels = lfu.uniqfy(delx)
		ydels = lfu.uniqfy(dely)
		if len(xdels) == 1 and len(ydels) == 1:
			pc_mesh = ax.imshow(surf, interpolation = 'bicubic', 
				cmap = plt.get_cmap('jet'), vmin = z_min, vmax = z_max, 
				#cmap = 'autumn', vmin = z_min, vmax = z_max, 
				origin = 'lower', extent = (x_min, x_max, y_min, y_max))
			#Acceptable interpolations are 'none', 'nearest', 'bilinear', 
			#'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 
			#'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 
			#'bessel', 'mitchell', 'sinc', 'lanczos'

		else:
			print 'axes values are not evenly spaced; plot will be boxy'
			pc_mesh = ax.pcolormesh(x, y, surf, 
				cmap = plt.get_cmap('jet'), 
			#pc_mesh = ax.pcolormesh(x, y, surf, cmap = 'autumn', 
				shading = 'gouraud', vmin = z_min, vmax = z_max)

		ax.axis([x.min(), x.max(), y.min(), y.max()])
		ax.grid(True)
		self.figure.colorbar(pc_mesh)
		self.canvas.draw()