python语法错误和yt包的使用
在yt中定义一个新的派生字段时,我需要一些帮助。我的目标是找出一个恒星系统是否会喷射出一些质量 我正在从我拥有的文件中附加派生字段列表。我试图定义系统的总能量E=0.5*m*v**2+重力势能*m 我对python完全陌生,并试图通过yt掌握该语言。我重视我的努力和错误。请帮我修一下 提前谢谢 以及相应的误差python语法错误和yt包的使用,python,flash,yt-project,Python,Flash,Yt Project,在yt中定义一个新的派生字段时,我需要一些帮助。我的目标是找出一个恒星系统是否会喷射出一些质量 我正在从我拥有的文件中附加派生字段列表。我试图定义系统的总能量E=0.5*m*v**2+重力势能*m 我对python完全陌生,并试图通过yt掌握该语言。我重视我的努力和错误。请帮我修一下 提前谢谢 以及相应的误差 缩进列表末尾的if和else代码块,使它们与上面的代码对齐。与大多数其他语言相比,缩进在Python中具有重要意义。解释器认为E_total=行是函数体中的最后一行 from yt imp
缩进列表末尾的
if
和else
代码块,使它们与上面的代码对齐。与大多数其他语言相比,缩进在Python中具有重要意义。解释器认为E_total=
行是函数体中的最后一行
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
File "<ipython-input-14-2cb04cd0ad81>", line 13
return 0
SyntaxError: 'return' outside function
[('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')]