-
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?
Changes from all commits
be202ce
f5e80e7
639c67c
196bb7d
0ee5db0
27c2632
7e66555
7ae012e
b4ee6fb
4ee1dd5
bf7c147
3984730
5f9baea
a79497b
b4b0895
0023370
846c8be
405d528
5c0f4c0
c4e94ea
a86acf4
068f521
ee5480c
27065c5
45f640c
80eec15
d3095fe
fffafe1
de04df5
9b9fcf6
e9b9e6f
e9e53d2
e62aab7
fdee97e
1a485fe
9d6d21a
68ed946
3efa220
6f9a9e5
2d43137
2185eca
92023cb
f5eed65
627315e
91432d5
02a4991
23319f7
9cee111
7dbcb49
9d210dd
cb216df
c547809
b8f494e
75679e9
47af789
5368c9a
f3b15bf
71a963e
d389b96
032a630
56eb4b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import pandas as pd | ||
| import numpy as np | ||
| from scipy.interpolate import griddata | ||
|
|
||
|
|
||
| def normalization(krmap, method, xy_params = None): | ||
|
|
||
| mu_values = krmap.mu.dropna() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| anode = krmap[krmap.k == 0] | ||
|
|
||
| if method == 'max': | ||
| E_reference_max = mu_values.max() | ||
| return E_reference_max | ||
|
|
||
| if method == 'mean chamber': | ||
| E_reference_chamber = mu_values.mean() | ||
| return E_reference_chamber | ||
|
|
||
| if method == 'median chamber': | ||
| E_median_chamber = mu_values.median() | ||
| return E_median_chamber | ||
|
|
||
| if method == 'mean anode': | ||
| mu_values_anode = anode.mu | ||
| E_reference_anode = mu_values_anode.mean() | ||
| return E_reference_anode | ||
|
|
||
| if method == 'median anode': | ||
| mu_median_anode = anode.mu | ||
| E_median_anode = mu_median_anode.median() | ||
| return E_median_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']) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
|
||
| if method == 'mean region anode': | ||
| region = anode[mask_region] | ||
| E_reference_slice_anode = region.mu.mean() | ||
| return E_reference_slice_anode | ||
|
|
||
| if method == 'mean region chamber': | ||
| region = krmap[mask_region] | ||
| E_reference_region = region.mu.mean() | ||
| return E_reference_region | ||
|
|
||
| if method == 'median region anode': | ||
| region = anode[mask_region] | ||
| E_median_region_anode = region.mu.median() | ||
| return E_median_region_anode | ||
|
|
||
| if method == 'median region': | ||
| region = krmap[mask_region] | ||
| E_median_region = region.mu.median() | ||
| return E_median_region | ||
|
|
||
|
|
||
| def apply_3Dmap(krmap, norm_method, dt, x, y, E, xy_params = None, keV = False): | ||
|
|
||
| map_points = krmap['dt x y'.split()].values | ||
| norm = normalization(krmap, norm_method, xy_params) | ||
|
|
||
| data_points = np.stack([dt, x, y], axis = 1) | ||
| E_interpolated_data = griddata(map_points, krmap.mu.values, data_points, method = 'nearest') | ||
|
|
||
| correction_factor = norm/E_interpolated_data | ||
| Ec = E * correction_factor | ||
|
|
||
| if keV: | ||
| Ec = Ec * (41.55 / norm) | ||
|
|
||
| return Ec | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| import pandas as pd | ||
| from correction_functions import normalization, apply_3Dmap | ||
|
|
||
|
|
||
| def test_method_norm(): | ||
|
|
||
| k_vals = np.arange(10) | ||
| i_vals = np.arange(12) | ||
| j_vals = np.arange(12) | ||
|
|
||
|
|
||
| k, i, j = map(np.ravel, | ||
| np.meshgrid(k_vals, i_vals, j_vals, indexing= 'ij')) | ||
|
|
||
| x = i * 25 | ||
| y = j * 25 | ||
| dt = k * 45 | ||
|
|
||
| mu = (k*i + 800)*j | ||
|
|
||
| map_test = pd.DataFrame({ | ||
| 'k': k, | ||
| 'i': i, | ||
| 'j': j, | ||
| 'x': x, | ||
| 'y': y, | ||
| 'dt': dt, | ||
| 'mu': mu | ||
| }) | ||
|
|
||
| region_mask = ( | ||
| (map_test.x <= 100) & (map_test.x >= -100) & | ||
| (map_test.y <= 100) & (map_test.y >= -100) | ||
| ) | ||
|
|
||
|
Comment on lines
+33
to
+37
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert normalization(map_test, 'max', None, None, None, None) == 9889 | ||
| assert normalization(map_test, 'mean chamber', None, None, None, None) == 4536.125 | ||
| assert normalization(map_test, 'mean anode', None, None, None, None) == 4400 | ||
| assert normalization(map_test, 'mean region anode', -100, 100, -100, 100) == map_test.loc[(map_test.k == 0) & region_mask,'mu'].mean() | ||
| assert normalization(map_test, 'mean region chamber', -100, 100, -100, 100) == map_test.loc[region_mask,'mu'].mean() | ||
|
|
||
| assert normalization(map_test, 'median chamber', None, None, None, None) == 4647.5 | ||
| assert normalization(map_test, 'median anode', None, None, None, None) == 4400.0 | ||
| assert normalization(map_test, 'median region anode', -100, 100, -100, 100) == map_test.loc[(map_test.k == 0) & region_mask, 'mu'].median() | ||
| assert normalization(map_test, 'median region chamber', -100, 100, -100, 100) == map_test.loc[region_mask, 'mu'].median() | ||
|
|
||
|
|
||
| def test_apply_3Dmap(): | ||
|
|
||
| n = 100 | ||
| dt = np.linspace(20, 1350, n) | ||
| x = np.linspace(-450, 450, n) | ||
| y = x | ||
| E = np.linspace(7e3, 9e3, n) | ||
| data_points_test = np.stack([dt, x, y], axis = 1) | ||
|
|
||
|
|
||
| k_vals = np.arange(10) | ||
| i_vals = np.arange(12) | ||
| j_vals = np.arange(12) | ||
|
|
||
|
|
||
| k, i, j = map(np.ravel, | ||
| np.meshgrid(k_vals, i_vals, j_vals, indexing= 'ij')) | ||
|
|
||
| x = i * 25 | ||
| y = j * 25 | ||
| dt = k * 45 | ||
|
|
||
| mu = (k*i + 800)*j | ||
|
|
||
| map_test = pd.DataFrame({ | ||
| 'k': k, | ||
| 'i': i, | ||
| 'j': j, | ||
| 'x': x, | ||
| 'y': y, | ||
| 'dt': dt, | ||
| 'mu': mu | ||
| }) | ||
|
|
||
| map_points = map_test['dt x y'.split()].values | ||
|
|
||
| E_interpolated_data = griddata(map_points, map_test.mu.values, data_points_test, method = 'nearest') | ||
|
|
||
| Ec = apply_3Dmap(map_test, norm_method = 'max', dt, x, y, E, keV = True) | ||
|
|
||
| assert len(Ec) == len(dt) | ||
| assert len(E_interpolated_data) == len(data_points_test) | ||
|
|
||
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