Skip to content
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ htmlcov/*
*.DS_Store

# Formatting venv
black_formatting_env/*
black_formatting_env/*

# Leftovers
*.png
*.hdf5
34 changes: 20 additions & 14 deletions swiftsimio/visualisation/power_spectrum.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "same units" required? Or is "compatible units" enough? cosmo_array should be clever enough now for the latter. Might want to check that mixed physical & comoving inputs give intuitive outputs, do you want to explicitly coerce the box size to match the comoving flag of the coordinates?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function explicitly asks for numpy arrays because of numba acceleration (value arrays; that's also what is passed by calling functions) so all unit coercion should be done before touching it.

Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ def deposit(
Parameters
----------
x : np.array[float64]
array of x-positions of the particles. Must be bounded by [0, 1].
array of x-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
y: np.array[float64]
array of y-positions of the particles. Must be bounded by [0, 1].
array of y-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
z: np.array[float64]
array of z-positions of the particles. Must be bounded by [0, 1].
array of z-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
m: np.array[float32]
array of masses (or otherwise weights) of the particles
res: int
Expand All @@ -48,7 +51,7 @@ def deposit(
the number of times to fold the box. Note that this is the
floating-point version (i.e. 2.0^folding).
box_x: float64
box size in x, in the same rescaled length units as x, y, and z. c
box size in x, in the same rescaled length units as x, y, and z.
box_y: float64
box size in y, in the same rescaled length units as x, y, and z.
box_z: float64
Expand Down Expand Up @@ -79,14 +82,14 @@ def deposit(

for x_pos, y_pos, z_pos, mass in zip(x, y, z, m):
# Fold the particles
x_pos = (x_pos % box_over_fold_x) * inv_box_over_fold_x
y_pos = (y_pos % box_over_fold_y) * inv_box_over_fold_y
z_pos = (z_pos % box_over_fold_z) * inv_box_over_fold_z
x_pos_scaled = (x_pos % box_over_fold_x) * inv_box_over_fold_x
y_pos_scaled = (y_pos % box_over_fold_y) * inv_box_over_fold_y
z_pos_scaled = (z_pos % box_over_fold_z) * inv_box_over_fold_z

# Convert to grid position
x_pix = int32(x_pos * float_res)
y_pix = int32(y_pos * float_res)
z_pix = int32(z_pos * float_res)
x_pix = int32(x_pos_scaled * float_res)
y_pix = int32(y_pos_scaled * float_res)
z_pix = int32(z_pos_scaled * float_res)

# Deposit the mass
output[x_pix, y_pix, z_pix] += mass * inv_volume_element
Expand Down Expand Up @@ -114,11 +117,14 @@ def deposit_parallel(
Parameters
----------
x : np.array[float64]
array of x-positions of the particles. Must be bounded by [0, 1].
array of x-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
y: np.array[float64]
array of y-positions of the particles. Must be bounded by [0, 1].
array of y-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
z: np.array[float64]
array of z-positions of the particles. Must be bounded by [0, 1].
array of z-positions of the particles. Scaled by box_x by this
function, so ensure they have the same units.
m: np.array[float32]
array of masses (or otherwise weights) of the particles
res: int
Expand All @@ -128,7 +134,7 @@ def deposit_parallel(
the number of times to fold the box. Note that this is the
floating-point version (i.e. 2.0^folding).
box_x: float64
box size in x, in the same rescaled length units as x, y, and z. c
box size in x, in the same rescaled length units as x, y, and z.
box_y: float64
box size in y, in the same rescaled length units as x, y, and z.
box_z: float64
Expand Down