[yt-users] How to use if, elif, else statements in creating a derived field

Reju Sam John rejusamjohn at gmail.com
Mon Oct 21 02:10:51 PDT 2013


Dear all,

I would like to create a derived field which should return a value
according to specified conditions. My definition of new field is shown
below.. But it is giving error.


@derived_field(name = "MyField")
def my_new_field(field, data):
    if data.pf["MachNumber"] < 2 :
        return (.5* (data["MachNumber"])**2) - 1
    elif data.pf["MachNumber"] < 100 :
        return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)
    else:
       return 5.446361E-01



Please suggest me how to implement if, elif, else statements in creating a
derived field.

Thank You
Reju Sam John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20131021/1f9af7b2/attachment.htm>


More information about the yt-users mailing list