From de58b03c8d3ea1db40e3a3ea377205d68b7f5efa Mon Sep 17 00:00:00 2001 From: Jan Caron <j.caron@fz-juelich.de> Date: Mon, 1 Sep 2014 14:32:15 +0200 Subject: [PATCH] Quality of life improvements, docstrings, and new gui-based method! Many Doctring corrections, all plots now have a "show" parameter to not show a plot at the end of the method (needed for guis and such). magdata: quiver_plot: axis switch for x-projection, implemented logarithmic arrows and scaling feature. projector: added to_mag_data() method to directly produce a projected magnetization distribution. gui/create_logo: removed (obsolete and unuseful). gui/mag_slicer: added! --- pyramid/costfunction.py | 10 +- pyramid/magdata.py | 84 ++++++--- pyramid/phasemap.py | 44 +++-- pyramid/projector.py | 22 +++ pyramid/reconstruction.py | 8 +- pyramid/regularisator.py | 8 +- .../vtk_conversion_nanowire_full.py | 60 +++++-- scripts/collaborations/zi_an.py | 72 ++++---- .../create_core_shell_disc.py | 9 +- .../create_core_shell_sphere.py | 7 +- scripts/create distributions/create_sample.py | 12 +- scripts/create distributions/create_vortex.py | 6 +- scripts/gui/create_logo.py | 70 -------- scripts/gui/create_logo.ui | 102 ----------- scripts/gui/gui_create_logo.py | 124 -------------- scripts/gui/mag_slicer.py | 160 ++++++++++++++++++ scripts/gui/mag_slicer.ui | 136 +++++++++++++++ .../reconstruct_random_pixels.py | 2 +- 18 files changed, 527 insertions(+), 409 deletions(-) delete mode 100644 scripts/gui/create_logo.py delete mode 100644 scripts/gui/create_logo.ui delete mode 100644 scripts/gui/gui_create_logo.py create mode 100644 scripts/gui/mag_slicer.py create mode 100644 scripts/gui/mag_slicer.ui diff --git a/pyramid/costfunction.py b/pyramid/costfunction.py index 940df35..a18cc4e 100644 --- a/pyramid/costfunction.py +++ b/pyramid/costfunction.py @@ -14,7 +14,6 @@ import logging class Costfunction(object): - # TODO: Docstrings! '''Class for calculating the cost of a 3D magnetic distributions in relation to 2D phase maps. Represents a strategy for the calculation of the `cost` of a 3D magnetic distribution in @@ -31,8 +30,13 @@ class Costfunction(object): fwd_model : :class:`~.ForwardModel` The Forward model instance which should be used for the simulation of the phase maps which will be compared to `y`. - lam : float, optional - Regularization parameter used in the Hessian matrix multiplication. Default is 0. + Se_inv : :class:`~numpy.ndarray` (N=2), optional + Inverted covariance matrix of the measurement errors. The matrix has size `NxN` with N + being the length of the targetvector y (vectorized phase map information). Defaults to + an appropriate unity matrix if none is provided. + regularisator : :class:`~.Regularisator`, optional + Regularisator class that's responsible for the regularisation term. Defaults to zero + order Tikhonov if none is provided. ''' diff --git a/pyramid/magdata.py b/pyramid/magdata.py index df365f9..23c931e 100644 --- a/pyramid/magdata.py +++ b/pyramid/magdata.py @@ -406,8 +406,8 @@ class MagData(object): mag_file.close() return MagData(a, magnitude) - def quiver_plot(self, title='Magnetization Distribution', filename=None, axis=None, - proj_axis='z', ax_slice=None): + def quiver_plot(self, title='Magnetization Distribution', axis=None, proj_axis='z', + ax_slice=None, log=False, scaled=True, show=True): '''Plot a slice of the magnetization as a quiver plot. Parameters @@ -416,15 +416,17 @@ class MagData(object): The title for the plot. axis : :class:`~matplotlib.axes.AxesSubplot`, optional Axis on which the graph is plotted. Creates a new figure if none is specified. - filename : string, optional - The filename, specifying the location where the image is saved. If not specified, - the image is shown instead. proj_axis : {'z', 'y', 'x'}, optional The axis, from which a slice is plotted. The default is 'z'. ax_slice : int, optional The slice-index of the axis specified in `proj_axis`. Is set to the center of `proj_axis` if not specified. - + log : boolean, optional + Takes the Default is False. + scaled : boolean, optional + Normalizes the plotted arrows in respect to the highest one. Default is True. + show: bool, optional + A switch which determines if the plot is shown at the end of plotting. Default is True. Returns ------- axis: :class:`~matplotlib.axes.AxesSubplot` @@ -438,45 +440,62 @@ class MagData(object): self.LOG.debug('proj_axis == z') if ax_slice is None: self.LOG.debug('ax_slice is None') - ax_slice = int(self.dim[0]/2) - mag_slice_u = self.magnitude[0][ax_slice, ...] # x-component - mag_slice_v = self.magnitude[1][ax_slice, ...] # y-component + ax_slice = int(self.dim[0]/2.) + plot_u = np.copy(self.magnitude[0][ax_slice, ...]) # x-component + plot_v = np.copy(self.magnitude[1][ax_slice, ...]) # y-component u_label = 'x [px]' v_label = 'y [px]' elif proj_axis == 'y': # Slice of the xz-plane with y = ax_slice self.LOG.debug('proj_axis == y') if ax_slice is None: self.LOG.debug('ax_slice is None') - ax_slice = int(self.dim[1]/2) - mag_slice_u = self.magnitude[0][:, ax_slice, :] # x-component - mag_slice_v = self.magnitude[2][:, ax_slice, :] # z-component + ax_slice = int(self.dim[1]/2.) + plot_u = np.copy(self.magnitude[0][:, ax_slice, :]) # x-component + plot_v = np.copy(self.magnitude[2][:, ax_slice, :]) # z-component u_label = 'x [px]' v_label = 'z [px]' elif proj_axis == 'x': # Slice of the yz-plane with x = ax_slice self.LOG.debug('proj_axis == x') if ax_slice is None: self.LOG.debug('ax_slice is None') - ax_slice = int(self.dim[2]/2) - mag_slice_u = self.magnitude[1][..., ax_slice] # y-component - mag_slice_v = self.magnitude[2][..., ax_slice] # z-component - u_label = 'y [px]' - v_label = 'z [px]' + ax_slice = int(self.dim[2]/2.) + plot_u = np.swapaxes(np.copy(self.magnitude[2][..., ax_slice]), 0, 1) # z-component + plot_v = np.swapaxes(np.copy(self.magnitude[1][..., ax_slice]), 0, 1) # y-component + u_label = 'z [px]' + v_label = 'y [px]' # If no axis is specified, a new figure is created: if axis is None: self.LOG.debug('axis is None') fig = plt.figure(figsize=(8.5, 7)) - axis = fig.add_subplot(1, 1, 1, aspect='equal') - axis.quiver(mag_slice_u, mag_slice_v, pivot='middle', angles='xy', scale_units='xy', - scale=1, headwidth=6, headlength=7) - axis.set_xlim(-1, np.shape(mag_slice_u)[1]) - axis.set_ylim(-1, np.shape(mag_slice_u)[0]) + axis = fig.add_subplot(1, 1, 1) + axis.set_aspect('equal') + angles = np.angle(plot_u+1j*plot_v, deg=True) + # Take the logarithm of the arrows to clearly show directions (if specified): + if log: + cutoff = 10 + amp = np.round(np.hypot(plot_u, plot_v), decimals=cutoff) + min_value = amp[np.nonzero(amp)].min() + plot_u = np.round(plot_u, decimals=cutoff) / min_value + plot_u = np.log10(np.abs(plot_u)+1) * np.sign(plot_u) + plot_v = np.round(plot_v, decimals=cutoff) / min_value + plot_v = np.log10(np.abs(plot_v)+1) * np.sign(plot_v) + # Scale the magnitude of the arrows to the highest one (if specified): + if scaled: + plot_u /= np.hypot(plot_u, plot_v).max() + plot_v /= np.hypot(plot_u, plot_v).max() + axis.quiver(plot_u, plot_v, pivot='middle', units='xy', angles=angles, + scale_units='xy', scale=1, headwidth=6, headlength=7) + axis.set_xlim(-1, np.shape(plot_u)[1]) + axis.set_ylim(-1, np.shape(plot_u)[0]) axis.set_title(title, fontsize=18) axis.set_xlabel(u_label, fontsize=15) axis.set_ylabel(v_label, fontsize=15) axis.tick_params(axis='both', which='major', labelsize=14) axis.xaxis.set_major_locator(MaxNLocator(nbins=9, integer=True)) axis.yaxis.set_major_locator(MaxNLocator(nbins=9, integer=True)) - plt.show() + # Show Plot: + if show: + plt.show() return axis def quiver_plot3d(self, title='Magnetization Distribution'): @@ -514,9 +533,18 @@ class MagData(object): mlab.colorbar(None, orientation='vertical') def save_to_x3d(self, filename='..\..\output\magdata_output.x3d', maximum=1): - # TODO: Docstring! - self.LOG.debug('Calling save_to_x3d') + '''Output the magnetization in the .x3d format for the Fraunhofer InstantReality Player. + + Parameters + ---------- + None + Returns + ------- + None + + ''' + self.LOG.debug('Calling save_to_x3d') dim = self.dim # Create points and vector components as lists: zz, yy, xx = np.mgrid[0.5:(dim[0]-0.5):dim[0]*1j, @@ -528,14 +556,14 @@ class MagData(object): x_mag = np.reshape(self.magnitude[0], (-1)) y_mag = np.reshape(self.magnitude[1], (-1)) z_mag = np.reshape(self.magnitude[2], (-1)) - + # Load template, load tree and write viewpoint information: template = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'template.x3d') parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(template, parser) scene = tree.find('Scene') etree.SubElement(scene, 'Viewpoint', position='0 0 {}'.format(1.5*dim[0]), fieldOfView='1') - + # Write each "spin"-tag separately: for i in range(np.prod(dim)): mag = np.sqrt(x_mag[i]**2+y_mag[i]**2+z_mag[i]**2) if mag != 0: @@ -562,5 +590,5 @@ class MagData(object): value='{} {} {}'.format(*spin_color)) etree.SubElement(spin, 'fieldValue', name='spin_scale', value='{} {} {}'.format(*spin_scale)) - + # Write the tree into the file in pretty print format: tree.write(filename, pretty_print=True) diff --git a/pyramid/phasemap.py b/pyramid/phasemap.py index 061ade2..9dd4add 100644 --- a/pyramid/phasemap.py +++ b/pyramid/phasemap.py @@ -332,7 +332,8 @@ class PhaseMap(object): # If no axis is specified, a new figure is created: if axis is None: fig = plt.figure(figsize=(8.5, 7)) - axis = fig.add_subplot(1, 1, 1, aspect='equal') + axis = fig.add_subplot(1, 1, 1) + axis.set_aspect('equal') # Plot the phasemap: im = axis.pcolormesh(phase, cmap=cmap, vmin=-limit, vmax=limit, norm=norm) # Set the axes ticks and labels: @@ -344,8 +345,8 @@ class PhaseMap(object): axis.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:g}'.format(x*self.a))) axis.tick_params(axis='both', which='major', labelsize=14) axis.set_title(title, fontsize=18) - axis.set_xlabel('x [nm]', fontsize=15) - axis.set_ylabel('y [nm]', fontsize=15) + axis.set_xlabel('u-axis [nm]', fontsize=15) + axis.set_ylabel('v-axis [nm]', fontsize=15) # Add colorbar: fig = plt.gcf() fig.subplots_adjust(right=0.8) @@ -359,7 +360,7 @@ class PhaseMap(object): # Return plotting axis: return axis - def display_phase3d(self, title='Phase Map', cmap='RdBu'): + def display_phase3d(self, title='Phase Map', cmap='RdBu', show=True): '''Display the phasemap as a 3-D surface with contourplots. Parameters @@ -369,6 +370,8 @@ class PhaseMap(object): cmap : string, optional The :class:`~matplotlib.colors.Colormap` which is used for the plot as a string. The default is 'RdBu'. + show: bool, optional + A switch which determines if the plot is shown at the end of plotting. Default is True. Returns ------- @@ -390,11 +393,12 @@ class PhaseMap(object): linewidth=0, antialiased=False) axis.contourf(uu, vv, phase, 15, zdir='z', offset=np.min(phase), cmap=cmap) axis.view_init(45, -135) - axis.set_xlabel('x-axis [px]') - axis.set_ylabel('y-axis [px]') + axis.set_xlabel('u-axis [px]') + axis.set_ylabel('v-axis [px]') axis.set_zlabel('phase shift [{}]'.format(self.unit)) # Show Plot: - plt.show() + if show: + plt.show() # Return plotting axis: return axis @@ -418,7 +422,7 @@ class PhaseMap(object): interpolation : {'none, 'bilinear', 'cubic', 'nearest'}, optional Defines the interpolation method. No interpolation is used in the default case. show: bool, optional - A switch which determines if the plot is shown at the end of plotting. + A switch which determines if the plot is shown at the end of plotting. Default is True. Returns ------- @@ -459,15 +463,16 @@ class PhaseMap(object): # If no axis is specified, a new figure is created: if axis is None: fig = plt.figure() - axis = fig.add_subplot(1, 1, 1, aspect='equal') + axis = fig.add_subplot(1, 1, 1) + axis.set_aspect('equal') # Plot the image and set axes: axis.imshow(holo_image, origin='lower', interpolation=interpolation) # Set the title and the axes labels: axis.set_title(title) plt.tick_params(axis='both', which='major', labelsize=14) axis.set_title(title, fontsize=18) - axis.set_xlabel('x-axis [px]', fontsize=15) - axis.set_ylabel('y-axis [px]', fontsize=15) + axis.set_xlabel('u-axis [px]', fontsize=15) + axis.set_ylabel('v-axis [px]', fontsize=15) axis.set_xlim(0, self.dim_uv[1]) axis.set_ylim(0, self.dim_uv[0]) axis.xaxis.set_major_locator(MaxNLocator(nbins=9, integer=True)) @@ -479,7 +484,7 @@ class PhaseMap(object): return axis def display_combined(self, title='Combined Plot', cmap='RdBu', limit=None, norm=None, - density=1, interpolation='none', grad_encode='bright'): + density=1, interpolation='none', grad_encode='bright', show=True): '''Display the phase map and the resulting color coded holography image in one plot. Parameters @@ -506,6 +511,8 @@ class PhaseMap(object): encodes the direction (without gradient strength), 'dark' modulates the gradient strength with a factor between 0 and 1 and 'bright' (which is the default) encodes the gradient strength with color saturation. + show: bool, optional + A switch which determines if the plot is shown at the end of plotting. Default is True. Returns ------- @@ -525,17 +532,20 @@ class PhaseMap(object): phase_axis = fig.add_subplot(1, 2, 2, aspect='equal') fig.subplots_adjust(right=0.85) self.display_phase(cmap='RdBu', limit=limit, norm=norm, axis=phase_axis, show=False) - plt.show() + # Show Plot: + if show: + plt.show() # Return the plotting axes: return phase_axis, holo_axis @classmethod - def make_color_wheel(cls): + def make_color_wheel(cls, show=True): '''Display a color wheel to illustrate the color coding of the gradient direction. Parameters ---------- - None + show: bool, optional + A switch which determines if the plot is shown at the end of plotting. Default is True. Returns ------- @@ -561,4 +571,6 @@ class PhaseMap(object): axis.imshow(color_wheel, origin='lower') axis.xaxis.set_major_locator(NullLocator()) axis.yaxis.set_major_locator(NullLocator()) - plt.show() + # Show Plot: + if show: + plt.show() diff --git a/pyramid/projector.py b/pyramid/projector.py index 56d0a75..c18088d 100644 --- a/pyramid/projector.py +++ b/pyramid/projector.py @@ -12,6 +12,8 @@ import itertools from scipy.sparse import coo_matrix, csr_matrix +from pyramid.magdata import MagData + import logging @@ -188,6 +190,26 @@ class Projector(object): raise AssertionError('Vector size has to be suited either for ' 'vector- or scalar-field-projection!') + def to_mag_data(self, mag_data): + self.LOG.debug('Calling to_mag_data') + '''Project a :class:`~.MagData` object and output another :class:`~.MagData` object. + + Parameters + ---------- + mag_data : :class:`~.MagData` + :class:`~.MagData` object that should be projected. + + Returns + ------- + mag_data_result : :class:`~.MagData` + :class:`~.MagData` object containing the projected magnetization distribution from + the input. + + ''' + mag_proj = self(mag_data.mag_vec).reshape((2,)+self.dim_uv) + magnitude = np.expand_dims(np.concatenate((mag_proj, np.zeros((1,)+self.dim_uv))), axis=1) + return MagData(mag_data.a, magnitude) + class XTiltProjector(Projector): diff --git a/pyramid/reconstruction.py b/pyramid/reconstruction.py index 22fd35b..f9b6bee 100644 --- a/pyramid/reconstruction.py +++ b/pyramid/reconstruction.py @@ -84,7 +84,6 @@ class PrintIterator(object): def optimize_sparse_cg(data, Se_inv=None, regularisator=None, verbosity=0): - # TODO: Docstring! '''Reconstruct a three-dimensional magnetic distribution from given phase maps via the conjugate gradient optimizaion method :func:`~.scipy.sparse.linalg.cg`. @@ -94,6 +93,13 @@ def optimize_sparse_cg(data, Se_inv=None, regularisator=None, verbosity=0): :class:`~.DataSet` object containing all phase maps in :class:`~.PhaseMap` objects and all projection directions in :class:`~.Projector` objects. These provide the essential information for the reconstruction. + Se_inv : :class:`~numpy.ndarray` (N=2), optional + Inverted covariance matrix of the measurement errors. The matrix has size `NxN` with N + being the length of the targetvector y (vectorized phase map information). Defaults to + an appropriate unity matrix if none is provided. + regularisator : :class:`~.Regularisator`, optional + Regularisator class that's responsible for the regularisation term. Defaults to zero + order Tikhonov if none is provided. verbosity : {0, 1, 2}, optional Parameter defining the verposity of the output. `2` will show the current number of the iteration and the cost of the current distribution. `1` will just show the iteration diff --git a/pyramid/regularisator.py b/pyramid/regularisator.py index 5ade7c6..c3b680f 100644 --- a/pyramid/regularisator.py +++ b/pyramid/regularisator.py @@ -28,17 +28,17 @@ class Regularisator(object): LOG = logging.getLogger(__name__+'.Regularisator') @abc.abstractmethod - def __init__(self, Sa_inv, x_a=None): + def __init__(self, Sa_sqrt_inv, x_a=None): self.LOG.debug('Calling __init__') - self.Sa_inv = Sa_inv + self.Sa_sqrt_inv = Sa_sqrt_inv if x_a is None: - x_a = np.zeros(np.shape(Sa_inv)[1]) + x_a = np.zeros(np.shape(Sa_sqrt_inv)[1]) self.x_a = x_a self.LOG.debug('Created '+str(self)) def __call__(self, x, x_a=None): self.LOG.debug('Calling __call__') - return (x-self.x_a).dot(self.Sa_inv.dot(x-self.x_a)) + return (x-self.x_a).dot(self.Sa_sqrt_inv.dot(x-self.x_a)) def __repr__(self): self.LOG.debug('Calling __repr__') diff --git a/scripts/collaborations/vtk_conversion_nanowire_full.py b/scripts/collaborations/vtk_conversion_nanowire_full.py index a0f52f9..697e6bc 100644 --- a/scripts/collaborations/vtk_conversion_nanowire_full.py +++ b/scripts/collaborations/vtk_conversion_nanowire_full.py @@ -16,7 +16,7 @@ from tqdm import tqdm import pyramid from pyramid.magdata import MagData -from pyramid.projector import SimpleProjector, YTiltProjector, XTiltProjector +from pyramid.projector import YTiltProjector, XTiltProjector from pyramid.phasemapper import PMConvolve from pyramid.phasemap import PhaseMap from pyramid.dataset import DataSet @@ -151,16 +151,48 @@ for i, figure in enumerate(figures): plt.close('all') ################################################################################################### # Close ups: -dim_uv = (600, 200) -mag_data_tip = MagData(mag_data.a, mag_data.magnitude[:, 600:, ...]) -pm = PMConvolve(mag_data.a, SimpleProjector(mag_data_tip.dim, 'y', dim_uv)) -phase_map_tip = PhaseMap(mag_data.a, pm(mag_data_tip).phase[350:, :]) -phase_map_tip.display_combined('Phase Map Nanowire Tip', density=density, - interpolation='bilinear') -plt.savefig(PATH+'_nanowire_tip.png') -mag_data_bot = MagData(mag_data.a, mag_data.magnitude[:, :300, ...]) -pm = PMConvolve(mag_data.a, SimpleProjector(mag_data_bot.dim, 'y', dim_uv)) -phase_map_tip = PhaseMap(mag_data.a, pm(mag_data_bot).phase[:250, :]) -phase_map_tip.display_combined('Phase Map Nanowire Bottom', density=density, - interpolation='bilinear') -plt.savefig(PATH+'_nanowire_bot.png') +dim = (300, 72, 72) +dim_uv = (600, 150) +angles = [0, 20, 40, 60, -20, -40, -60] +for angle in angles: + angle_rad = angle * np.pi/180 + shift = int(np.abs(80*np.sin(angle_rad))) + projector = XTiltProjector(dim, np.pi/2+angle_rad, dim_uv) + projector_scaled = XTiltProjector((dim[0]/2, dim[1]/2, dim[2]/2), np.pi/2+angle_rad, + (dim_uv[0]/2, dim_uv[1]/2)) + # Tip: + mag_data_tip = MagData(mag_data.a, mag_data.magnitude[:, 608:, ...]) + pm = PMConvolve(mag_data.a, projector) + phase_map_tip = PhaseMap(mag_data.a, pm(mag_data_tip).phase[350-shift:530-shift, :]) + phase_map_tip.display_combined('Phase Map Nanowire Tip', density=density, + interpolation='bilinear') + plt.savefig(PATH+'_nanowire_tip_xtilt_{}.png'.format(angle)) + mag_data_tip.scale_down() + mag_proj_tip = projector_scaled.to_mag_data(mag_data_tip) + axis = mag_proj_tip.quiver_plot() + axis.set_xlim(17, 55) + axis.set_ylim(180-shift/2, 240-shift/2) + plt.savefig(PATH+'_nanowire_tip_mag_xtilt_{}.png'.format(angle)) + axis = mag_proj_tip.quiver_plot(log=True) + axis.set_xlim(17, 55) + axis.set_ylim(180-shift/2, 240-shift/2) + plt.savefig(PATH+'_nanowire_tip_mag_log_xtilt_{}.png'.format(angle)) + # Bottom: + mag_data_bot = MagData(mag_data.a, mag_data.magnitude[:, :300, ...]) + pm = PMConvolve(mag_data.a, projector) + phase_map_tip = PhaseMap(mag_data.a, pm(mag_data_bot).phase[50+shift:225+shift, :]) + phase_map_tip.display_combined('Phase Map Nanowire Bottom', density=density, + interpolation='bilinear') + plt.savefig(PATH+'_nanowire_bot_xtilt_{}.png'.format(angle)) + mag_data_bot.scale_down() + mag_proj_bot = projector_scaled.to_mag_data(mag_data_bot) + axis = mag_proj_bot.quiver_plot() + axis.set_xlim(17, 55) + axis.set_ylim(50+shift/2, 110+shift/2) + plt.savefig(PATH+'_nanowire_bot_mag_xtilt_{}.png'.format(angle)) + axis = mag_proj_bot.quiver_plot(log=True) + axis.set_xlim(17, 55) + axis.set_ylim(50+shift/2, 110+shift/2) + plt.savefig(PATH+'_nanowire_bot_mag_log_xtilt_{}.png'.format(angle)) + # Close plots: + plt.close('all') diff --git a/scripts/collaborations/zi_an.py b/scripts/collaborations/zi_an.py index 3d9b03e..d4a44a7 100644 --- a/scripts/collaborations/zi_an.py +++ b/scripts/collaborations/zi_an.py @@ -30,7 +30,6 @@ LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False) ################################################################################################### -PATH = '../../output/zi-an/' threshold = 1 a = 1.0 # in nm density = 5 @@ -38,30 +37,33 @@ b_0 = 1 inter = 'none' dim_small = (64, 64) smoothed_pictures = True -lam = 7.5E-5 +lam = 1E-4 order = 1 +log = True +PATH = '../../output/zi-an/' +if not os.path.exists(PATH+'%.0e/'%lam): + os.makedirs(PATH+'%.0e/'%lam) ################################################################################################### - # Read in files: if smoothed_pictures: - dm3_2_mag = dm3.DM3(PATH+'Output333_hw512.dm3').image - dm3_4_mag = dm3.DM3(PATH+'Output334_hw512.dm3').image - dm3_2_ele = dm3.DM3(PATH+'Output335.dm3').image - dm3_4_ele = dm3.DM3(PATH+'Output336.dm3').image + dm3_2_mag = dm3.DM3(PATH+'Output334_hw512.dm3').image + dm3_4_mag = dm3.DM3(PATH+'Output333_hw512.dm3').image + dm3_2_ele = dm3.DM3(PATH+'Output336.dm3').image + dm3_4_ele = dm3.DM3(PATH+'Output335.dm3').image else: - dm3_2_mag = dm3.DM3(PATH+'07_0102mag60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image - dm3_4_mag = dm3.DM3(PATH+'18a_0102mag_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image - dm3_2_ele = dm3.DM3(PATH+'07_0102ele60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image - dm3_4_ele = dm3.DM3(PATH+'18a_0102ele_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image + dm3_2_mag = dm3.DM3(PATH+'18a_0102mag_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image + dm3_4_mag = dm3.DM3(PATH+'07_0102mag60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image + dm3_2_ele = dm3.DM3(PATH+'18a_0102ele_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image + dm3_4_ele = dm3.DM3(PATH+'07_0102ele60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image # Construct phase maps and masks -phase_map_2 = PhaseMap(a, np.array(dm3_2_mag.resize(dim_small))+0.101) +phase_map_2 = PhaseMap(a, np.array(dm3_2_mag.resize(dim_small))-2.546) phase_map_2.display_combined(density=density, interpolation=inter) -plt.savefig(PATH+'phase_map_2part.png') +plt.savefig(PATH+'%.0e/phase_map_2part.png'%lam) mask_2 = np.expand_dims(np.where(np.array(dm3_2_ele.resize(dim_small)) >= threshold, True, False), axis=0) -phase_map_4 = PhaseMap(a, np.array(dm3_4_mag.resize(dim_small))-2.546) +phase_map_4 = PhaseMap(a, np.array(dm3_4_mag.resize(dim_small))+0.101) phase_map_4.display_combined(density=density, interpolation=inter) -plt.savefig(PATH+'phase_map_4part.png') +plt.savefig(PATH+'%.0e/phase_map_4part.png'%lam) mask_4 = np.expand_dims(np.where(np.array(dm3_4_ele.resize(dim_small)) >= threshold, True, False), axis=0) # Reconstruct the magnetic distribution: @@ -74,39 +76,51 @@ print '4 particle reconstruction time:', clock() - tic # Display the reconstructed phase map and holography image: phase_map_rec_2 = PMConvolve(a, SimpleProjector(mag_data_rec_2.dim), b_0)(mag_data_rec_2) phase_map_rec_2.display_combined('Reconstr. Distribution', density=density, interpolation=inter) -plt.savefig(PATH+'phase_map_2part_rec.png') +plt.savefig(PATH+'%.0e/phase_map_2part_rec.png'%lam) phase_map_rec_4 = PMConvolve(a, SimpleProjector(mag_data_rec_4.dim), b_0)(mag_data_rec_4) phase_map_rec_4.display_combined('Reconstr. Distribution', density=density, interpolation=inter) -plt.savefig(PATH+'phase_map_4part_rec.png') +plt.savefig(PATH+'%.0e/phase_map_4part_rec.png'%lam) # Plot the magnetization: axis = (mag_data_rec_2*(1/mag_data_rec_2.magnitude.max())).quiver_plot() -#axis.set_xlim(20, 45) -#axis.set_ylim(20, 45) -plt.savefig(PATH+'mag_data_2part.png') +axis.set_xlim(20, 45) +axis.set_ylim(20, 45) +plt.savefig(PATH+'%.0e/mag_data_2part.png'%lam) axis = (mag_data_rec_4*(1/mag_data_rec_4.magnitude.max())).quiver_plot() -#axis.set_xlim(20, 45) -#axis.set_ylim(20, 45) -plt.savefig(PATH+'mag_data_4part.png') +axis.set_xlim(20, 45) +axis.set_ylim(20, 45) +plt.savefig(PATH+'%.0e/mag_data_4part.png'%lam) # Display the Phase: phase_diff_2 = phase_map_rec_2-phase_map_2 phase_diff_2.display_phase('Difference') -plt.savefig(PATH+'phase_map_2part_diff.png') +plt.savefig(PATH+'%.0e/phase_map_2part_diff.png'%lam) phase_diff_4 = phase_map_rec_4-phase_map_4 phase_diff_4.display_phase('Difference') -plt.savefig(PATH+'phase_map_4part_diff.png') +plt.savefig(PATH+'%.0e/phase_map_4part_diff.png'%lam) # Get the average difference from the experimental results: print 'Average difference (2 cubes):', np.average(phase_diff_2.phase) print 'Average difference (4 cubes):', np.average(phase_diff_4.phase) # Plot holographic contour maps with overlayed magnetic distributions: axis = phase_map_rec_2.display_holo('Magnetization Overlay', density=0.1, interpolation=inter) -(mag_data_rec_2*(1/mag_data_rec_2.magnitude.max())).quiver_plot(axis=axis) +mag_data_rec_2.quiver_plot(axis=axis) +axis = plt.gca() +axis.set_xlim(20, 45) +axis.set_ylim(20, 45) +plt.savefig(PATH+'%.0e/phase_map_2part_holo.png'%lam) +axis = phase_map_rec_4.display_holo('Magnetization Overlay', density=0.1, interpolation=inter) +mag_data_rec_4.quiver_plot(axis=axis) +axis = plt.gca() +axis.set_xlim(20, 45) +axis.set_ylim(20, 45) +plt.savefig(PATH+'%.0e/phase_map_4part_holo.png'%lam) +axis = phase_map_rec_2.display_holo('Magnetization Overlay', density=0.1, interpolation=inter) +mag_data_rec_2.quiver_plot(axis=axis, log=log) axis = plt.gca() axis.set_xlim(20, 45) axis.set_ylim(20, 45) -plt.savefig(PATH+'phase_map_2part_holo.png') +plt.savefig(PATH+'%.0e/phase_map_2part_holo_log.png'%lam) axis = phase_map_rec_4.display_holo('Magnetization Overlay', density=0.1, interpolation=inter) -(mag_data_rec_4*(1/mag_data_rec_4.magnitude.max())).quiver_plot(axis=axis) +mag_data_rec_4.quiver_plot(axis=axis, log=log) axis = plt.gca() axis.set_xlim(20, 45) axis.set_ylim(20, 45) -plt.savefig(PATH+'phase_map_4part_holo.png') +plt.savefig(PATH+'%.0e/phase_map_4part_holo_log.png'%lam) diff --git a/scripts/create distributions/create_core_shell_disc.py b/scripts/create distributions/create_core_shell_disc.py index 920b4e5..930a40e 100644 --- a/scripts/create distributions/create_core_shell_disc.py +++ b/scripts/create distributions/create_core_shell_disc.py @@ -29,7 +29,6 @@ if not os.path.exists(directory): # Input parameters: filename = directory + '/mag_dist_core_shell_disc.txt' a = 1.0 # in nm -density = 1 dim = (32, 32, 32) center = (dim[0]/2-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5) radius_core = dim[1]/8 @@ -42,13 +41,13 @@ mag_shape_shell = np.logical_xor(mag_shape_outer, mag_shape_core) mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape_shell, magnitude=0.75)) mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_core, phi=0, theta=0)) mag_data.quiver_plot('z-projection', proj_axis='z') -mag_data.quiver_plot('x-projection', proj_axis='x') -mag_data.quiver_plot3d() +mag_data.quiver_plot('y-projection', proj_axis='y') mag_data.save_to_llg(filename) +mag_data.quiver_plot3d() phase_map_z = PMConvolve(a, SimpleProjector(dim, axis='z'))(mag_data) phase_map_x = PMConvolve(a, SimpleProjector(dim, axis='x'))(mag_data) -phase_map_z.display_holo(density, 'Core-Shell structure (z-proj.)') -phase_axis, holo_axis = phase_map_x.display_combined(density, 'Core-Shell structure (x-proj.)') +phase_map_z.display_holo('Core-Shell structure (z-proj.)', density=1E2) +phase_axis, holo_axis = phase_map_x.display_combined('Core-Shell structure (x-proj.)', density=1E3) phase_axis.set_xlabel('y [nm]') phase_axis.set_ylabel('z [nm]') holo_axis.set_xlabel('y-axis [px]') diff --git a/scripts/create distributions/create_core_shell_sphere.py b/scripts/create distributions/create_core_shell_sphere.py index d2dbe8a..d6033cc 100644 --- a/scripts/create distributions/create_core_shell_sphere.py +++ b/scripts/create distributions/create_core_shell_sphere.py @@ -29,7 +29,6 @@ if not os.path.exists(directory): # Input parameters: filename = directory + '/mag_dist_core_shell_sphere.txt' a = 1.0 # in nm -density = 500 dim = (32, 32, 32) center = (dim[0]/2-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5) radius_core = dim[1]/8 @@ -43,12 +42,12 @@ mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape_shell, magnitude=0.75) mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_core, phi=0, theta=0)) mag_data.quiver_plot('z-projection', proj_axis='z') mag_data.quiver_plot('x-projection', proj_axis='x') -mag_data.quiver_plot3d() mag_data.save_to_llg(filename) +mag_data.quiver_plot3d() phase_map_z = PMConvolve(a, SimpleProjector(dim, axis='z'))(mag_data) phase_map_x = PMConvolve(a, SimpleProjector(dim, axis='x'))(mag_data) -phase_map_z.display_holo(density, 'Core-Shell structure (z-proj.)') -phase_axis, holo_axis = phase_map_x.display_combined(density, 'Core-Shell structure (x-proj.)') +phase_map_z.display_holo('Core-Shell structure (z-proj.)', density=1E2) +phase_axis, holo_axis = phase_map_x.display_combined('Core-Shell structure (x-proj.)', density=1E3) phase_axis.set_xlabel('y [nm]') phase_axis.set_ylabel('z [nm]') holo_axis.set_xlabel('y-axis [px]') diff --git a/scripts/create distributions/create_sample.py b/scripts/create distributions/create_sample.py index b69ad17..949d852 100644 --- a/scripts/create distributions/create_sample.py +++ b/scripts/create distributions/create_sample.py @@ -24,12 +24,12 @@ if not os.path.exists(directory): os.makedirs(directory) ################################################################################################### # Input parameters: -key = 'sphere' +key = 'slab' ################################################################################################### filename = directory + '/mag_dist_' + key + '.txt' -dim = (64, 64, 64) # in px (z, y, x) +dim = (32, 32, 32) # in px (z, y, x) a = 1.0 # in nm -phi = pi/2 +phi = pi/4 # Geometry parameters: center = (dim[0]/2-0.5, dim[1]/2-0.5, dim[2]/2-0.5) # in px (z, y, x), index starts with 0! width = (dim[0]/2, dim[1]/2, dim[2]/2) # in px (z, y, x) @@ -49,7 +49,7 @@ elif key == 'filament': elif key == 'pixel': mag_shape = mc.Shapes.pixel(dim, pixel) # Create magnetic distribution -magnitude = mc.create_mag_dist_homog(mag_shape, phi) -mag_data = MagData(a, magnitude) -mag_data.quiver_plot() +mag_data = MagData(a, mc.create_mag_dist_homog(mag_shape, phi, magnitude=0.75)) mag_data.save_to_llg(filename) +mag_data.quiver_plot() +mag_data.quiver_plot3d() diff --git a/scripts/create distributions/create_vortex.py b/scripts/create distributions/create_vortex.py index cd70c5f..699832f 100644 --- a/scripts/create distributions/create_vortex.py +++ b/scripts/create distributions/create_vortex.py @@ -28,13 +28,14 @@ if not os.path.exists(directory): filename = directory + '/mag_dist_vortex.txt' a = 10.0 # in nm # density = 1 -dim = (64, 64, 64) +dim = (32, 32, 32) center = (int(dim[0]/2)-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5) +print 'center', center radius = 0.25 * dim[1] height = dim[0]/4 # Create magnetic shape: mag_shape = mc.Shapes.disc(dim, center, radius, height) -mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape)) +mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape, magnitude=0.75)) mag_data.quiver_plot() mag_data.save_to_llg(filename) projector = SimpleProjector(dim) @@ -44,3 +45,4 @@ phase_slice = phase_map.phase[dim[1]/2, :] fig = plt.figure() fig.add_subplot(111) plt.plot(range(dim[1]), phase_slice) +mag_data.quiver_plot3d() diff --git a/scripts/gui/create_logo.py b/scripts/gui/create_logo.py deleted file mode 100644 index b7269a2..0000000 --- a/scripts/gui/create_logo.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- - -# Form implementation generated from reading ui file 'create_logo.ui' -# -# Created: Tue May 21 14:29:03 2013 -# by: PyQt4 UI code generator 4.9.5 -# -# WARNING! All changes made in this file will be lost! - - -from PyQt4 import QtCore, QtGui -from matplotlibwidget import MatplotlibWidget - - -try: - _fromUtf8 = QtCore.QString.fromUtf8 -except AttributeError: - _fromUtf8 = lambda s: s - - -class Ui_CreateLogoWidget(object): - def setupUi(self, CreateLogoWidget): - CreateLogoWidget.setObjectName(_fromUtf8("CreateLogoWidget")) - CreateLogoWidget.resize(520, 492) - self.verticalLayout_2 = QtGui.QVBoxLayout(CreateLogoWidget) - self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) - self.verticalLayout = QtGui.QVBoxLayout() - self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) - self.horizontalLayout = QtGui.QHBoxLayout() - self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) - self.xLabel = QtGui.QLabel(CreateLogoWidget) - self.xLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.xLabel.setObjectName(_fromUtf8("xLabel")) - self.horizontalLayout.addWidget(self.xLabel) - self.xSpinBox = QtGui.QSpinBox(CreateLogoWidget) - self.xSpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.xSpinBox.setMaximum(512) - self.xSpinBox.setProperty("value", 128) - self.xSpinBox.setObjectName(_fromUtf8("xSpinBox")) - self.horizontalLayout.addWidget(self.xSpinBox) - self.yLabel = QtGui.QLabel(CreateLogoWidget) - self.yLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.yLabel.setObjectName(_fromUtf8("yLabel")) - self.horizontalLayout.addWidget(self.yLabel) - self.ySpinBox = QtGui.QSpinBox(CreateLogoWidget) - self.ySpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.ySpinBox.setMaximum(512) - self.ySpinBox.setProperty("value", 128) - self.ySpinBox.setObjectName(_fromUtf8("ySpinBox")) - self.horizontalLayout.addWidget(self.ySpinBox) - self.logoPushButton = QtGui.QPushButton(CreateLogoWidget) - self.logoPushButton.setObjectName(_fromUtf8("logoPushButton")) - self.horizontalLayout.addWidget(self.logoPushButton) - self.verticalLayout.addLayout(self.horizontalLayout) - self.verticalLayout_2.addLayout(self.verticalLayout) - self.mplWidget = MatplotlibWidget(CreateLogoWidget) - self.mplWidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor)) - self.mplWidget.setLayoutDirection(QtCore.Qt.LeftToRight) - self.mplWidget.setAutoFillBackground(False) - self.mplWidget.setObjectName(_fromUtf8("mplWidget")) - self.verticalLayout_2.addWidget(self.mplWidget) - - self.retranslateUi(CreateLogoWidget) - QtCore.QMetaObject.connectSlotsByName(CreateLogoWidget) - - def retranslateUi(self, CreateLogoWidget): - CreateLogoWidget.setWindowTitle(QtGui.QApplication.translate("CreateLogoWidget", "Form", None, QtGui.QApplication.UnicodeUTF8)) - self.xLabel.setText(QtGui.QApplication.translate("CreateLogoWidget", "X [px] :", None, QtGui.QApplication.UnicodeUTF8)) - self.yLabel.setText(QtGui.QApplication.translate("CreateLogoWidget", "Y [px] :", None, QtGui.QApplication.UnicodeUTF8)) - self.logoPushButton.setText(QtGui.QApplication.translate("CreateLogoWidget", "Create Logo", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/scripts/gui/create_logo.ui b/scripts/gui/create_logo.ui deleted file mode 100644 index e785b90..0000000 --- a/scripts/gui/create_logo.ui +++ /dev/null @@ -1,102 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>CreateLogoWidget</class> - <widget class="QWidget" name="CreateLogoWidget"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>520</width> - <height>492</height> - </rect> - </property> - <property name="windowTitle"> - <string>Create Pyramid Logo</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="xLabel"> - <property name="text"> - <string>X [px] :</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="xSpinBox"> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - <property name="maximum"> - <number>512</number> - </property> - <property name="value"> - <number>128</number> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="yLabel"> - <property name="text"> - <string>Y [px] :</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="ySpinBox"> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - <property name="maximum"> - <number>512</number> - </property> - <property name="value"> - <number>128</number> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="logoPushButton"> - <property name="text"> - <string>Create Logo</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="MatplotlibWidget" name="mplWidget"> - <property name="cursor"> - <cursorShape>ArrowCursor</cursorShape> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="autoFillBackground"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>MatplotlibWidget</class> - <extends>QWidget</extends> - <header>matplotlibwidget</header> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> diff --git a/scripts/gui/gui_create_logo.py b/scripts/gui/gui_create_logo.py deleted file mode 100644 index 3e00bf5..0000000 --- a/scripts/gui/gui_create_logo.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -"""Create the Pyramid-Logo via GUI-Input.""" - - -import sys -import numpy as np -from numpy import pi -from PyQt4 import QtCore, QtGui, uic - -import pyramid.magcreator as mc -from pyramid.projector import SimpleProjector -from pyramid.phasemapper import PMConvolve -from pyramid.magdata import MagData - -from create_logo import Ui_CreateLogoWidget - - -class Overlay(QtGui.QWidget): - def __init__(self, parent=None): - QtGui.QWidget.__init__(self, parent) - palette = QtGui.QPalette(self.palette()) - palette.setColor(palette.Background, QtCore.Qt.transparent) - self.setPalette(palette) - - def paintEvent(self, event): - painter = QtGui.QPainter() - painter.begin(self) - painter.setRenderHint(QtGui.QPainter.Antialiasing) - painter.fillRect(event.rect(), QtGui.QBrush(QtGui.QColor(255, 255, 255, 127))) - painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) - for i in range(6): - if (self.counter / 5) % 6 == i: - painter.setBrush(QtGui.QBrush(QtGui.QColor(127, 127 + (self.counter % 5)*32, 127))) - else: - painter.setBrush(QtGui.QBrush(QtGui.QColor(127, 127, 127))) - painter.drawEllipse( - self.width()/2 + 30 * np.cos(2 * pi * i / 6.0) - 10, - self.height()/2 + 30 * np.sin(2 * pi * i / 6.0) - 10, - 20, 20) - painter.end() - - def showEvent(self, event): - self.timer = self.startTimer(50) - self.counter = 0 - - def hideEvent(self, event): - self.killTimer(self.timer) - - def timerEvent(self, event): - self.counter += 1 - self.update() - - -class CreateLogoWidget(QtGui.QWidget, Ui_CreateLogoWidget): - - def __init__(self): - # Call parent constructor - QtGui.QWidget.__init__(self) - self.setupUi(self) - self.ui = uic.loadUi('create_logo.ui') -# self.setCentralWidget(self.ui) - # Connect Widgets with locally defined functions: - self.connect(self.logoPushButton, QtCore.SIGNAL('clicked()'), self.buttonPushed) - # Create overlay to indicate busy state: - self.overlay = Overlay(self) -# self.ui.overlay = Overlay(self.ui) - self.overlay.hide() - # Show Widget: - self.show() - - self.workerThread = WorkerThread() - - def buttonPushed(self): - self.overlay.show() - x = self.xSpinBox.value() - y = self.ySpinBox.value() - create_logo((1, y, x), self.mplWidget.axes) - self.mplWidget.draw() -# self.workerThread.start() - self.overlay.hide() - - def resizeEvent(self, event): - self.overlay.resize(event.size()) - event.accept() - - -class WorkerThread(QtCore.QThread): - - def __init__(self, parent=None): - QtCore.QThread.__init__(self) - - def run(self): - x = self.xSpinBox.value() - y = self.ySpinBox.value() - create_logo((1, y, x), self.mplWidget.axes) - self.mplWidget.draw() - - -def create_logo(dim, axis): - '''Calculate and display the Pyramid-Logo.''' - # Input parameters: - a = 10.0 # in nm - phi = -pi/2 # in rad - density = 10 - # Create magnetic shape: - mag_shape = np.zeros(dim) - x = range(dim[2]) - y = range(dim[1]) - xx, yy = np.meshgrid(x, y) - bottom = (yy >= 0.25*dim[1]) - left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx) - right = np.fliplr(left) - mag_shape[0, ...] = np.logical_and(np.logical_and(left, right), bottom) - # Create magnetic data, project it, get the phase map and display the holography image: - mag_data = MagData(a, mc.create_mag_dist_homog(mag_shape, phi)) - phase_map = PMConvolve(a, SimpleProjector(dim))(mag_data) - phase_map.display_holo(density, 'PYRAMID - LOGO', interpolation='bilinear', - axis=axis, show=False) - - -if __name__ == '__main__': - app = QtGui.QApplication(sys.argv) - gui = CreateLogoWidget() - sys.exit(app.exec_()) diff --git a/scripts/gui/mag_slicer.py b/scripts/gui/mag_slicer.py new file mode 100644 index 0000000..fcce907 --- /dev/null +++ b/scripts/gui/mag_slicer.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'mag_slicer2.ui' +# +# Created: Sun Aug 31 20:39:52 2014 +# by: PyQt4 UI code generator 4.9.6 +# +# WARNING! All changes made in this file will be lost! + + +import sys + +from PyQt4 import QtCore, QtGui + +from matplotlibwidget import MatplotlibWidget + +from pyramid.magdata import MagData + + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + def _fromUtf8(s): + return s + +try: + _encoding = QtGui.QApplication.UnicodeUTF8 + + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig, _encoding) + +except AttributeError: + + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig) + + +class UI_MagSlicerMain(QtGui.QWidget): + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + Form = self + self.setGeometry(100, 100, 650, 650) + self.setWindowTitle('Mag Slicer') + self.gridLayout = QtGui.QGridLayout(Form) + self.gridLayout.setObjectName(_fromUtf8("gridLayout")) + self.horizontalLayout = QtGui.QHBoxLayout() + self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) + self.pushButton = QtGui.QPushButton(Form) + self.pushButton.setObjectName(_fromUtf8("pushButton")) + self.horizontalLayout.addWidget(self.pushButton) + self.scaleCheckBox = QtGui.QCheckBox(Form) + self.scaleCheckBox.setChecked(True) + self.scaleCheckBox.setTristate(False) + self.scaleCheckBox.setObjectName(_fromUtf8("scaleCheckBox")) + self.horizontalLayout.addWidget(self.scaleCheckBox) + self.logCheckBox = QtGui.QCheckBox(Form) + self.logCheckBox.setObjectName(_fromUtf8("logCheckBox")) + self.horizontalLayout.addWidget(self.logCheckBox) + self.comboBox = QtGui.QComboBox(Form) + self.comboBox.setObjectName(_fromUtf8("comboBox")) + self.comboBox.addItem(_fromUtf8("")) + self.comboBox.addItem(_fromUtf8("")) + self.comboBox.addItem(_fromUtf8("")) + self.horizontalLayout.addWidget(self.comboBox) + self.label = QtGui.QLabel(Form) + self.label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | + QtCore.Qt.AlignVCenter) + self.label.setObjectName(_fromUtf8("label")) + self.horizontalLayout.addWidget(self.label) + self.spinBox = QtGui.QSpinBox(Form) + self.spinBox.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | + QtCore.Qt.AlignVCenter) + self.spinBox.setMaximum(0) + self.spinBox.setProperty("value", 0) + self.spinBox.setObjectName(_fromUtf8("spinBox")) + self.horizontalLayout.addWidget(self.spinBox) + self.scrollBar = QtGui.QScrollBar(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.scrollBar.sizePolicy().hasHeightForWidth()) + self.scrollBar.setSizePolicy(sizePolicy) + self.scrollBar.setMaximum(0) + self.scrollBar.setOrientation(QtCore.Qt.Horizontal) + self.scrollBar.setObjectName(_fromUtf8("scrollBar")) + self.horizontalLayout.addWidget(self.scrollBar) + self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1) + self.mplWidget = MatplotlibWidget(Form) + self.mplWidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor)) + self.mplWidget.setLayoutDirection(QtCore.Qt.LeftToRight) + self.mplWidget.setAutoFillBackground(False) + self.mplWidget.setObjectName(_fromUtf8("mplWidget")) + self.gridLayout.addWidget(self.mplWidget, 1, 0, 1, 1) + self.retranslateUi(Form) + self.connect(self.scrollBar, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")), + self.spinBox.setValue) + self.connect(self.spinBox, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")), + self.scrollBar.setValue) + self.connect(self.logCheckBox, QtCore.SIGNAL(_fromUtf8('clicked()')), + self.update_plot) + self.connect(self.scaleCheckBox, QtCore.SIGNAL(_fromUtf8('clicked()')), + self.update_plot) + self.connect(self.spinBox, QtCore.SIGNAL(_fromUtf8('valueChanged(int)')), + self.update_plot) + self.connect(self.comboBox, QtCore.SIGNAL(_fromUtf8('currentIndexChanged(int)')), + self.update_ui) + self.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8('clicked()')), + self.load) + QtCore.QMetaObject.connectSlotsByName(Form) + + def retranslateUi(self, Form): + Form.setWindowTitle(_translate("Form", "Mag Slicer", None)) + self.pushButton.setText(_translate("Form", "Laden", None)) + self.scaleCheckBox.setText(_translate("Form", "Scaled", None)) + self.logCheckBox.setText(_translate("Form", "Log", None)) + self.comboBox.setItemText(0, _translate("Form", "xy-plane", None)) + self.comboBox.setItemText(1, _translate("Form", "xz-plane", None)) + self.comboBox.setItemText(2, _translate("Form", "zy-plane", None)) + self.label.setText(_translate("Form", "Slice:", None)) + + def update_ui(self): + if self.mag_data_loaded: + mode_ind = self.comboBox.currentIndex() + if mode_ind == 0: + self.mode = 'z' + length = self.mag_data.dim[0]-1 + elif mode_ind == 1: + self.mode = 'y' + length = self.mag_data.dim[1]-1 + else: + self.mode = 'x' + length = self.mag_data.dim[2]-1 + self.spinBox.setMaximum(length) + self.scrollBar.setMaximum(length) + self.spinBox.setValue(int(length/2.)) + self.update_plot() + + def update_plot(self): + if self.mag_data_loaded: + self.mag_data.quiver_plot(axis=self.mplWidget.axes, proj_axis=self.mode, + ax_slice=self.spinBox.value(), + log=self.logCheckBox.isChecked(), + scaled=self.scaleCheckBox.isChecked(), + show=False) + self.mplWidget.draw() + + def load(self): + mag_file = QtGui.QFileDialog.getOpenFileName(self, 'Open Data File', '', + 'NetCDF files (*.nc)') + self.mag_data = MagData.load_from_netcdf4(mag_file) + self.mag_data_loaded = True + self.comboBox.setCurrentIndex(0) + self.update_ui() + + +if __name__ == '__main__': + app = QtGui.QApplication(sys.argv) + widget = UI_MagSlicerMain() + widget.show() + sys.exit(app.exec_()) diff --git a/scripts/gui/mag_slicer.ui b/scripts/gui/mag_slicer.ui new file mode 100644 index 0000000..030f735 --- /dev/null +++ b/scripts/gui/mag_slicer.ui @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>652</width> + <height>646</height> + </rect> + </property> + <property name="windowTitle"> + <string>Mag Slicer</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Laden</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="scaleCheckBox"> + <property name="text"> + <string>Scaled</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="tristate"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="logCheckBox"> + <property name="text"> + <string>Log</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="comboBox"> + <item> + <property name="text"> + <string>xy-plane</string> + </property> + </item> + <item> + <property name="text"> + <string>xz-plane</string> + </property> + </item> + <item> + <property name="text"> + <string>zy-plane</string> + </property> + </item> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Slice:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinBox"> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="maximum"> + <number>0</number> + </property> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item> + <widget class="QScrollBar" name="scrollBar"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximum"> + <number>0</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="MatplotlibWidget" name="mplWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursorShape>ArrowCursor</cursorShape> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>MatplotlibWidget</class> + <extends>QWidget</extends> + <header>matplotlibwidget</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/scripts/reconstruction/reconstruct_random_pixels.py b/scripts/reconstruction/reconstruct_random_pixels.py index ca7e212..65c5289 100644 --- a/scripts/reconstruction/reconstruct_random_pixels.py +++ b/scripts/reconstruction/reconstruct_random_pixels.py @@ -46,7 +46,7 @@ phase_map = PMConvolve(a, SimpleProjector(dim), b_0)(mag_data) phase_map.display_combined('Generated Distribution', density=10) # Reconstruct the magnetic distribution: -mag_data_rec = rc.optimize_simple_leastsq(phase_map, mag_data.get_mask(), b_0) +mag_data_rec = rc.optimize_simple_leastsq(phase_map, mag_data.get_mask(), b_0, lam=1E-4, order=1) # Display the reconstructed phase map and holography image: phase_map_rec = PMConvolve(a, SimpleProjector(dim), b_0)(mag_data_rec) -- GitLab