Saving and Reloading Data Objects in yt

Hello everyone, I am working with cosmological simulations and I am trying to make use of the ability to save spatial plots as datasets. I am running into an issue after reloading the data when I try to center the plot on a specific halo. When I specify the center in the yt.ProjectionPlot function after reading in the .h5 file, if I print the center of the projection it returns "[0.5,0.5]", which is the center of the simulation not the center I specified. I am confused why this doesn't work because creating the same plot without saving and reloading data results in a projection with the correct center. The script I am using is below: import yt import numpy as np #load in the simulation ds = yt.load('/mnt/research/galaxies-REU/sims/cosmological/set1_LR/halo_008508/RD0032/RD0032') center = [0.4915,0.478,0.5066] # Creating the projection from the dataset proj = ds.proj('density','x',weight_field=None) #Saving projection as a dataset fn = proj.save_as_dataset() # Making a regular projection plot to compare to plot = yt.ProjectionPlot(ds,'x','density',center=center,width=(2,'Mpc'),weight_field='density') plot.save('projection_from_ProjectionPlot.png') # Print the center for the Projection Plot print('\n\n',plot.center,'\n\n') # Load in the saved object from before new_plot = yt.load(fn) #Make a new projection plot from the loaded in saved dataset new_proj = yt.ProjectionPlot(new_plot,'x','density',center=center,width=(2,'Mpc'),weight_field='density') new_proj.save('projection_from_ds_proj.png') #Print the center of the new projection plot print('\n\n',new_proj.center,'\n\n') This script will save two plots, one will be made from the saved and reloaded data and the other will be just from yt.ProjectionPlot. It will also print the center for the projection after saving and loading the data (which seems to always be [0.5,0.5]) and the center for the normal projection (which will always be [0.478,0.5066]). By comparing the two plots that it saves, the "projection_from_ProjectionPlot.png" image is centered on the correct halo, while the "projection_from_ds_proj.png" is centered on the center of the simulation and not the correct halo. I have tried specifying the center in the "ds.proj" arguments to no avail, and I have tried specifying the center in "ds.proj" and not setting it in yt.ProjectionPlot for the saved data and this did not work either. Any help would be much appreciated! Thank you, Trevor Fush

Hi Trevor, Thanks for reporting this issue. There is indeed a bug, or perhaps a couple of bugs. When making projections from the reloaded dataset, the center is not getting passed correctly to the plot initializer. This can be gotten around by doing new_proj.set_center(center[1:]) Note, I explicitly pass just the y and z values for set_center as it accepts only the 2d center in the plane of the image. While this fixes the centering issues, I further noted that the image comes out as an unweighted projection. I think these are relatively easy to fix, but I am pretty swamped at the moment. Could you file an issue on github with the information from your email? That way, this won't get lost and maybe someone else can pick it up before I have the chance. Thanks and sorry for the trouble! Britton On Wed, May 20, 2020 at 10:43 PM <fushstep@msu.edu> wrote:
Hello everyone,
I am working with cosmological simulations and I am trying to make use of the ability to save spatial plots as datasets. I am running into an issue after reloading the data when I try to center the plot on a specific halo. When I specify the center in the yt.ProjectionPlot function after reading in the .h5 file, if I print the center of the projection it returns "[0.5,0.5]", which is the center of the simulation not the center I specified. I am confused why this doesn't work because creating the same plot without saving and reloading data results in a projection with the correct center. The script I am using is below:
import yt import numpy as np
#load in the simulation ds = yt.load('/mnt/research/galaxies-REU/sims/cosmological/set1_LR/halo_008508/RD0032/RD0032')
center = [0.4915,0.478,0.5066]
# Creating the projection from the dataset proj = ds.proj('density','x',weight_field=None)
#Saving projection as a dataset fn = proj.save_as_dataset()
# Making a regular projection plot to compare to plot = yt.ProjectionPlot(ds,'x','density',center=center,width=(2,'Mpc'),weight_field='density') plot.save('projection_from_ProjectionPlot.png')
# Print the center for the Projection Plot print('\n\n',plot.center,'\n\n')
# Load in the saved object from before new_plot = yt.load(fn)
#Make a new projection plot from the loaded in saved dataset new_proj = yt.ProjectionPlot(new_plot,'x','density',center=center,width=(2,'Mpc'),weight_field='density') new_proj.save('projection_from_ds_proj.png')
#Print the center of the new projection plot print('\n\n',new_proj.center,'\n\n')
This script will save two plots, one will be made from the saved and reloaded data and the other will be just from yt.ProjectionPlot. It will also print the center for the projection after saving and loading the data (which seems to always be [0.5,0.5]) and the center for the normal projection (which will always be [0.478,0.5066]). By comparing the two plots that it saves, the "projection_from_ProjectionPlot.png" image is centered on the correct halo, while the "projection_from_ds_proj.png" is centered on the center of the simulation and not the correct halo. I have tried specifying the center in the "ds.proj" arguments to no avail, and I have tried specifying the center in "ds.proj" and not setting it in yt.ProjectionPlot for the saved data and this did not work either. Any help would be much appreciated!
Thank you, Trevor Fush _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: brittonsmith@gmail.com

