Home Ask Login Register

Developers Planet

Your answer is one click away!

bhjghjh February 2016

python syntax error and usage of yt package

I need a little help in defining a new derived field in yt. my goal is to find if a stellar system eject some mass or not.

I am attaching the derived_field_list from the file I have. I am trying to define the total energy of the system E=0.5*m*v**2+gravitational potential energy*m

I am completely new to python and trying to get hold of the language through yt. I am attaching my efforts and the errors. please help me fix that.

Thanks in advance.

from yt import derived_field
@derived_field(name = 'mass_ejected')
def shock(field,data):
    dm = data["gas",'cell_mass']
    xv = data["gas","velocity_x"]
    yv = data["gas","velocity_y"]
    zv = data["gas","velocity_z"]
    grav_pot= data["flash", u'gpot']
#define total energy

if E_total > 0:
    return 0
else :
    return 1

and the corresponding error

 File "<ipython-input-14-2cb04cd0ad81>", line 13
    return 0
SyntaxError: 'return' outside function

and the file contains these following derived fields already

[('flash', u'dens'),
 ('flash', u'eint'),
 ('flash', u'gamc'),
 ('flash', u'gpot'),
 ('flash', u'pres'),
 ('flash', u'temp'),
 ('flash', u'velx'),
 ('flash', u'vely'),
 ('flash', u'velz'),
 ('gas', 'H_nuclei_density'),
 ('gas', 'He_nuclei_density'),
 ('gas', 'angular_momentum_magnitude'),
 ('gas', 'angular_momentum_x'),
 ('gas', 'angular_momentum_y'),
 ('gas', 'angular_momentum_z'),
 ('gas', 'averaged_density'),
 ('gas', 'baroclinic_vorticity_magnitude'),
 ('gas', 'baroclinic_vorticity_x'),
 ('gas', 'baroclinic_vorticity_y'),
 ('gas', 'baroclinic_vorticity_z'),
 ('gas', 'cell_mass'),
 ('gas', 'courant_time_step'),
 ('gas', 'cutting_plane_velocity_x'),
 ('gas', 'cutting_plane_velocity_y'),
 ('gas', 'cutting_plane_velocity_z'),
 ('gas', 'cylindrical_radial_velocity'),
 ('gas', 'c        


Paul Cornelius February 2016

Indent the if and else code blocks at the end of the listing so they align with the code above. Indentation has significance in Python, as opposed to most other languages. The interpreter thinks the E_total= line is the last one in the function body.

Post Status

Asked in February 2016
Viewed 3,302 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life