<div dir="ltr">"<span style="font-family:arial,sans-serif;font-size:13px">It probably doesn't waste that much."</span><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">"</span><span style="font-size:13px;font-family:arial,sans-serif">add_field("Grey_Radiation_</span><span style="font-size:13px;font-family:arial,sans-serif">source", function=grey_radiation_</span><span style="font-size:13px;font-family:arial,sans-serif">function,</span></div>
<span style="font-family:arial,sans-serif;font-size:13px">convert_function=grey_</span><span style="font-family:arial,sans-serif;font-size:13px">radiation_convert_function, take_log=True,</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">unts="erg\/s**{-1}")"</span><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Even with Nathan's suggestion I'll still need to define a grey_radiation_function, and that's what I was trying to avoid. However, Matt says it won't be that much more expensive, so I'll just go with my original defining a new field by multiplying the original field by constants.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Sorry for the trouble.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">From</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">G.S.</span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Feb 25, 2014 at 12:01 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The units for the field are generated from the unit string.  This<br>
needs to be defined in the call to add_field for<br>
"Grey_Radiation_Source".  The unit string should be in LaTeX format.<br>
Something like:<br>
<br>
add_field("Grey_Radiation_source", function=grey_radiation_function,<br>
convert_function=grey_radiation_convert_function, take_log=True,<br>
unts="erg\/s**{-1}")<br>
<br>
where grey_radiation_function and grey_radiation_convert_function are<br>
python functions with the correct signature and return values expected<br>
for field definitions and field conversion functions.<br>
<br>
As sam suggested, you might want to define a convert_function for this<br>
field to handle the constant conversions you want to apply.<br>
<br>
See here: <a href="http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html" target="_blank">http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html</a><br>
<br>
In unitrefactor this is all more streamlined so that units can be<br>
dynamically modified and unit strings for plots are generated based on<br>
the data not a hard-coded LaTeX string.<br>
<br>
Cheers,<br>
<br>
Nathan<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Feb 25, 2014 at 11:51 AM, Geoffrey So <<a href="mailto:gsiisg@gmail.com">gsiisg@gmail.com</a>> wrote:<br>
> Not trying to do anything too fancy, just trying to put units on the<br>
> colorbar since the field does not have build in cgs conversion factors in<br>
> Enzo.  I multiply the plot by the conversion factors but the text on the<br>
> colorbar says 'unknown' for units.  I can bypass this by defining a derived<br>
> field by using the original field and multiplied by the same constants, and<br>
> including the correct units there, but that seems to waste a lot of<br>
> computation.<br>
><br>
> From<br>
> G.S.<br>
><br>
> convD = pf.conversion_factors["Density"]<br>
> convV = pf.conversion_factors["x-velocity"]<br>
> z     = pf["CosmologyCurrentRedshift"]<br>
><br>
> field = 'Grey_Radiation_Energy'<br>
><br>
> prj = ProjectionPlot(pf, direct, field, center='c',<br>
>                      weight_field=field,<br>
>                      fontsize=24)<br>
><br>
> # multiply by conversion factors to get erg cm^{-3}<br>
> prj.data_source['Grey_Radiation_Energy'] *= convD*convV*convV<br>
><br>
> prj.annotate_text((1.05,1.05),'z=%2.2f' % z)<br>
><br>
> prj.set_log(field,'log')<br>
><br>
> prj.save('frames/')<br>
><br>
><br>
> On Mon, Feb 24, 2014 at 6:56 PM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com">nathan12343@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hi Geoffrey,<br>
>><br>
>> It depends on what you're trying to do.<br>
>><br>
>> Can you share the script you're working on?<br>
>><br>
>> -Nathan<br>
>><br>
>> On Mon, Feb 24, 2014 at 6:24 PM, Geoffrey So <<a href="mailto:gsiisg@gmail.com">gsiisg@gmail.com</a>> wrote:<br>
>> > A follow-up question,<br>
>> ><br>
>> > Is there a way to change the labels on the x, y axes and colorbar text?<br>
>> ><br>
>> > From<br>
>> > G.S.<br>
>> ><br>
>> ><br>
>> > On Mon, Feb 24, 2014 at 5:31 PM, Geoffrey So <<a href="mailto:gsiisg@gmail.com">gsiisg@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Hi Sam,<br>
>> >><br>
>> >> I might be mistaken but it seems the convert_function requires there to<br>
>> >> be<br>
>> >> already a cgs conversion factor YT knows about, and unfortunately this<br>
>> >> field<br>
>> >> I'm working with does not have that.  What I used to do is just<br>
>> >> multiply the<br>
>> >> conversion factors in after making the FRB, but I'm starting to try to<br>
>> >> using<br>
>> >> the new Projection/PhasePlot.<br>
>> >><br>
>> >> I tried the script you have up there, and I think it is doing the same<br>
>> >> thing I was with the FRB.  At least I see the colorbar also changed<br>
>> >> accordingly, which is exactly what I hoped for, thanks!<br>
>> >><br>
>> >> From<br>
>> >> G.S.<br>
>> >><br>
>> >><br>
>> >><br>
>> >> On Mon, Feb 24, 2014 at 4:52 PM, Sam Skillman <<a href="mailto:samskillman@gmail.com">samskillman@gmail.com</a>><br>
>> >> wrote:<br>
>> >>><br>
>> >>> Hi Geoffrey,<br>
>> >>><br>
>> >>> Yes, it would save time to multiply the projection object by a<br>
>> >>> constant<br>
>> >>> factor if your projection has already been done. However, it is a bit<br>
>> >>> dangerous to do this since now you need to manually edit how all the<br>
>> >>> units/labels work out.<br>
>> >>><br>
>> >>> I'd suggest just creating a new derived field that uses the<br>
>> >>> convert_function option<br>
>> >>><br>
>> >>> (<a href="http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html#field-options" target="_blank">http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html#field-options</a>).<br>

>> >>> A good, non-trivial example is the SZY field:<br>
>> >>><br>
>> >>><br>
>> >>> <a href="https://bitbucket.org/yt_analysis/yt/src/61e6b84f875cc8fcf25b5b1e67ddd501a19daf68/yt/data_objects/universal_fields.py?at=yt#cl-577" target="_blank">https://bitbucket.org/yt_analysis/yt/src/61e6b84f875cc8fcf25b5b1e67ddd501a19daf68/yt/data_objects/universal_fields.py?at=yt#cl-577</a><br>

>> >>><br>
>> >>> If you do want to manually modify an projection object, you can do<br>
>> >>> something like the following:<br>
>> >>><br>
>> >>> from yt.mods import *<br>
>> >>> pf = load('IsolatedGalaxy/galaxy0030/galaxy0030')<br>
>> >>> proj_pw = ProjectionPlot(pf, 0, 'Density', weight_field='Density')<br>
>> >>> proj_pw.save('before')<br>
>> >>> proj_pw.data_source['Density'] *= 1.5<br>
>> >>> proj_pw.refresh()<br>
>> >>> proj_pw.save('after')<br>
>> >>><br>
>> >>> Sam<br>
>> >>><br>
>> >>><br>
>> >>><br>
>> >>> On Mon, Feb 24, 2014 at 12:26 PM, Geoffrey So <<a href="mailto:gsiisg@gmail.com">gsiisg@gmail.com</a>><br>
>> >>> wrote:<br>
>> >>>><br>
>> >>>> Hi all,<br>
>> >>>><br>
>> >>>> Will I be saving computation time by multiplying some constant<br>
>> >>>> conversion factors on the projection object instead of creating a<br>
>> >>>> derived<br>
>> >>>> field with an existing field multiplied by the factors?<br>
>> >>>><br>
>> >>>> And how would I go about multiplying the projection by some factors?<br>
>> >>>><br>
>> >>>> If there's no significant saving I'll just do the derived field.<br>
>> >>>><br>
>> >>>> From<br>
>> >>>> G.S.<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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
>> >>>><br>
>> >>><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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
>> >>><br>
>> >><br>
>> ><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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
><br>
><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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</div></div></blockquote></div><br></div>