Hi, everyone
I want to utilize data using ds.region function. I have used the CHANGA code-Tipsy dataset, which has 3 particle types - Gas, Stars, Darkmatter.
Because there is no particle index, so I added a field this way.
```
ds=yt.load("My data~~")
gas_num=np.shape(ds.all_data()['Gas','Mass'])[0] #number of gas particle
star_num=np.shape(ds.all_data()['Stars','Mass'])[0] #number of star particle
dm_num=np.shape(ds.all_data()['DarkMatter','Mass'])[0] #number of darkmatter particle
gas_index=range(gas_num) #gas index
star_index=range(gas_num,gas_num+star_num) #star index
dm_index=range(gas_num+star_num,gas_num+star_num+dm_num) #darkmatter index
all_index=range(gas_num+star_num+dm_num)
def _gas_index(field,data): #define index field
return (ds.arr(gas_index))
def _star_index(field,data):
return (ds.arr(star_index))
def _dm_index(field,data):
return (ds.arr(dm_index))
def _all_index(field,data):
return (ds.arr(all_index))
yt.add_field(
name=("Gas", "particle_index"),
function=_gas_index,
sampling_type="particle",
units="(dimensionless)",
)
ds.add_field(
name=("Gas", "particle_index"),
function=_gas_index,
sampling_type="particle",
units="(dimensionless)",
)
yt.add_field(
name=("Stars", "particle_index"),
function=_star_index,
sampling_type="particle",
units="(dimensionless)",
)
ds.add_field(
name=("Stars", "particle_index"),
function=_star_index,
sampling_type="particle",
units="(dimensionless)",
)
yt.add_field(
name=("DarkMatter", "particle_index"),
function=_dm_index,
sampling_type="particle",
units="(dimensionless)",
)
ds.add_field(
name=("DarkMatter", "particle_index"),
function=_dm_index,
sampling_type="particle",
units="(dimensionless)",
)
yt.add_field(
name=("all", "particle_index"),
function=_all_index,
sampling_type="particle",
units="(dimensionless)",
)
ds.add_field(
name=("all", "particle_index"),
function=_all_index,
sampling_type="particle",
units="(dimensionless)",
)
```
and then, I made a sphere region to select data in this region. However, the problem is although I made the regions, particle_index returns all datasets.
```
sp=ds.sphere(center,(radius,"kpc"))
len(ds.all_data()["DarkMatter","particle_mass"])
-->19584552
len(sp["DarkMatter","particle_mass"])
-->1287749
```
this is what I expected, but
```
len(ds.all_data()["DarkMatter","particle_index"])
-->19584552
len(sp["DarkMatter","particle_index"])
-->19584552
```
the particle_index field returns the same value.
It seems that this is because I just used array when I define the field function, but I don't have an idea.
I would appreciate it if anyone can give me some favors.
Thank you for reading!
Sincerely,
HyeonYong