<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Hi Britton,
<div><br>
</div>
<div>Yes that makes a lot of sense. I have made the modifications and the code seems to work up to the point of the pc.add line and then crashes:</div>
<div><br>
</div>
<div>Here is the code as is it stands:</div>
<div><br>
</div>
<div>
<div>from yt.mods import *</div>
<div><br>
</div>
<div>p6 = load("output_00006/info_00006.txt")</div>
<div>cen = [0.5, 0.5, 0.5]</div>
<div><br>
</div>
<div>sphere = p6.h.sphere(cen, 0.5/p6['cm'])</div>
<div>r_max = sphere['Radius'][sphere['Density'] == sphere['Density'].max()]</div>
<div>sphere.set_field_parameter('r_max', r_max)</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>@derived_field(name = "Denin", units = "g/cm^3", take_log = False)</div>
<div>def denunits(field, data):</div>
<div> return(data["Density"]*1)</div>
<div>@derived_field(name = "Presin", units = "g/cm^2", take_log = False)</div>
<div>def presunits(field, data):</div>
<div> return(data["Pressure"]*1)</div>
<div><br>
</div>
<div>@derived_field(name = "RRsh", take_log = False)</div>
<div>def RRshunits(field, data):</div>
<div> r_max = data.get_field_parameter('rmax')</div>
<div> return(data["Radius"]/r_max)</div>
<div> </div>
<div> </div>
<div><br>
</div>
<div>pc = PlotCollection(p6, center = cen)</div>
<div>pc.add_profile_object(sphere, ["RRsh", "Denin"], x_log=False)</div>
<div>pc.add_profile_object(sphere, ["RRsh", "Presin"], x_log=False)</div>
<div>pc.add_profile_object(sphere, ["RRsh", "VelocityMagnitude"], x_log=False)</div>
<div>pc.save('test103')</div>
<div><br>
</div>
<div>print sphere['Density']</div>
<div><br>
</div>
<div><br>
</div>
<div>and the error message:</div>
<div><br>
</div>
<div>
<div>Traceback (most recent call last):</div>
<div> File "profiles2.py", line 27, in <module></div>
<div> pc.add_profile_object(sphere, ["RRsh", "Denin"], x_log=False)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 961, in add_profile_object</div>
<div> lazy_reader=lazy_reader)[0]</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 92, in __call__</div>
<div> return self._call_func_lazy(args, kwargs)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 99, in _call_func_lazy</div>
<div> rv = self.func(GridChildMaskWrapper(g, self._data_source), *args, **kwargs)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 615, in _Extrema</div>
<div> if data[field].size < 1:</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 60, in __getitem__</div>
<div> data = self.data_source._get_data_from_grid(self.grid, item)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 95, in save_state</div>
<div> tr = func(self, grid, field, *args, **kwargs)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 2645, in _get_data_from_grid</div>
<div> tr = grid[field]</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 157, in __getitem__</div>
<div> self.get_data(key)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 200, in get_data</div>
<div> self._generate_field(field)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 145, in _generate_field</div>
<div> self[field] = self.pf.field_info[field](self)</div>
<div> File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 395, in __call__</div>
<div> dd = self._function(self, data)</div>
<div> File "profiles2.py", line 22, in RRshunits</div>
<div> return(data["Radius"]/r_max)</div>
<div>TypeError: unsupported operand type(s) for /: 'float' and ‘NoneType'</div>
</div>
<div><br>
</div>
<div>Thanks</div>
<div><br>
</div>
<div>Kearn</div>
<div>
<div>On 4 Nov 2013, at 15:53, Britton Smith <<a href="mailto:brittonsmith@gmail.com">brittonsmith@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div dir="ltr">Hi Kearn,
<div><br>
</div>
<div>Sorry, that was a typo on my part. sp should be "sphere". So, what's happening here is the following:</div>
<div><br>
</div>
<div>I have made a sphere data container with the first line, and now I can access all of the field data for that sphere. So for example,</div>
<div>sphere["Density"]</div>
<div>will give me an array of all the densities for all the cells in the sphere. Since it's a numpy array, I can get the maximum density in the sphere by doing:</div>
<div>sphere["Density"].max()</div>
<div><br>
</div>
<div>Then, I can figure out which cell is the one that has the maximum density with:</div>
<div>sphere["Density"] == sphere["Density"].max()</div>
<div><br>
</div>
<div>If you print out that line by itself, it will be an array of Trues and Falses. Really, it will have only one True value and all the rest will be Falses. The point is that this True/False array can then be used as a filter on any other array of the same
shape. So then, if I do:</div>
<div>my_filter = sphere["Density"] == sphere["Density"].max()</div>
<div><br>
</div>
<div>Then,</div>
<div>sphere["Radius"][my_filter]</div>
<div>will be the radius value for the cell that was True in the filter array, which is the cell with the maximum density.</div>
<div><br>
</div>
<div>Does that make sense?</div>
<div><br>
</div>
<div>Britton</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Mon, Nov 4, 2013 at 3:38 PM, <span dir="ltr"><<a href="mailto:k.grisdale@surrey.ac.uk" target="_blank">k.grisdale@surrey.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;">
<div style="word-wrap:break-word">Hi Britton,
<div><br>
</div>
<div>Thanks for the reply.</div>
<div><br>
</div>
<div>I have tried to implement what you have suggest. But I get the following error:</div>
<div><br>
</div>
<div>
<div> File "profiles2.py", line 7, in <module></div>
<div class="im">
<div> r_max = sp['Radius'][sp['Density'] == sp['Density'].max()]</div>
</div>
<div>NameError: name 'sp' is not defined.</div>
<div><br>
</div>
<div>To be honest I don’t quite follow the r_max = sp…etc line. could you explain that a little?</div>
<div><br>
</div>
<div>Thanks</div>
<div><br>
</div>
<div>Kearn</div>
<div>
<div class="h5">
<div>
<div>On 4 Nov 2013, at 15:21, Britton Smith <<a href="mailto:brittonsmith@gmail.com" target="_blank">brittonsmith@gmail.com</a>> wrote:</div>
<br>
<blockquote type="cite">
<div dir="ltr">Hi Kearn,
<div><br>
</div>
<div>I recommend doing something like the following:</div>
<div><br>
</div>
<div>Create a sphere on you're own with</div>
<div>sphere = pf.h.sphere(center, (radius, units))</div>
<div><br>
</div>
<div>Then, calculate the maximum density and position of that with some numpy array operations and set it as a "field parameter":</div>
<div>r_max = sp['Radius'][sp['Density'] == sp['Density'].max()]<br>
</div>
<div>sp.set_field_parameter('r_max', r_max)</div>
<div><br>
</div>
<div>Then, in your field definition, you can do:</div>
<div>r_max = data.get_field_parameter('rmax')</div>
<div><br>
</div>
<div>and then do the rest of the field definition just as you described.</div>
<div><br>
</div>
<div>Finally, instead of add_profile_sphere, you can you add_profile_object which will take the sphere you just created as an argument.</div>
<div><br>
</div>
<div>That should do what you want. Feel free to write back if you have more questions.</div>
<div><br>
</div>
<div>Britton</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Mon, Nov 4, 2013 at 2:49 PM, <span dir="ltr"><<a href="mailto:k.grisdale@surrey.ac.uk" target="_blank">k.grisdale@surrey.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi yt-users<br>
<br>
I’m attempting to plot some profiles as a function of radius/radiusSH, where radiusSh is the radius of a shock. However I am not sure what the simplest way of getting yt to plot this. I have been using the following commands to produce the profiles.<br>
:<br>
<br>
pc = PlotCollection(p6, center = cen)<br>
pc.add_profile_sphere(0.5, "cm", ["Radius", "Density"], weight = "Denin”)<br>
<br>
I have also tried to define a new field:<br>
<br>
<br>
@derived_field(name = "RRsh", take_log = False, validators = [ValidateParameter("rsh")])<br>
def RRshunits(field, data):<br>
value, rsh = p6.h.find_max("Density")<br>
return(data["Radius"]/rsh)<br>
<br>
but this leads to the following error:<br>
<br>
Traceback (most recent call last):<br>
File "profiles.py", line 21, in <module><br>
pc.add_profile_sphere(0.5, "cm", ["RRsh", "Denin"], weight = "Denin")<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 1058, in add_profile_sphere<br>
figure=figure, axes=axes)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 961, in add_profile_object<br>
lazy_reader=lazy_reader)[0]<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 92, in __call__<br>
return self._call_func_lazy(args, kwargs)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 99, in _call_func_lazy<br>
rv = self.func(GridChildMaskWrapper(g, self._data_source), *args, **kwargs)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 615, in _Extrema<br>
if data[field].size < 1:<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/derived_quantities.py", line 60, in __getitem__<br>
data = self.data_source._get_data_from_grid(self.grid, item)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 95, in save_state<br>
tr = func(self, grid, field, *args, **kwargs)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 2645, in _get_data_from_grid<br>
tr = grid[field]<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 157, in __getitem__<br>
self.get_data(key)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 200, in get_data<br>
self._generate_field(field)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/grid_patch.py", line 132, in _generate_field<br>
self.pf.field_info[field].check_available(self)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 366, in check_available<br>
validator(data)<br>
File "/Applications/Code/yt/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 442, in __call__<br>
raise NeedsParameter(doesnt_have)<br>
yt.data_objects.field_info_container.NeedsParameter: (['rsh’])<br>
<br>
Am I missing something in my field definition or is their a simpler way to go about this?<br>
<br>
Thanks<br>
<br>
Kearn<br>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</blockquote>
</div>
<br>
</div>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
<br>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br>
</blockquote>
</div>
<br>
</div>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br>
</blockquote>
</div>
<br>
</div>
</body>
</html>