<div dir="ltr"><div><div><div><div>Dear yt:<br><br></div>I am trying to plot magnetic 
field lines using the annotate magnetic field call back from the link 
<a href="http://yt-project.org/doc/visualizing/callbacks.html">http://yt-project.org/doc/visualizing/callbacks.html</a> link.<br><br></div>However,
 after running the script it gives the error below. A google drive link 
to my script (yt_numpy_load_B.py) is also given below. When I use quiver
 annotate it works fine but issue comes when I am using 
slc.annotate_magnetic_field(). <br>Quiver plots are also available on the drive link.<br><br></div>Thanks in advance<br><br>===============<br></div>Google drive link<br><a href="https://drive.google.com/open?id=0B4g8shg4DL7oak5PLWVVdG5UMHc">https://drive.google.com/open?id=0B4g8shg4DL7oak5PLWVVdG5UMHc</a><br><div>===============<br><br>===============<br></div><div>Error while running the script<br><br>  File "yt_numpy_load_B.py", line 47, in <module><br>    slc.save()<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_container.py", line 77, in newfunc<br>    args[0]._setup_plots()<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 980, in _setup_plots<br>    self.run_callbacks()<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1033, in run_callbacks<br>    sys.exc_info()[2])<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1029, in run_callbacks<br>    callback(cbw)<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 316, in __call__<br>    return qcb(plot)<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 357, in __call__<br>    fv_x = plot.data[self.field_x]<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 246, in __getitem__<br>    f = self._determine_fields([key])[0]<br> 
 File 
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py",
 line 518, in _determine_fields<br>    finfo = self.ds._get_field_info("unknown", fname)<br>  File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/static_output.py", line 543, in _get_field_info<br>    raise YTFieldNotFound((ftype, fname), self)<br>yt.utilities.exceptions.YTPlotCallbackError:
 annotate_magnetic_field callback failed with the following error: Could
 not find field '('all', 'magnetic_field_x')' in UniformGridData.<br></div>===============<br><br><br><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 16, 2016 at 12:52 PM,  <span dir="ltr"><<a href="mailto:yt-users-request@lists.spacepope.org" target="_blank">yt-users-request@lists.spacepope.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send yt-users mailing list submissions to<br>
        <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:yt-users-request@lists.spacepope.org">yt-users-request@lists.spacepope.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:yt-users-owner@lists.spacepope.org">yt-users-owner@lists.spacepope.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of yt-users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: Making averaged line plot. (Suoqing Ji)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 15 Mar 2016 15:23:43 -0700<br>
From: Suoqing Ji <<a href="mailto:suoqing@physics.ucsb.edu">suoqing@physics.ucsb.edu</a>><br>
To: Discussion of the yt analysis package<br>
        <<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a>><br>
Subject: Re: [yt-users] Making averaged line plot.<br>
Message-ID: <<a href="mailto:70E5BA6C-7798-45F2-AE83-21233252E109@physics.ucsb.edu">70E5BA6C-7798-45F2-AE83-21233252E109@physics.ucsb.edu</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi Yuxiao,<br>
<br>
If you would like to start from your current code, the most straightforward way is to write a loop to smooth over a certain distance by each step, which also works for AMR data:<br>
<br>
smooth_len = 100 # smoothing length of 100 kpc<br>
SmoothedBMag = np.copy(ray[?ScaledBMag?]) # store the smoothed array<br>
bin_num = np.ceiling((ray[?x?].max() - ray[?x?].min()) / smooth_len) # make bins every 100 kpc<br>
<br>
for step in range(bin_num):<br>
    mask1 = (ray[?x?] >= ray[?x?].min() + step * smooth_len)<br>
    mask2 = (ray[?x?] < ray[?x?].min() + (step + 1) * smooth_len)<br>
    mask = np.logical_and(mask1, mask2) # mask the cells within a certain length of 100 kpc<br>
    SmoothedBMag[mask] = np.mean(ray[?ScaledBMag?][mask]) # take the average and save<br>
