Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/not implemented problem: annotate_contour does not work with GIZMO MFM output #4858

Open
jkgo232 opened this issue Mar 29, 2024 · 1 comment

Comments

@jkgo232
Copy link

jkgo232 commented Mar 29, 2024

Bug report

Bug summary

When I try to overplot contours using annotate_contour on my GIZMO data I get an error. The plot works using other annotate functions, only the contour seems to have a problem.

Code for reproduction

I used the Fire 12i example from http://yt-project.org/data in the demonstration below:

import yt
import numpy as np
import matplotlib.pyplot as plt
from yt.units import kpc

ds0 = yt.load("D:/snapshot_600.hdf5")
ad0 = ds0.all_data()
potential = ad0["PartType4", "Potential"]
wdens = np.where(potential == np.min(potential))
coordinates0 = ad0["PartType4", "Coordinates"]
center0 = coordinates0[wdens][0]
print("center = ", center0)

p=yt.SlicePlot(ds0, "y", ("gas", "temperature"), center=center0, width=(20, "kpc"))
p.annotate_contour(("gas", "temperature"))
p.show()

Actual outcome

yt : [INFO     ] 2024-03-29 12:10:24,007 Calculating time from 1.000e+00 to be 4.355e+17 seconds
yt : [INFO     ] 2024-03-29 12:10:24,009 Assuming length units are in kpc/h (comoving)
yt : [INFO     ] 2024-03-29 12:10:24,108 Parameters: current_time              = 4.3545571088051405e+17 s
yt : [INFO     ] 2024-03-29 12:10:24,110 Parameters: domain_dimensions         = [1 1 1]
yt : [INFO     ] 2024-03-29 12:10:24,122 Parameters: domain_left_edge          = [0. 0. 0.]
yt : [INFO     ] 2024-03-29 12:10:24,137 Parameters: domain_right_edge         = [60000. 60000. 60000.]
yt : [INFO     ] 2024-03-29 12:10:24,138 Parameters: cosmological_simulation   = 1
yt : [INFO     ] 2024-03-29 12:10:24,139 Parameters: current_redshift          = 0.0
yt : [INFO     ] 2024-03-29 12:10:24,140 Parameters: omega_lambda              = 0.728
yt : [INFO     ] 2024-03-29 12:10:24,141 Parameters: omega_matter              = 0.272
yt : [INFO     ] 2024-03-29 12:10:24,142 Parameters: omega_radiation           = 0.0
yt : [INFO     ] 2024-03-29 12:10:24,142 Parameters: hubble_constant           = 0.702
yt : [INFO     ] 2024-03-29 12:10:24,208 Allocating for 4.787e+06 particles
Loading particle index: 100%|██████████| 10/10 [00:00<00:00, 180.85it/s]
yt : [INFO     ] 2024-03-29 12:10:25,593 xlim = 32582.574671 32596.614671
yt : [INFO     ] 2024-03-29 12:10:25,594 ylim = 29279.041454 29293.081454
yt : [INFO     ] 2024-03-29 12:10:25,597 xlim = 32582.574671 32596.614671
yt : [INFO     ] 2024-03-29 12:10:25,599 ylim = 29279.041454 29293.081454
yt : [INFO     ] 2024-03-29 12:10:25,601 Making a fixed resolution buffer of (('gas', 'temperature')) 800 by 800
center =  [29286.06145364 31049.2410335  32589.59467114] code_length
---------------------------------------------------------------------------
YTNonIndexedDataContainer                 Traceback (most recent call last)
File C:\ProgramData\Anaconda3\lib\site-packages\yt\visualization\plot_window.py:1279, in PWViewerMPL.run_callbacks(self)
   1278 try:
-> 1279     callback(cbw)
   1280 except (NotImplementedError, YTDataTypeUnsupported):

File C:\ProgramData\Anaconda3\lib\site-packages\yt\visualization\plot_modifications.py:960, in ContourCallback.__call__(self, plot)
    956 elif plot._type_name in ["Projection", "Slice"]:
    957     # Makes a copy of the position fields "px" and "py" and adds the
    958     # appropriate shift to the copied field.
