![]() ![]() palette_canvas = Canvas ( master, width = c_width, height = palette_height ) self. pack () # The palette for selecting colours. c_width, c_height = width, height p_pad = 5 p_width = p_height = palette_height - 2 * p_pad # The main frame onto which we draw the App's elements. pad = pad xsize = ( width - npad * pad ) / n ysize = ( height - npad * pad ) / n # Canvas dimensions for the cell grid and the palette. height = width, height palette_height = 40 # Padding stuff: xsize, ysize is the cell size in pixels (without pad). n = n # Some dimensions for the App in pixels. # Maximum and default grid size MAX_N, DEFAULT_N = 26, 10 # The "default" colour for an unfilled grid cell UNFILLED = '#fff' class GridApp : """The main class representing a grid of coloured cells.""" # The colour palette colours = ( UNFILLED, 'red', 'green', 'blue', 'cyan', 'orange', 'yellow', 'magenta', 'brown', 'black' ) ncolours = len ( colours ) def _init_ ( self, master, n, width = 600, height = 600, pad = 5 ): """Initialize a grid and the Tk Frame on which it is rendered.""" # Number of cells in each dimension. Import sys from tkinter import * from tkinter import filedialog # A simple colouring grid app, with load/save functionality. rotate_from_angax ( angle = angs, axis = 'y', anchor = 0 ) magpy. Sensor ( position = ( - 5, 0, 0 )) angs = np. rotate_from_angax ( angle = 45, axis = ( 1, 1, 1 )) # add a sensor for testing sensor = magpy. showdefault = False # apply some geometric manipulation for src in : src. array () trace = dict ( backend = 'matplotlib', constructor = 'plot', args = ( xs, ys, zs ), kwargs =, ) custom. CustomSource ( field_func = interpolate_field ( data )) xs = 1.1 * np. getB ( grid ))) # create custom source with nice 3D model custom = magpy. # create data for interpolation cube = magpy. In this example, the data for the interpolation is generated from a known cuboid field, which makes it easy to verify this approach afterwards. In the second step we create a custom source with an interpolated field as get_B_lambda input. ![]() T return field_func Custom source with interpolation field # ![]() append ( rgi ) def field_func ( field, observers ): return np. reshape ( nx, ny, nz ), ** kwargs ) field_interp. unique ( z ) nx, ny, nz = len ( X ), len ( Y ), len ( Z ) # construct interpolation with RegularGridInterpolator field_interp = kwargs = dict ( bounds_error = bounds_error, fill_value = fill_value, method = method ) for f in field_vec : rgi = RegularGridInterpolator (( X, Y, Z ), f. lexsort (( data, data, data )) # sort data by x,y,z x, y, z, * field_vec = data. Returns - callable: interpolating function for field values """ # condition input data data = np. ![]() fill_value : number, optional Value returned when points outside the interpolation domain are sampled. bounds_error : bool, optional If True, when interpolated values are requested outside of the domain of the input data, a ValueError is raised. method : str, optional The method of interpolation to perform. nan ): """ Creates a 3D-vector field interpolation from regular grid data Parameters - data: array_like, shape (n,6) The first dimension is a flattened regular grid, the second dimension corresponds to positions x, y, z, then field Bx, By, Bz in this order. Import numpy as np from scipy.interpolate import RegularGridInterpolator import magpylib as magpy def interpolate_field ( data, method = "linear", bounds_error = False, fill_value = np. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |