Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements to docs #128

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/derived_fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ def GroupDistance3D(arrs, snap=None):
groupid = groupid.magnitude
boxsize *= snap.ureg("code_length")
pos_cat = snap.data["Group"]["GroupPos"][groupid]
dist3 = pos_part-pos_cat
dist3 = (pos_part-pos_cat)
dist3, u = dist3.magnitude, dist3.units
dist3 = da.where(dist3>boxsize/2.0, boxsize-dist3, dist3)
dist3 = da.where(dist3<=-boxsize/2.0, boxsize+dist3, dist3) # PBC
return dist3
return dist3 * u

@fielddefs.register_field("all")
def GroupDistance(arrs, snap=None):
import dask.array as da
dist3 = arrs["GroupDistance3D"]
dist3, u = dist3.magnitude, dist3.units
dist = da.sqrt((dist3**2).sum(axis=1))
dist = da.where(arrs["GroupID"]==-1, np.nan, dist) # set unbound gas to nan
return dist
return dist * u
```

1. We define a list of field containers that we want to add particles to.
Expand All @@ -117,5 +119,4 @@ In above example, we now have the following fields available:
gas = ds.data["PartType0"]
print(gas["Volume"])
print(gas["GroupDistance"])
print(gas["Subhalo"])
```
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def evaluate(self):
# evaluate all at once (for now)
code = "\n".join(self.codeblocks)
print("Evaluating code:")
print(code)
exec(code)
print('"""' + code + '"""')
exec(code, globals()) # need to use global() to allow using imports


def get_docfiles():
Expand Down