def field2topological_density(field, slice_axis, slice_coord): """ field2topological_density(field, slice_axis, slice_coord) This function constructs a Holoviews object which shows the topological density. Inputs ====== field: Path to an OMF file or object of type disc.Field slice_axis: The axis along which the vector field will be sliced given as a string. Must be one of ['x', 'y', 'z'] slice_coord: The coordinate along the slice_axis where the field is sliced """ # Construct a field object if not a field object if isinstance(field, str): field = discretisedfield.read_oommf_file(field, normalisedto=1) field.normalise() if slice_axis == 'z': axis = (0, 1, 2) elif slice_axis == 'y': axis = (0, 2, 1) elif slice_axis == 'x': axis = (1, 2, 0) else: raise ValueError("Slice Axis must be one of 'x', 'y' ,'z'") dims = ['x', 'y', 'z'] bounds = [field.mesh.p1[axis[0]], field.mesh.p1[axis[1]], field.mesh.p2[axis[0]], field.mesh.p2[axis[1]]] x, y, vec, coords = field.slice_field(slice_axis, slice_coord) shape = np.shape(vec)[0], np.shape(vec)[1] mbig = np.zeros((shape[0] + 2, shape[1] + 2, 3)) mbig[1:-1, 1:-1] = vec Q = np.zeros((shape[0] + 2, shape[1] + 2)) print(shape) for i in range(1, shape[0]+1): for j in range(1, shape[1]+1): Q[i, j] = (mbig[i, j].dot(np.cross(mbig[i+1, j], mbig[i, j+1])) + mbig[i, j].dot(np.cross(mbig[i-1, j], mbig[i, j-1])) - mbig[i, j].dot(np.cross(mbig[i-1, j], mbig[i, j+1])) - mbig[i, j].dot(np.cross(mbig[i+1, j], mbig[i, j-1])) ) return hv.Image(Q[1:-1, 1:-1], label='Topological Density', bounds=bounds, kdims=[dims[axis[0]], dims[axis[1]]], vdims=[hv.Dimension('Q_{}'.format(slice_axis))])
def _update_m(self, system): # Find last omf file. dirname = self._filenames(system)["dirname"] last_omf_file = max(glob.iglob("{}*.omf".format(dirname)), key=os.path.getctime) # Update system's magnetisaton. m_field = df.read_oommf_file(last_omf_file) m_field.normalisedto = system.m.normalisedto m_field.normalise() system.m = m_field
def field2topological_density(field, slice_axis, slice_coord): """ field2topological_density(field, slice_axis, slice_coord) This function constructs a Holoviews object which shows the topological density. Inputs ====== field: Path to an OMF file or object of type disc.Field slice_axis: The axis along which the vector field will be sliced given as a string. Must be one of ['x', 'y', 'z'] slice_coord: The coordinate along the slice_axis where the field is sliced """ # Construct a field object if not a field object if isinstance(field, str): field = discretisedfield.read_oommf_file(field, normalisedto=1) field.normalise() if slice_axis == 'z': axis = (0, 1, 2) elif slice_axis == 'y': axis = (0, 2, 1) elif slice_axis == 'x': axis = (1, 2, 0) else: raise ValueError("Slice Axis must be one of 'x', 'y' ,'z'") dims = ['x', 'y', 'z'] bounds = [ field.mesh.p1[axis[0]], field.mesh.p1[axis[1]], field.mesh.p2[axis[0]], field.mesh.p2[axis[1]] ] x, y, vec, coords = field.slice_field(slice_axis, slice_coord) shape = np.shape(vec)[0], np.shape(vec)[1] mbig = np.zeros((shape[0] + 2, shape[1] + 2, 3)) mbig[1:-1, 1:-1] = vec Q = np.zeros((shape[0] + 2, shape[1] + 2)) print(shape) for i in range(1, shape[0] + 1): for j in range(1, shape[1] + 1): Q[i, j] = (mbig[i, j].dot(np.cross(mbig[i + 1, j], mbig[i, j + 1])) + mbig[i, j].dot(np.cross(mbig[i - 1, j], mbig[i, j - 1])) - mbig[i, j].dot(np.cross(mbig[i - 1, j], mbig[i, j + 1])) - mbig[i, j].dot(np.cross(mbig[i + 1, j], mbig[i, j - 1]))) return hv.Image(Q[1:-1, 1:-1], label='Topological Density', bounds=bounds, kdims=[dims[axis[0]], dims[axis[1]]], vdims=[hv.Dimension('Q_{}'.format(slice_axis))])
def update_plot(self, value): self.out.clear_output(wait=True) omffile = self.find_omf_file() field = df.read_oommf_file(omffile) slice_index = {"x": 0, "y": 1, "z": 2}[self.select.value] point = field.mesh.pmin[ slice_index] + self.slice_slider.value * field.mesh.l[slice_index] field.plot_slice(self.select.value, point, xsize=10) with self.out: display(plt.gcf()) plt.close()
def __init__(self, name): self.dirname = os.path.join(name, "") odtfile = max(glob.iglob("{}*.odt".format(self.dirname)), key=os.path.getctime) self.omffiles = sorted(glob.iglob("{}*.omf".format(self.dirname)), key=os.path.getctime) last_omf_file = max(glob.iglob("{}*.omf".format(self.dirname)), key=os.path.getctime) self.last_field = df.read_oommf_file(last_omf_file) self.dt = oommfodt.OOMMFodt(odtfile).df self.stage = self.dt["stage"].as_matrix() self.slider = ipywidgets.IntSlider( value=self.stage[0], min=self.stage[0], max=self.stage[-1], step=self.stage[1] - self.stage[0], description="Stage:", readout=True, layout=ipywidgets.Layout(width="80%"), continuous_update=False) self.slice_slider = ipywidgets.FloatSlider( value=0, min=0, max=1, step=0.01, description="Point:", readout=True, layout=ipywidgets.Layout(width="75.5%"), continuous_update=False) self.play = ipywidgets.Play(value=self.stage[0], min=self.stage[0], max=self.stage[-1], step=self.stage[1] - self.stage[0]) self.select = ipywidgets.RadioButtons(options=["x", "y", "z"], description="Slice:") ipywidgets.jslink((self.play, "value"), (self.slider, "value")) self.slider.observe(self.update_plot) self.slice_slider.observe(self.update_plot) self.select.observe(self.update_plot) self.out = ipywidgets.Output(layout=ipywidgets.Layout(width="300%")) self.update_plot(None)
def field2inplane_angle(field, slice_axis, slice_coord): """ field2hv(field, slice_axis, slice_coord) This function constructs a Holoviews object which shows the in plane Magnetisation and out of plane Magnetisation Inputs ====== field: Path to an OMF file or object of type discretisedfield.Field slice_axis: The axis along which the vector field will be sliced given as a string. Must be one of ['x', 'y', 'z'] slice_coord: The coordinate along the slice_axis where the field is sliced """ # Construct a field object if not a field object if isinstance(field, str): field = discretisedfield.read_oommf_file(field, normalisedto=1) field.normalise() if slice_axis == 'z': axis = (0, 1, 2) elif slice_axis == 'y': axis = (0, 2, 1) elif slice_axis == 'x': axis = (1, 2, 0) else: raise ValueError("Slice Axis must be one of 'x', 'y' ,'z'") dims = ['x', 'y', 'z'] bounds = [ field.mesh.p1[axis[0]], field.mesh.p1[axis[1]], field.mesh.p2[axis[0]], field.mesh.p2[axis[1]] ] x, y, vec, coords = field.slice_field(slice_axis, slice_coord) X, Y = np.meshgrid(x, y) flat = vec.flatten() angm = np.pi + np.arctan2(flat[axis[1]::3], flat[axis[0]::3]).reshape( (len(x), len(y))) kdims = [dims[axis[0]], dims[axis[1]]] return hv.Image(angm, bounds=bounds, kdims=kdims, label='In-plane Magnetisation angle', vdims=[ hv.Dimension('xyfield'.format(slice_axis), range=(0, 2 * np.pi)) ])
def field2inplane_angle(field, slice_axis, slice_coord): """ field2hv(field, slice_axis, slice_coord) This function constructs a Holoviews object which shows the in plane Magnetisation and out of plane Magnetisation Inputs ====== field: Path to an OMF file or object of type discretisedfield.Field slice_axis: The axis along which the vector field will be sliced given as a string. Must be one of ['x', 'y', 'z'] slice_coord: The coordinate along the slice_axis where the field is sliced """ # Construct a field object if not a field object if isinstance(field, str): field = discretisedfield.read_oommf_file(field, normalisedto=1) field.normalise() if slice_axis == 'z': axis = (0, 1, 2) elif slice_axis == 'y': axis = (0, 2, 1) elif slice_axis == 'x': axis = (1, 2, 0) else: raise ValueError("Slice Axis must be one of 'x', 'y' ,'z'") dims = ['x', 'y', 'z'] bounds = [field.mesh.p1[axis[0]], field.mesh.p1[axis[1]], field.mesh.p2[axis[0]], field.mesh.p2[axis[1]]] x, y, vec, coords = field.slice_field(slice_axis, slice_coord) X, Y = np.meshgrid(x, y) flat = vec.flatten() angm = np.pi + np.arctan2(flat[axis[1]::3], flat[axis[0]::3]).reshape((len(x), len(y))) kdims = [dims[axis[0]], dims[axis[1]]] return hv.Image(angm, bounds=bounds, kdims=kdims, label='In-plane Magnetisation angle', vdims=[hv.Dimension('xyfield'.format(slice_axis), range=(0, 2*np.pi))])