--> 960     AllX = np.zeros(data["px"].size, dtype="bool")
    961     AllY = np.zeros(data["py"].size, dtype="bool")

File C:\ProgramData\Anaconda3\lib\site-packages\yt\data_objects\data_containers.py:232, in YTDataContainer.__getitem__(self, key)
    231 if f in self._container_fields:
--> 232     self.field_data[f] = self.ds.arr(self._generate_container_field(f))
    233     return self.field_data[f]

File C:\ProgramData\Anaconda3\lib\site-packages\yt\data_objects\selection_objects\slices.py:89, in YTSlice._generate_container_field(self, field)
     88 if field == "px":
---> 89     return self._current_chunk.fcoords[:, xax]
     90 elif field == "py":

File C:\ProgramData\Anaconda3\lib\site-packages\yt\geometry\geometry_handler.py:272, in cacheable_property.<locals>.cacheable_func(self)
    271 if self.data_size is None:
--> 272     tr = self._accumulate_values(n[1:])
    273 else:

File C:\ProgramData\Anaconda3\lib\site-packages\yt\geometry\geometry_handler.py:308, in YTDataChunk._accumulate_values(self, method)
    307     f = getattr(obj, mname)
--> 308     arrs.append(f(self.dobj))
    309 if method == "dtcoords":

File C:\ProgramData\Anaconda3\lib\site-packages\yt\data_objects\index_subobjects\particle_container.py:17, in _non_indexed.<locals>._func_non_indexed(self, *args, **kwargs)
     16 def _func_non_indexed(self, *args, **kwargs):
---> 17     raise YTNonIndexedDataContainer(self)

YTNonIndexedDataContainer: The data container type (ParticleContainer) is an unindexed type. Operations such as ires, icoords, fcoords and fwidth will not work on it.
Did you just attempt to perform an off-axis operation ? Be sure to consult the latest documentation to see whether the operation you tried is actually supported for your data type.

The above exception was the direct cause of the following exception:

YTPlotCallbackError                       Traceback (most recent call last)
Cell In[29], line 16
     14 p=yt.SlicePlot(ds0, "y", ("gas", "temperature"), center=center0, width=(20, "kpc"))
     15 p.annotate_contour(("gas", "temperature"))
---> 16 p.show()

File C:\ProgramData\Anaconda3\lib\site-packages\yt\visualization\_commons.py:172, in validate_plot.<locals>.newfunc(self, *args, **kwargs)
    168     self._recreate_profile()
    169 if not self._plot_valid:
    170     # it is the responsibility of _setup_plots to
    171     # call plot.run_callbacks()
--> 172     self._setup_plots()
    173 retv = f(self, *args, **kwargs)
    174 return retv

File C:\ProgramData\Anaconda3\lib\site-packages\yt\visualization\plot_window.py:1222, in PWViewerMPL._setup_plots(self)
   1219         self.plots[f]._toggle_axes(draw_axes, draw_frame)
   1221 self._set_font_properties()
-> 1222 self.run_callbacks()
   1224 if self._flip_horizontal or self._flip_vertical:
   1225     # some callbacks (e.g., streamlines) fail when applied to a
   1226     # flipped axis, so flip only at the end.
   1227     for f in field_list:

File C:\ProgramData\Anaconda3\lib\site-packages\yt\visualization\plot_window.py:1283, in PWViewerMPL.run_callbacks(self)
   1281         raise
   1282     except Exception as e:
-> 1283         raise YTPlotCallbackError(callback._type_name) from e
   1284 for key in self.frb.keys():
   1285     if key not in keys:

YTPlotCallbackError: annotate_contour callback failed

Expected outcome
I expected to get a slice plot with contour lines overdrawn.

Version Information

I am using a Jupyter notebook launched from an Anaconda Navigator running Anaconda3. yt was installed using conda install, but I don't remember the details. I am using yt 4.2.2 and python 3.8.18

Copy link

welcome bot commented Mar 29, 2024

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant