[yt-users] Clearing a derived field from all grids

Matthew Turk matthewturk at gmail.com
Tue Dec 13 04:03:41 PST 2011


Hi Elizabeth,

On Tue, Dec 13, 2011 at 4:14 AM, Elizabeth Tasker
<tasker at astro1.sci.hokudai.ac.jp> wrote:
> Hi Matt,
>
> Sorry, this is still a problem for my set-up.
>
> The issue is that EffectivePotential is only created on some grids,
> not all of them, so if I do:
>
> for g in pf.h.grids: del g[field_name]
>
> it freaks out when it can't find the field.
>
> But, I don't want to delete the grids as I go, because then I end up
> calculating EffectivePotential a ridiculous number of times.
>
> Yet, if I don't clear it as we go through that c loop, my results get
> screwed up.
>
> So what I need is:
>
> for c in (nclouds):
>
>    grids, cis = kd.locate_neighbors_from_position(position)
>     for  n in range(26):
>           phi = grids[n]["EffectivePotential"][cis[n]]
>
>    << clear all the grids that have EffectivePotential on them before
> c increments and it needs to be recalculated>>
>
>
> Is it possible to hack yt so that
>
> for g in pf.h.grids: del g[field_name]
>
> just chills out and moves on if it can't find the field_name? Or do a
> (if this field exists, delete grid) line?
>

No hacking needed.  Grids have a "has_key" function.

for g in pf.h.grids:
    if g.has_key(field_name): del g[field_name]

-Matt

>
> Elizabeth
>
>
>
> On 13 December 2011 12:14, Matthew Turk <matthewturk at gmail.com> wrote:
>> Hi Elizabeth,
>>
>> Yes, sorry, I misread 'ng'.  I'll be more explicit -- if you have a
>> GridPatch object, you can do "del grid[field_name]" and it will remove
>> it.  One thing you can do is iterate over the grids, as you note, like
>> this:
>>
>> for g in pf.h.grids: del g[field_name]
>>
>> Good luck.
>>
>> -Matt
>>
>> On Mon, Dec 12, 2011 at 8:58 PM, Elizabeth Tasker
>> <tasker at astro1.sci.hokudai.ac.jp> wrote:
>>> Hi Matt,
>>>
>>> Unfortunately, that doesn't work.
>>>
>>> I can do:
>>>
>>> del ng[n][fieldname]
>>>
>>> But then I'd have to recreate the field afresh for each grid (very
>>> slow), as opposed to just when I rerun the whole loop again:
>>>
>>> for c in (nclouds):
>>>  grids, cis = kd.locate_neighbors_from_position(position)
>>>  for  n in range(26):
>>>    phi = grids[n]["EffectivePotential"][cis[n]]
>>>     del grids[n]["EffectivePotential"]
>>>
>>> I really want to delete every c-loop, not every n loop.
>>>
>>> Possibly the best way is to loop over the n loop again and delete the
>>> grids afterwards:
>>>
>>> for n in range(26):
>>> del grids[n]["EffectivePotential"]
>>>
>>> Which is fine, I was just checking if there was a neater way!
>>>
>>> Elizabeth
>>>
>>>
>>> On 12 December 2011 20:18, Matthew Turk <matthewturk at gmail.com> wrote:
>>>> Hi Elizabeth,
>>>>
>>>> You can do:
>>>>
>>>> del ng[fieldname]
>>>>
>>>> -Matt
>>>>
>>>> On Dec 12, 2011 5:45 AM, "Elizabeth Tasker"
>>>> <tasker at astro1.sci.hokudai.ac.jp> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Is there a way of deleting a single derived field from all grids?
>>>>>
>>>>> I seem to be having a problem with my derived field not being
>>>>> re-calculated for every element in a loop (it needs to be). Therefore,
>>>>> if I run the complete loop, I get an incorrect result for some of the
>>>>> elements which are totally fine if I tell the code to just calculate
>>>>> that element in a single sweep.
>>>>>
>>>>> I've tried deleting the individual elements that use that variable,
>>>>> but it doesn't seem to be enough, e.g.
>>>>>
>>>>> ng, nc = kd.locate_neighbors_from_position(nposn)
>>>>> .
>>>>> .
>>>>> .
>>>>> del ng
>>>>>
>>>>>
>>>>> Elizabeth
>>>>> _______________________________________________
>>>>> yt-users mailing list
>>>>> yt-users at lists.spacepope.org
>>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>
>>>>
>>>> _______________________________________________
>>>> yt-users mailing list
>>>> yt-users at lists.spacepope.org
>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>
>>> _______________________________________________
>>> yt-users mailing list
>>> yt-users at lists.spacepope.org
>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org



More information about the yt-users mailing list