Plot a slice combining data from two datasets
Hi all, I want a slice plot of pressure(x, y, z = 0, t) - pressure(x, y, z = 0, t = 0). I tried using a derived field as follows: ---- # Load the initial dataset ds0 = yt.load('my t=0 dataset') p0 = initialPressure = ds0.all_data()['pressure'] # Define the derived field def _perturbationPressure(field, data): return data['pressure'] - initialPressure # Add the derived field yt.add_field(('gas', 'perturbationPressure'), function=_perturbationPressure, units = "auto", dimensions = yt.units.dimensions.pressure) # Load the dataset of interest ds = yt.load('my dataset') yt.SlicePlot(ds, 'z', 'perturbationPressure') ---- The error:
ValueError: operands could not be broadcast together with shapes (16,16,16) (134217728,)
I noticed the "data" in the definition of the derived field is a FieldDetector, so I'm not sure how I should define the derived field to plot the pressure difference (if using a derived field is the right approach at all!). The dataset I'm trying to plot is from FLASH, and I'm running yt 3.6.0. Thanks!
Hi Ricardo, This is a tricky question. If you want this to be done on a cell-by-cell basis, and the AMR structure of the two datasets is not precisely identical, you'll need to put the two datasets onto a regular grid by doing something like: ds.r[::128j,::128j,::128j] . But if they have identical grid structures, you might be able to get around this by using a ValidateSpatial() validator and then using ID lookup on data.id. I think the former is morel likely to work than the latter, though. Can you try that? On Thu, Apr 23, 2020 at 4:17 AM Ricardo Y <richardlol1024@gmail.com> wrote:
Hi all,
I want a slice plot of pressure(x, y, z = 0, t) - pressure(x, y, z = 0, t = 0). I tried using a derived field as follows:
---- # Load the initial dataset ds0 = yt.load('my t=0 dataset') p0 = initialPressure = ds0.all_data()['pressure']
# Define the derived field def _perturbationPressure(field, data): return data['pressure'] - initialPressure
# Add the derived field yt.add_field(('gas', 'perturbationPressure'), function=_perturbationPressure, units = "auto", dimensions = yt.units.dimensions.pressure)
# Load the dataset of interest ds = yt.load('my dataset') yt.SlicePlot(ds, 'z', 'perturbationPressure') ----
The error:
ValueError: operands could not be broadcast together with shapes (16,16,16) (134217728,)
I noticed the "data" in the definition of the derived field is a FieldDetector, so I'm not sure how I should define the derived field to plot the pressure difference (if using a derived field is the right approach at all!). The dataset I'm trying to plot is from FLASH, and I'm running yt 3.6.0. Thanks! _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Hi Matthew, I forgot to mention this simulation is on an uniform grid. It's not clear to me how to do it the ValidateSpatial() way, but using ds.r like you suggested worked. Thank you!
Ricardo, That's great -- would you mind putting your example code here so folks can see, and if it comes up again it'll show up in the archives? On Sun, Apr 26, 2020 at 6:58 AM Ricardo Y <richardlol1024@gmail.com> wrote:
Hi Matthew,
I forgot to mention this simulation is on an uniform grid. It's not clear to me how to do it the ValidateSpatial() way, but using ds.r like you suggested worked. Thank you! _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Sure! ---- import matplotlib.pyplot as plt import numpy as np import yt simZcenter = 1.3914e11 ## Load the first file and get the initial pressure ds0 = yt.load('initial file') # Example for a 512 by 512 slice in the xy plane. ds0r = ds0.r[::512j, ::512j, simZcenter] p0 = ds0r['pressure'] # Load the file for which we want to know the perturbation pressure ds = yt.load('final file') dsr = ds.r[::512j, ::512j, simZcenter] p = dsr['pressure'] # Plot the difference fig, ax = plt.subplots() im = ax.imshow(np.array(p - p0), origin = 'lower') plt.savefig('plot.png') plt.close() ----
participants (2)
-
Matthew Turk
-
Ricardo Y