-
Notifications
You must be signed in to change notification settings - Fork 280
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
[WIP] add depth-limiting to off-axis sph particle projections #4712
Conversation
4aaeb9e
to
4dfe236
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. Thank you! I've left some comments.
cdef np.float64_t * yiterv | ||
cdef np.float64_t * ziterv | ||
|
||
if weight_field is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you got this code from elsewhere, but I will say that it definitely confused me. I at first thought this was a string, but now I see it's either a numpy array or none. Yowza!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed! copied directly from pixelize_sph_kernel_projection
. Up in the python somewhere there's a weight
that is a string, so definitely confusing. Could rename this variable to weight_array
(and also rename in pixelize_sph_kernel_projection
).
# pixelize_sph_kernel_projection. | ||
|
||
local_buff = <np.float64_t *> malloc(sizeof(np.float64_t) * xsize * ysize) | ||
xiterv = <np.float64_t *> malloc(sizeof(np.float64_t) * 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a sneaking suspicion it's to avoid a race condition, but I think a long time ago we were supposed to be able to declare variables inside a parallel
block to get them to be thread-local. No changes needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpful context! I was confused by why this was needed.
for yyi in range(ysize): | ||
buff[xxi, yyi] += local_buff[xxi + yyi*xsize] | ||
free(local_buff) | ||
free(xiterv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this also need to happen inside the parallel context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1910,6 +2095,61 @@ def rotate_particle_coord(np.float64_t[:] px, | |||
return px_rotated, py_rotated, rot_bounds_x0, rot_bounds_x1, rot_bounds_y0, rot_bounds_y1 | |||
|
|||
|
|||
@cython.boundscheck(False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this function looks right. What I'm wondering is if it needs to be in Cython as-is. I think it could potentially take advantage of being in cython by consolidating the matmul
stuff with the copying of coordinates -- i.e., iterating over the particles one-by-one and avoiding temporary arrays. I'm not 100% sure that it's necessary, but it could potentially eliminate some allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya, I agree -- it could be written with just numpy matrix operations at the python level or rewritten with a different loop control.
Also, could actually cut out an entire loop over the particles by calculating the rotated particle positions as needed within pixelize_sph_kernel_projection_with_depth_check
(and pixelize_sph_kernel_projection
)?
weight_field=weight_field, | ||
check_period=0) | ||
if depth_set: | ||
px_rotated, py_rotated, pz_rotated, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't fix this here, but is this a case where something like a named tuple or simple data class could simplify our code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I do think that would help. it might be worth fixing here too :) I think it could cut down on some of the code duplication I'm introducing.
I ended up putting in depth limits in SPH projections in #4939 -- too bad it was duplicate work. |
great!! I'm just glad the functionality got in :) I'll close this one out. |
Closes #4711
The initial push does indeed work for sph particle projections, but I intend to refactor...
that said,
returns
and
which seems to make sense (first image is 2 Mpc depth, second is 20 Mpc depth).
Still to do:
depth
inOffAxisProjectionPlot
is(1, '1')
instead ofNone
, so it may drop some particles, changing what the plots with default values look like? UPDATE: didn't actually break tests, but that may be a function of test coverage and there could be a change in behavior introduced here?OffAxisProjectionDummyDataSource
). I think it's fine, but want to double check... UPDATE: I think I'm coming back around on this ... now thinking that it'd be better to simply always apply the depth limitation, following how the off axis projection for gridded data works. Will marinate on this for a bit ....pixelize_sph_kernel_projection
androtate_particle_coord
and introduced a ton of code duplication in the process. I mainly wanted to avoid creating extra arrays for the rotated z coordinates and running extra checks on z bounds in the case where it's not limiting by z, so started off by simply creating separate functions... but will go back and refactor this now that I have it nominally working.