Skip to content

Commit

Permalink
fix tests of markdown files (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbyrohl authored Jan 3, 2024
1 parent f067d7e commit 11b22f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit 11b22f7

Please sign in to comment.