<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Yuxiao,<div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><div class="">smooth_len = 100 # smoothing length of 100 kpc</div><div class="">SmoothedBMag = np.copy(ray[’ScaledBMag’]) # store the smoothed array</div><div class="">bin_num = np.ceiling((ray[‘x’].max() - ray[‘x’].min()) / smooth_len) # make bins every 100 kpc</div><div class=""><br class=""></div><div class="">for step in range(bin_num):</div><div class="">    mask1 = (ray[‘x’] >= ray[‘x’].min() + step * smooth_len)</div><div class="">    mask2 = (ray[‘x’] < ray[‘x’].min() + (step + 1) * smooth_len)</div><div class="">    mask = np.logical_and(mask1, mask2) # mask the cells within a certain length of 100 kpc</div><div class="">    SmoothedBMag[mask] = np.mean(ray[’ScaledBMag’][mask]) # take the average and save</div><div class=""><br class=""></div><div class="">After that the array “SmoothedBMag” is the smoothed one.</div><div class=""><br class=""></div><div class="">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" class="">http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots</a>), and in this case you could do something like:</div><div class=""><br class=""></div><div class="">plot = ProfilePlot(pf.h.all_data(), ‘x’, [’ScaledBMag’], n_bins=bin_num)</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Best wishes,</div><div class="">--</div><div class="">Suoqing JI</div><div class="">Ph.D Candidate</div><div class="">Department of Physics</div><div class="">University of California, Santa Barbara</div><div class=""><a href="http://web.physics.ucsb.edu/~suoqing" class="">http://web.physics.ucsb.edu/~suoqing</a></div></div></div></div></div></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Mar 14, 2016, at 10:57 PM, Yuxiao Dai <<a href="mailto:yuxiao.dai@nyu.edu" class="">yuxiao.dai@nyu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">Dear all, </div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">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? </div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.8px" class="">I would very much appreciate it if anyone could help me on this. </span><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.8px" class="">==============================</span><span style="font-size:12.8px" class="">=====</span><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">import ...</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><p class=""><span class="">def</span><span class=""> _ScaledBMag(field, data):</span></p><p class=""><span class="">    </span><span class="">return</span><span class=""> ...</span></p><p class=""><span class=""><br class=""></span></p></div><div class="gmail_default" style="font-family:georgia,serif">....</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><p class=""><span class="">pf = load(filename)</span></p><p class=""><span class="">    add_field(</span><span class="">"ScaledBMag"</span><span class="">, function=_ScaledBMag)</span></p><p class=""><span class=""></span><br class=""></p><p class=""><span class="">    c = pf.h.find_max(</span><span class="">'ScaledBMag'</span><span class="">)[</span><span class="">1</span><span class="">]</span></p><p class=""><span class="">    ax = </span><span class="">0</span></p><p class=""><span class="">    ray = pf.h.ortho_ray(ax, (c[</span><span class="">1</span><span class="">], c[</span><span class="">2</span><span class="">]))</span></p><div class=""><span class="">    </span><br class="webkit-block-placeholder"></div><p class=""><span class="">    P.subplot(</span><span class="">211</span><span class="">)</span></p><p class=""><span class="">    P.semilogy(ray[</span><span class="">'x'</span><span class="">], ray[</span><span class="">'ScaledBMag'</span><span class="">])</span></p><p class=""><span class="">    P.xlabel(</span><span class="">'x'</span><span class="">)</span></p><p class=""><span class="">    P.ylabel(</span><span class="">'ScaledBMag'</span><span class="">)</span></p><p class=""><span class="">    </span><span class="">print</span><span class=""> </span><span class="">"works"</span></p><p class=""><span class="">    P.savefig(</span><span class="">"ScaledBMag_lineplot.png"</span><span class="">)</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><span id="cid:ii_15378d3cd9d354f9"><image.png></span><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.8px" class="">==============================</span><span style="font-size:12.8px" class="">=====</span><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><p style="font-size:12.8px" class=""><span style="font-size:12.8px" class="">I'm using yt</span><br class=""></p><p style="font-size:12.8px" class="">Version = 2.6.1</p><div style="font-size: 12.8px;" class=""><br class="webkit-block-placeholder"></div><p style="font-size:12.8px" class="">Changeset = c994959ed3be</p><p style="font-size:12.8px" class="">=======================<span style="font-size:12.8px" class="">=======</span><span style="font-size:12.8px" class="">=====</span></p><p style="font-size:12.8px" class=""><span style="font-size:12.8px" class=""><br class=""></span></p><p style="font-size:12.8px" class=""><span style="font-size:12.8px" class=""><br class=""></span></p></div><div class="gmail_default" style="font-family:georgia,serif"><p style="font-size:12.8px" class="">Regards,</p><p style="font-size:12.8px" class="">Dai </p></div></div>
_______________________________________________<br class="">yt-users mailing list<br class=""><a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br class=""></div></blockquote></div><br class=""></div></body></html>