jluastro / PopSyCLE

Population Synthesis for Compact-object Lensing Events
https://popsycle.readthedocs.io/en/latest/
16 stars 3 forks source link

Changing calc_events from looping over time_array to lenses #24

Closed MichaelMedford closed 4 years ago

MichaelMedford commented 4 years ago

Code Description This rewrite of calc_events is an implementation of the brainstorming made at the January BAMM meeting. The idea was to avoid reconstruction of the kdtree at each time in the survey's time_array. The central idea is to treat slow stars and fast stars differently.

Slow stars will be near the same surrounding stars throughout any reasonably long microlensing survey (< 10 yrs). Therefore we can compare each slow star to it's surrounding stars at t0 = 0, or what I'm calling the static catalog. We loop through each star in the catalog, and ask what stars are around it in the static catalog within the search radius radius_cut. To calculate what the speed_cut is between slow stars and fast stars, we calculate: speed_cut = radius_cut_mas / (2 * obs_time_yrs) speed_cut = 91.3 mas/yr for radius_cut = 0.5 and obs_time_yrs = 10.

This method finds all microlensing events with Einstein radius less than radius_cut.

The code loops over all of the stars in the catalog, asking if each one could be a lens to the stars in it's search radius. Through a series of cuts, it only applies expensive calculations to extremely close stars that are behind the lens. Then the event parameters and blends are calculated for the event.

Fast stars are pre-treated in two ways. First, before the main loop begins, the code queries the location of fast stars against the static catalog for every time in the survey's time_array. If at any point in the survey a fast star moves into the search radius of a different static star, (1) the fast star is added to the list of possible microlensing sources of that static star, and (2) the static star is added the list of possible microlensing sources of the fast star. Second, every fast star is compared to the location of every other fast star at every time step in the survey. If either fast star is within the search radius of another fast star at any time, the sub-steps listed above are down for each fast star. Once this has been done for all fast stars, the main search loop proceeds.

Performance Results Tables showing identical events detected and speed ups for single sets of PopSyCLE parameters shown here. To highlight the speed-up in calc_events:

Small longitude 1.250000 latitude -2.650000 surveyArea 0.00100 master : 326.1s neighbor_matching : 245.8s ~25% reduction

Medium longitude 1.250000 latitude -2.650000 surveyArea 0.00330 master : 1183.2s neighbor_matching : 817.1s 31% reduction

Large longitude 2.000000 latitude 1.000000 surveyArea 0.33000 master : s neighbor_matching : s % reduction

Plots showing the speed ups across a range of PopSyCLE parameters shown here.

Additional Changes

MichaelMedford commented 4 years ago

@jluastro @caseylam I have tried many different implementations of this idea to attempt to balance memory consumption and execution time. I cannot find a sweet spot where the scripts execute in less time but do not consume too much memory. I now believe that this method was an interesting idea but is ultimately not an improvement over the current implementation.

I am going to close this pull request and call it quits on my attempts to make this work.