-
Notifications
You must be signed in to change notification settings - Fork 77
Add functions to get 3D krypton maps #948
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
base: master
Are you sure you want to change the base?
Conversation
gonzaponte
left a comment
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.
First round
|
|
||
|
|
||
|
|
||
| def normalization(krmap, method, x_low, x_high, y_low, y_high): |
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.
The last 4 parameters need to be optional, since they are only relevant for method == "region". I also think it would be interesting to gather them in a dictionary to simplify the logic.
|
|
||
| def normalization(krmap, method, x_low, x_high, y_low, y_high): | ||
|
|
||
| mu_values = krmap.mu |
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.
since you are doing .dropna() everywhere, you can do it here already
| k, i, j = np.meshgrid(k_vals, i_vals, j_vals, indexing='ij') | ||
| k = k.ravel() | ||
| i = i.ravel() | ||
| j = j.ravel() |
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.
| k, i, j = np.meshgrid(k_vals, i_vals, j_vals, indexing='ij') | |
| k = k.ravel() | |
| i = i.ravel() | |
| j = j.ravel() | |
| k, i, j = map(np.ravel, | |
| np.meshgrid(k_vals, i_vals, j_vals, indexing='ij')) |
|
|
||
| """ | ||
|
|
||
| def create_NaN_map(xy_range, dt_range, xy_nbins, dt_nbins): |
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.
| def create_NaN_map(xy_range, dt_range, xy_nbins, dt_nbins): | |
| def create_empty_map(xy_range, dt_range, xy_nbins, dt_nbins): |
| xy_bins = np.linspace(xy_range[0], xy_range[1], xy_nbins + 1) | ||
| dt_bins = np.linspace(dt_range[0], dt_range[1], dt_nbins + 1) | ||
|
|
||
| #shift to bin centers invisible_cities.core.core_functions | ||
|
|
||
| i_range = np.arange(0, len(xy_bins)-1) | ||
| j_range = np.arange(0, len(xy_bins)-1) | ||
| k_range = np.arange(0, len(dt_bins)-1) |
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.
xy_bins and dt_bins are only used to compute their length, which are given by the variables xy_nbins and dt_nbins
| range_S2t = (low_S2t, high_S2t) | ||
| sel_S2t = in_range(kdst.S2t, *range_S2t) |
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.
| range_S2t = (low_S2t, high_S2t) | |
| sel_S2t = in_range(kdst.S2t, *range_S2t) | |
| sel_S2t = in_range(kdst.S2t, low_S2t, high_S2t) |
|
|
||
|
|
||
| def select_DTrange(kdst, low_DT, high_DT): | ||
| df_DTrange = kdst[(kdst.DT >= low_DT) & (kdst.DT <= high_DT)] |
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.
Use in_range
|
|
||
|
|
||
| def select_nsipm(kdst, low_nsipm, high_nsipm): | ||
| sel_nsipm = (kdst.Nsipm >= low_nsipm) & (kdst.Nsipm <= high_nsipm) |
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.
Use in_range
|
|
||
| df, eff_1S1_1S2 = select_1S1_1S2(df) | ||
|
|
||
| df, eff_S2t = select_S2t(df, low_S2t, high_S2t) |
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.
This one should go before the 1S1+1S2 selection, I think
| d = {'eff diffusion band': [eff_DT], 'eff X rays': [eff_Xrays], 'eff 1S1 & 1S2': [eff_1S1_1S2], | ||
| 'eff S2 trigger time': [eff_S2t], 'eff Rmax': [eff_Rmax], 'eff range DT': [eff_DTrange], | ||
| 'eff number of SiPMS': [eff_nsipm], 'total efficiency': [total_eff]} | ||
|
|
||
| df_efficiencies = pd.DataFrame(data = d) |
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.
You can also have numbers in the dictionary (instead of lists of 1 element) and then add index=[0] when creating the dataframe
…p with two columns for corrected energies
gonzaponte
left a comment
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.
More comments. We will need to build up a bit more testing and put everything together in a city.
|
|
||
| def normalization(krmap, method, xy_params = None): | ||
|
|
||
| mu_values = krmap.mu.dropna() |
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.
dropna should affect all options of method. Right now, it's only affecting the first two, the other three do not use this variable. You should redefine kr_map so it doesn't contain nan values.:
krmap = krmap.dropna(subset=["mu"]). Then use krmap.mu.something everywhere
| from scipy.interpolate import griddata | ||
|
|
||
|
|
||
| def normalization(krmap, method, xy_params = 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.
We will discuss how to do this with symbols
| E_reference_anode = mu_values_anode.mean() | ||
| return E_reference_anode | ||
|
|
||
| mask_region = (krmap['x'] <= xy_params['x_high']) & (krmap['x'] >= xy_params['x_low']) & (krmap['y'] <= xy_params['y_high']) & (krmap['y'] >= xy_params['y_low']) |
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.
use in_range
| region_mask = ( | ||
| (map_test.x <= 100) & (map_test.x >= -100) & | ||
| (map_test.y <= 100) & (map_test.y >= -100) | ||
| ) | ||
|
|
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.
in_range
|
|
||
| def gaussian_fit(df, ebins, min_events = 10): | ||
| if len(df)< min_events: | ||
| results = get_median(df) |
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.
| results = get_median(df) | |
| return get_median(df) |
| mask_df = ((df.X >= x1) & (df.X <= x1+2*shape_size) & (df.Y >= y1) & | ||
| (df.Y <= y1+2*shape_size)) |
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.
in_range
| def LT_fit(DT, s2e, p0): | ||
|
|
||
| f = fit.fit(fit.expo, DT, s2e, p0) | ||
| return f.values, (f[2][0], f[2][1]) |
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.
Probably not worth making a function just with this
| med_fun(empty_dst) | ||
|
|
||
|
|
||
| def test_gaussianfit_does_fit_right(): |
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.
| def test_gaussianfit_does_fit_right(): | |
| def test_gaussianfit_empty(): |
| result_med = med_fun(df_test) | ||
| assert result_med['nevents'].iloc[0] == N | ||
| assert fit_function(df_test, bins = 6)['nevents'].iloc[0] == N |
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.
| result_med = med_fun(df_test) | |
| assert result_med['nevents'].iloc[0] == N | |
| assert fit_function(df_test, bins = 6)['nevents'].iloc[0] == N | |
| result_med = med_fun(df_test) | |
| result_fit = fit_function(df_test, bins = 6) | |
| assert result_med['nevents'].iloc[0] == N | |
| assert result_fit['nevents'].iloc[0] == N |
| def test_merge_maps(): | ||
| Nan_map_test = create_empty_map(xy_range = (-500, 500), dt_range = (0, 1400), xy_nbins = 100, dt_nbins = 10) | ||
| d = {'nevents': np.empty(6, dtype = int), 'mu' : np.empty(6), 'sigma' : np.empty(6), 'mu_error' : np.empty(6), 'sigma_error' : np.empty(6)} | ||
| map_3D_test = pd.DataFrame(data = d, index = range(0, 6)) | ||
| assert merge_maps(Nan_map_test, map_3D_test).shape == Nan_map_test.shape |
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.
map_3D_test needs to contain the columns k, i, and j.
These scripts contain functions to: