<jupyter_start><jupyter_text>Grids: Non-Uniform Grids Some data cannot be easily represented on a grid of uniformly spaced vertices. It is still possible to create a grid object to represent such a dataset.<jupyter_code>%matplotlib inline

import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np

from plasmapy.plasma import grids
grid = grids.NonUniformCartesianGrid(np.array([-1, -1, -1])*u.cm, np.array([1, 1, 1])*u.cm, num=(50, 50, 50))<jupyter_output><empty_output><jupyter_text>Currently, all non-uniform data is stored as an unordered 1D array of points. Therefore, although the dataset created above falls approximately on a Cartesian grid, its treatment is identical to a completely unordered set of points<jupyter_code>grid.shape<jupyter_output><empty_output><jupyter_text>Many of the properties defined for uniform grids are inaccessible for non-uniform grids. For example, it is not possible to pull out an axis. However, the following properties still apply<jupyter_code>print(f"Grid points: {grid.grid.shape}")
print(f"Units: {grid.units}")<jupyter_output><empty_output><jupyter_text>Properties can be added in the same way as on uniform grids.<jupyter_code>Bx = np.random.rand(*grid.shape)*u.T
grid.add_quantities(B_x=Bx)
print(grid)<jupyter_output><empty_output><jupyter_text>Nearest-neighbor interpolation also works identically. However, volume-weighted interpolation is not implemented for non-uniform grids.<jupyter_code>pos = np.array([[0.1, -0.3, 0], [0.5, .25, .8]]) * u.cm
print(f"Pos shape: {pos.shape}")
print(f"Position 1: {pos[0,:]}")
print(f"Position 2: {pos[1,:]}")

Ex_vals = grid.nearest_neighbor_interpolator(pos, "B_x")
print(f"Bx at position 1: {Ex_vals[0]:.2f}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11606632361349342, 'fraction_numerical': 0.017152658662092625, 'mean_word_length': 6.641921397379913, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '360587', 'license': 'MIT', 'n_tokens_mistral': 608, 'n_tokens_neox': 585, 'n_words': 177, 'path': 'docs/notebooks/plasma/grids_nonuniform.ipynb', 'repo_name': 'cfe316/PlasmaPy', 'size': '1749'}