<br>
After that the array ?SmoothedBMag? is the smoothed one.<br>
<br>
However, an easier way is to use the the 1D ProfilePlot function (<a href="http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots" rel="noreferrer" target="_blank">http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots</a> <<a href="http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots" rel="noreferrer" target="_blank">http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots</a>>), and in this case you could do something like:<br>
<br>
plot = ProfilePlot(pf.h.all_data(), ?x?, [?ScaledBMag?], n_bins=bin_num)<br>
<br>
Note that this will do the average over entire y-z plane for each x bins, which is different from averaging only an array of a ray object (so maybe it?s not what you want). If you really want the data within a thin slit only, you could define a region object pf.h.region() and do ProfilePlot. I think it?s also doable to use the function ?load_uniform_grid? to create a 1D dataset from the arrays in ray object and pass it to ProfilePlot.<br>
<br>
Best wishes,<br>
--<br>
Suoqing JI<br>
Ph.D Candidate<br>
Department of Physics<br>
University of California, Santa Barbara<br>
<a href="http://web.physics.ucsb.edu/~suoqing" rel="noreferrer" target="_blank">http://web.physics.ucsb.edu/~suoqing</a><br>
<br>
> On Mar 14, 2016, at 10:57 PM, Yuxiao Dai <<a href="mailto:yuxiao.dai@nyu.edu">yuxiao.dai@nyu.edu</a>> wrote:<br>
><br>
> Dear all,<br>
><br>
> I have a line plot of some parameter along an axis as a function of distance. Now I would like to get another line plot of the same parameter but averaged over a certain distance (say 100 kpc, the plot below is supposed to be flat after this). I've been searching the document for some time but haven't found a method. Is there a simple way to do this?<br>
><br>
> I would very much appreciate it if anyone could help me on this.<br>
><br>
><br>
> ===================================<br>
> import ...<br>
><br>
> def _ScaledBMag(field, data):<br>
><br>
>     return ...<br>
><br>
><br>
><br>
> ....<br>
><br>
> pf = load(filename)<br>
><br>
>     add_field("ScaledBMag", function=_ScaledBMag)<br>
><br>
><br>
><br>
>     c = pf.h.find_max('ScaledBMag')[1]<br>
><br>
>     ax = 0<br>
><br>
>     ray = pf.h.ortho_ray(ax, (c[1], c[2]))<br>
><br>
><br>
>     P.subplot(211)<br>
><br>
>     P.semilogy(ray['x'], ray['ScaledBMag'])<br>
><br>
>     P.xlabel('x')<br>
><br>
>     P.ylabel('ScaledBMag')<br>
><br>
>     print "works"<br>
><br>
>     P.savefig("ScaledBMag_lineplot.png")<br>
><br>
><br>
> <image.png><br>
><br>
> ===================================<br>
> I'm using yt<br>
><br>
> Version = 2.6.1<br>
><br>
><br>
> Changeset = c994959ed3be<br>
><br>
> ===================================<br>
><br>
><br>
><br>
><br>
><br>
> Regards,<br>
><br>
> Dai<br>
><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" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160315/8afc239c/attachment.html" rel="noreferrer" target="_blank">http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160315/8afc239c/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<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" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br>
<br>
------------------------------<br>
<br>
End of yt-users Digest, Vol 97, Issue 19<br>
****************************************<br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><span style="border-collapse:collapse"><div style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b><i>SK<sup>2</sup></i></b></span></div><div style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b><i><sup><br></sup></i></b></span></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;border-collapse:collapse"><b><sup>"</sup></b></span><font face="arial, sans-serif" color="#500050"><b>Claiming that something can move faster than light is a good conversation-stopper in physics. People edge away from you in cocktail parties; friends never return phone calls. You just don’t mess with Albert Einstein.</b></font><b style="color:rgb(80,0,80);font-family:arial,sans-serif"><sup>"</sup></b></div><div style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px"><br></div></span></div>
</div></div>