I need a little help creating a derived field which will return me the negative gradient of gravitational potential, hence the gravitational acceleration. I tried something like this:
@derived_field(name = "gradient_gravpot", units = " cm/s**2")
def _gradient (field, data):
G = add_gradient_fields(("gas"," gravitational_potental"))
return (- data["gravitational_potential_gradient_x"])
and I got this error
NameError: global name 'add_gradient_fields' is not defined
please suggest me the right method to define the field. thanks
It looks like you got an answer on the yt project mailing list. That said, I'll repeat here that add_gradient_fields
is a method of the Dataset
class, so you will need to call it on a loaded dataset. For example:
ds = yt.load('path/to/dataset')
ds.add_gradient_fields(('gas', 'gravitational_potential'))