Hi Salome,
I think what's happening is that you're defining the field, but using
data external to the field definition, and the way yt subchunks data
causes the shape error.
Creating field parameters is still annoying and hard, which is what
you would normally want. So, to err on the safe side, here's how I
would write your script so that you're using the right mean. It has
an extra function layer in it to make sure the average is correctly
defined.
def _create_new_field(ds, average_value):
def _B_fluc(field, data):
return data["gas", "magnetic_field_magnitude"] - average_value
ds.add_field(("gas", "B_fluc", function=_B_fluc, units="gauss")
dd = ds.all_data()
avg = dd.mean("magnetic_field_magnitude")
_create_new_field(ds, avg)
prof ...
On Tue, Mar 31, 2020 at 11:06 AM Salome Mtchedlidze
Hello everyone!
I am trying to create radial profile of a halo. I can create e.g. temperature, density, B profile but if I add a new field then it does not give me the profile; The code is here:
----------------- ds = yt.load('Dataset') dd = ds.all_data()
Halo_ds = "catalog.h5" File = h5py.File(Halo_ds, 'r') n = 0
radius = File["virial_radius"][n]/float(ds.domain_width.in_units("cm")[0]) #code units x = File["particle_position_x"][n]/float(ds.domain_width.in_units("cm")[0]) #Code units y = File["particle_position_y"][n]/float(ds.domain_width.in_units("cm")[0]) z = File["particle_position_z"][n]/float(ds.domain_width.in_units("cm")[0]) center = ds.arr([x, y, z], 'code_length') rvir = radius sph = ds.sphere(center, rvir)
#Define new field B = dd['gas','magnetic_field_magnitude'] B_f = B - B.mean()
def _B_fluc(field, dd): return (B_f)
ds.add_field(("gas", "B_fluc"), function=_B_fluc, units="gauss")
prof = yt.create_profile(sph, ["radius"], fields=["B_fluc"], n_bins=64) --------------------------------------
The error is:
"Profile fields must have same shape: ('index', 'radius') has shape (6530,) and ('gas', 'B_flucc') has shape (9533574,)."
So, I am wondering, is there a way to define this added field only inside the sphere? _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org