[yt-users] syntax error when defining a new field

Nathan Goldbaum nathan12343 at gmail.com
Fri Jun 6 09:33:36 PDT 2014


Hi Mike,

Units are no longer LaTeX strings in yt 3.0. Now unit strings are parsed to
generate a symbolic unit object for each field. Try instead
"units=g/cm**2".  Note that powers need to be in python syntax (** instead
of ^) since sympy is parsing the unit string and converting it into a
symbolic unit object.

Take a look at the following doc page:

http://yt-project.org/docs/dev-3.0/analyzing/units/data_selection_and_fields.html

That said, I'm not sure this will actually work for your code snippet for
two reasons.  First, unless you are using an Enzo dataset, it's likely that
the Density field is not defined.  We've renamed the "standard" field names
to be more rational.  Try "density" instead. See:

http://ytep.readthedocs.org/en/latest/YTEPs/YTEP-0003.html

Even if you are using Enzo, it will still likely give the wrong answer
since the Density field is in internal code units by default
(code_mass/code_length**3). Assigning units of g/cm**2 to an alias of
Density won't work since the unit dimensionalities won't match.

If you are just using this field to make a ProjectionPlot use Sigma as the
display name for the projected field instead of Density, you might need to
say that it's units are g/cm**3 and let the ProjectionPlot do the unit
conversion for you if you are doing an unweighted projection.

This might seem more complicated, but this will also prevent you from
creating plots with buggy units - which would have happened if you tried to
create a slice of your Sigma field under the old unit system.

Best,

Nathan

On Friday, June 6, 2014, Mike Butler <mbutler.astro at gmail.com> wrote:

> Hello, I am using the latest version of yt-3.0 and am having some problems
> defining a new field.  Here is an example of a field that produces an error:
> def _Sigm(field,data): return data["Density"]
>
> add_field("Sigma",function=_Sigm,units=r"\rm{g}/\rm{cm}^{2}",display_name=r"\Sigma")
>
> and this is the error I get when I try to do a projection of it:
>
>   File "<string>", line 1
>     \Symbol ('rm' ,positive =True ){Symbol ('g' ,positive =True )}/\Symbol
> ('rm' ,positive =True ){Symbol ('cm' ,positive =True )}^{Integer (2 )}
>
> ^
> SyntaxError: unexpected character after line continuation character
>
> It works fine on the stable and dev versions of yt.  Has something changed
> for defining fields in 3.0?
>
> Thanks,
>
> Mike
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140606/c2ff7756/attachment.htm>


More information about the yt-users mailing list