[yt-users] ProjectionPlot of a new field

Nathan Goldbaum nathan12343 at gmail.com
Tue Feb 25 12:01:57 PST 2014


The units for the field are generated from the unit string.  This
needs to be defined in the call to add_field for
"Grey_Radiation_Source".  The unit string should be in LaTeX format.
Something like:

add_field("Grey_Radiation_source", function=grey_radiation_function,
convert_function=grey_radiation_convert_function, take_log=True,
unts="erg\/s**{-1}")

where grey_radiation_function and grey_radiation_convert_function are
python functions with the correct signature and return values expected
for field definitions and field conversion functions.

As sam suggested, you might want to define a convert_function for this
field to handle the constant conversions you want to apply.

See here: http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html

In unitrefactor this is all more streamlined so that units can be
dynamically modified and unit strings for plots are generated based on
the data not a hard-coded LaTeX string.

Cheers,

Nathan

On Tue, Feb 25, 2014 at 11:51 AM, Geoffrey So <gsiisg at gmail.com> wrote:
> Not trying to do anything too fancy, just trying to put units on the
> colorbar since the field does not have build in cgs conversion factors in
> Enzo.  I multiply the plot by the conversion factors but the text on the
> colorbar says 'unknown' for units.  I can bypass this by defining a derived
> field by using the original field and multiplied by the same constants, and
> including the correct units there, but that seems to waste a lot of
> computation.
>
> From
> G.S.
>
> convD = pf.conversion_factors["Density"]
> convV = pf.conversion_factors["x-velocity"]
> z     = pf["CosmologyCurrentRedshift"]
>
> field = 'Grey_Radiation_Energy'
>
> prj = ProjectionPlot(pf, direct, field, center='c',
>                      weight_field=field,
>                      fontsize=24)
>
> # multiply by conversion factors to get erg cm^{-3}
> prj.data_source['Grey_Radiation_Energy'] *= convD*convV*convV
>
> prj.annotate_text((1.05,1.05),'z=%2.2f' % z)
>
> prj.set_log(field,'log')
>
> prj.save('frames/')
>
>
> On Mon, Feb 24, 2014 at 6:56 PM, Nathan Goldbaum <nathan12343 at gmail.com>
> wrote:
>>
>> Hi Geoffrey,
>>
>> It depends on what you're trying to do.
>>
>> Can you share the script you're working on?
>>
>> -Nathan
>>
>> On Mon, Feb 24, 2014 at 6:24 PM, Geoffrey So <gsiisg at gmail.com> wrote:
>> > A follow-up question,
>> >
>> > Is there a way to change the labels on the x, y axes and colorbar text?
>> >
>> > From
>> > G.S.
>> >
>> >
>> > On Mon, Feb 24, 2014 at 5:31 PM, Geoffrey So <gsiisg at gmail.com> wrote:
>> >>
>> >> Hi Sam,
>> >>
>> >> I might be mistaken but it seems the convert_function requires there to
>> >> be
>> >> already a cgs conversion factor YT knows about, and unfortunately this
>> >> field
>> >> I'm working with does not have that.  What I used to do is just
>> >> multiply the
>> >> conversion factors in after making the FRB, but I'm starting to try to
>> >> using
>> >> the new Projection/PhasePlot.
>> >>
>> >> I tried the script you have up there, and I think it is doing the same
>> >> thing I was with the FRB.  At least I see the colorbar also changed
>> >> accordingly, which is exactly what I hoped for, thanks!
>> >>
>> >> From
>> >> G.S.
>> >>
>> >>
>> >>
>> >> On Mon, Feb 24, 2014 at 4:52 PM, Sam Skillman <samskillman at gmail.com>
>> >> wrote:
>> >>>
>> >>> Hi Geoffrey,
>> >>>
>> >>> Yes, it would save time to multiply the projection object by a
>> >>> constant
>> >>> factor if your projection has already been done. However, it is a bit
>> >>> dangerous to do this since now you need to manually edit how all the
>> >>> units/labels work out.
>> >>>
>> >>> I'd suggest just creating a new derived field that uses the
>> >>> convert_function option
>> >>>
>> >>> (http://yt-project.org/docs/dev/analyzing/creating_derived_fields.html#field-options).
>> >>> A good, non-trivial example is the SZY field:
>> >>>
>> >>>
>> >>> https://bitbucket.org/yt_analysis/yt/src/61e6b84f875cc8fcf25b5b1e67ddd501a19daf68/yt/data_objects/universal_fields.py?at=yt#cl-577
>> >>>
>> >>> If you do want to manually modify an projection object, you can do
>> >>> something like the following:
>> >>>
>> >>> from yt.mods import *
>> >>> pf = load('IsolatedGalaxy/galaxy0030/galaxy0030')
>> >>> proj_pw = ProjectionPlot(pf, 0, 'Density', weight_field='Density')
>> >>> proj_pw.save('before')
>> >>> proj_pw.data_source['Density'] *= 1.5
>> >>> proj_pw.refresh()
>> >>> proj_pw.save('after')
>> >>>
>> >>> Sam
>> >>>
>> >>>
>> >>>
>> >>> On Mon, Feb 24, 2014 at 12:26 PM, Geoffrey So <gsiisg at gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> Hi all,
>> >>>>
>> >>>> Will I be saving computation time by multiplying some constant
>> >>>> conversion factors on the projection object instead of creating a
>> >>>> derived
>> >>>> field with an existing field multiplied by the factors?
>> >>>>
>> >>>> And how would I go about multiplying the projection by some factors?
>> >>>>
>> >>>> If there's no significant saving I'll just do the derived field.
>> >>>>
>> >>>> From
>> >>>> G.S.
>> >>>>
>> >>>> _______________________________________________
>> >>>> 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