Hi Trevor, I didn't read your sample script carefully enough and missed the fact that the projection you saved with save_as_dataset didn't have the weight_field set, so there is no bug there. My fault. Fixing the center was straightforward. I've issued a PR for this, which you can see here: https://github.com/yt-project/yt/pull/2607 The workaround from my previous email should take care of things until the fix is merged. Britton On Mon, May 25, 2020 at 11:48 AM Britton Smith <brittonsmith@gmail.com> wrote:
Hi Trevor,
Thanks for reporting this issue. There is indeed a bug, or perhaps a couple of bugs. When making projections from the reloaded dataset, the center is not getting passed correctly to the plot initializer. This can be gotten around by doing new_proj.set_center(center[1:])
Note, I explicitly pass just the y and z values for set_center as it accepts only the 2d center in the plane of the image.
While this fixes the centering issues, I further noted that the image comes out as an unweighted projection. I think these are relatively easy to fix, but I am pretty swamped at the moment. Could you file an issue on github with the information from your email? That way, this won't get lost and maybe someone else can pick it up before I have the chance.
Thanks and sorry for the trouble!
Britton
On Wed, May 20, 2020 at 10:43 PM <fushstep@msu.edu> wrote:
Hello everyone,
I am working with cosmological simulations and I am trying to make use of the ability to save spatial plots as datasets. I am running into an issue after reloading the data when I try to center the plot on a specific halo. When I specify the center in the yt.ProjectionPlot function after reading in the .h5 file, if I print the center of the projection it returns "[0.5,0.5]", which is the center of the simulation not the center I specified. I am confused why this doesn't work because creating the same plot without saving and reloading data results in a projection with the correct center. The script I am using is below:
import yt import numpy as np
#load in the simulation ds = yt.load('/mnt/research/galaxies-REU/sims/cosmological/set1_LR/halo_008508/RD0032/RD0032')
center = [0.4915,0.478,0.5066]
# Creating the projection from the dataset proj = ds.proj('density','x',weight_field=None)
#Saving projection as a dataset fn = proj.save_as_dataset()
# Making a regular projection plot to compare to plot = yt.ProjectionPlot(ds,'x','density',center=center,width=(2,'Mpc'),weight_field='density') plot.save('projection_from_ProjectionPlot.png')
# Print the center for the Projection Plot print('\n\n',plot.center,'\n\n')
# Load in the saved object from before new_plot = yt.load(fn)
#Make a new projection plot from the loaded in saved dataset new_proj = yt.ProjectionPlot(new_plot,'x','density',center=center,width=(2,'Mpc'),weight_field='density') new_proj.save('projection_from_ds_proj.png')
#Print the center of the new projection plot print('\n\n',new_proj.center,'\n\n')
This script will save two plots, one will be made from the saved and reloaded data and the other will be just from yt.ProjectionPlot. It will also print the center for the projection after saving and loading the data (which seems to always be [0.5,0.5]) and the center for the normal projection (which will always be [0.478,0.5066]). By comparing the two plots that it saves, the "projection_from_ProjectionPlot.png" image is centered on the correct halo, while the "projection_from_ds_proj.png" is centered on the center of the simulation and not the correct halo. I have tried specifying the center in the "ds.proj" arguments to no avail, and I have tried specifying the center in "ds.proj" and not setting it in yt.ProjectionPlot for the saved data and this did not work either. Any help would be much appreciated!
Thank you, Trevor Fush _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: brittonsmith@gmail.com

Hi Dr. Smith, Using set_center worked perfect, and yes I forgot to specify the weight field in the ds.proj. Thank you! Trevor
participants (2)
-
Britton Smith
-
fushstep@msu.edu