flash - python syntax error and usage of yt package -


i need little in defining new derived field in yt. goal find if stellar system eject mass or not.

i attaching derived_field_list file have. trying define total energy of system e=0.5*m*v**2+gravitational potential energy*m

i new python , trying hold of language through yt. attaching efforts , errors. please 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     e_total=0.5*dm*(xv**2+yv**2+zv**2)+grav_pot*dm  if e_total > 0:     return 0 else :     return 1 

and corresponding error

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

and 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', 'cylindrical_radial_velocity_absolute'),  ('gas', 'cylindrical_tangential_velocity'),  ('gas', 'cylindrical_tangential_velocity_absolute'),  ('gas', 'density'),  ('gas', 'density_gradient_magnitude'),  ('gas', 'density_gradient_x'),  ('gas', 'density_gradient_y'),  ('gas', 'density_gradient_z'),  ('gas', 'dynamical_time'),  ('gas', 'entropy'),  ('gas', 'gravitational_potential'),  ('gas', 'kt'),  ('gas', 'kinetic_energy'),  ('gas', 'mach_number'),  ('gas', 'mazzotta_weighting'),  ('gas', 'pressure'),  ('gas', 'pressure_gradient_magnitude'),  ('gas', 'pressure_gradient_x'),  ('gas', 'pressure_gradient_y'),  ('gas', 'pressure_gradient_z'),  ('gas', 'radial_mach_number'),  ('gas', 'radial_velocity'),  ('gas', 'radial_velocity_absolute'),  ('gas', 'shear'),  ('gas', 'shear_criterion'),  ('gas', 'shear_mach'),  ('gas', 'sound_speed'),  ('gas', 'specific_angular_momentum_magnitude'),  ('gas', 'specific_angular_momentum_x'),  ('gas', 'specific_angular_momentum_y'),  ('gas', 'specific_angular_momentum_z'),  ('gas', 'sz_kinetic'),  ('gas', 'szy'),  ('gas', 'tangential_over_velocity_magnitude'),  ('gas', 'tangential_velocity'),  ('gas', 'temperature'),  ('gas', 'thermal_energy'),  ('gas', 'total_energy'),  ('gas', 'velocity_cylindrical_radius'),  ('gas', 'velocity_cylindrical_theta'),  ('gas', 'velocity_cylindrical_z'),  ('gas', 'velocity_divergence'),  ('gas', 'velocity_divergence_absolute'),  ('gas', 'velocity_magnitude'),  ('gas', 'velocity_spherical_phi'),  ('gas', 'velocity_spherical_radius'),  ('gas', 'velocity_spherical_theta'),  ('gas', 'velocity_x'),  ('gas', 'velocity_y'),  ('gas', 'velocity_z'),  ('gas', 'vorticity_growth_magnitude'),  ('gas', 'vorticity_growth_magnitude_absolute'),  ('gas', 'vorticity_growth_timescale'),  ('gas', 'vorticity_growth_x'),  ('gas', 'vorticity_growth_y'),  ('gas', 'vorticity_growth_z'),  ('gas', 'vorticity_magnitude'),  ('gas', 'vorticity_squared'),  ('gas', 'vorticity_stretching_magnitude'),  ('gas', 'vorticity_stretching_x'),  ('gas', 'vorticity_stretching_y'),  ('gas', 'vorticity_stretching_z'),  ('gas', 'vorticity_x'),  ('gas', 'vorticity_y'),  ('gas', 'vorticity_z'),  ('gas', 'xray_emissivity'),  ('index', 'cell_volume'),  ('index', 'cylindrical_r'),  ('index', 'cylindrical_radius'),  ('index', 'cylindrical_theta'),  ('index', 'cylindrical_z'),  ('index', 'disk_angle'),  ('index', 'dx'),  ('index', 'dy'),  ('index', 'dz'),  ('index', 'grid_indices'),  ('index', 'grid_level'),  ('index', 'height'),  ('index', 'ones'),  ('index', 'ones_over_dx'),  ('index', 'path_element_x'),  ('index', 'path_element_y'),  ('index', 'path_element_z'),  ('index', 'radius'),  ('index', 'spherical_phi'),  ('index', 'spherical_r'),  ('index', 'spherical_radius'),  ('index', 'spherical_theta'),  ('index', 'virial_radius_fraction'),  ('index', 'x'),  ('index', 'y'),  ('index', 'z'),  ('index', 'zeros')] 

indent if , else code blocks @ end of listing align code above. indentation has significance in python, opposed other languages. interpreter thinks e_total= line last 1 in function body.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -