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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
70 changes: 62 additions & 8 deletions docs/swapi/figure_src/figure_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,68 @@ def load_swapi_response() -> SwapiResponse:

COARSE_SWEEP_VOLTAGES_MEAN_V = np.array(
[
9895.52, 9088.69, 8348.80, 7667.55, 7042.16, 6469.31, 5941.77, 5457.31,
5013.22, 4603.65, 4230.77, 3886.92, 3569.16, 3278.72, 3011.13, 2766.25,
2539.54, 2333.83, 2144.24, 1969.31, 1808.74, 1660.86, 1525.75, 1401.82,
1287.58, 1182.24, 1085.15, 995.55, 914.31, 839.94, 771.70, 709.46,
651.59, 598.47, 549.91, 505.12, 463.89, 425.92, 391.18, 359.35,
329.94, 303.02, 278.25, 255.55, 234.77, 215.61, 197.95, 181.82,
167.04, 153.46, 140.91, 129.50, 118.91, 109.20, 100.30, 92.11,
84.61, 77.73, 71.40, 65.59, 60.23, 55.34,
9895.52,
9088.69,
8348.80,
7667.55,
7042.16,
6469.31,
5941.77,
5457.31,
5013.22,
4603.65,
4230.77,
3886.92,
3569.16,
3278.72,
3011.13,
2766.25,
2539.54,
2333.83,
2144.24,
1969.31,
1808.74,
1660.86,
1525.75,
1401.82,
1287.58,
1182.24,
1085.15,
995.55,
914.31,
839.94,
771.70,
709.46,
651.59,
598.47,
549.91,
505.12,
463.89,
425.92,
391.18,
359.35,
329.94,
303.02,
278.25,
255.55,
234.77,
215.61,
197.95,
181.82,
167.04,
153.46,
140.91,
129.50,
118.91,
109.20,
100.30,
92.11,
84.61,
77.73,
71.40,
65.59,
60.23,
55.34,
]
)

Expand Down
12 changes: 7 additions & 5 deletions docs/swapi/figure_src/plot_alpha_peak_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ def _read_5_sweep_block(

def _coarse_measurement_times_ns(epoch_ns: np.ndarray) -> np.ndarray:
coarse_bins = np.arange(SWAPI_COARSE_SWEEP_BINS.start, SWAPI_COARSE_SWEEP_BINS.stop)
seconds_into_sweep = coarse_bins * SWAPI_BIN_PERIOD_S + SWAPI_LIVETIME_CENTER_OFFSET_S
return (epoch_ns[:, None] + seconds_into_sweep * ONE_SECOND_IN_NANOSECONDS).flatten()
seconds_into_sweep = (
coarse_bins * SWAPI_BIN_PERIOD_S + SWAPI_LIVETIME_CENTER_OFFSET_S
)
return (
epoch_ns[:, None] + seconds_into_sweep * ONE_SECOND_IN_NANOSECONDS
).flatten()


# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -261,9 +265,7 @@ def _plot_case(ax, swapi_response, cdf_path, mag_data, chunk_index):
proton_moments=proton_moments,
magnetic_field_direction=b_hat,
)
alpha_velocity_rtn = np.array(
[c.nominal_value for c in alpha_moments.velocity_rtn]
)
alpha_velocity_rtn = np.array([c.nominal_value for c in alpha_moments.velocity_rtn])
alpha_sw = SolarWindParams(
density=alpha_moments.density.nominal_value,
velocity_rtn=alpha_velocity_rtn,
Expand Down
6 changes: 5 additions & 1 deletion docs/swapi/figure_src/plot_collapsed_response_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
from imap_l3_processing.constants import HE_PUI_PARTICLE_MASS_PER_CHARGE_M_P_PER_E

_REFERENCE_CSV_PATH = (
REPO_ROOT / "tests" / "test_data" / "swapi" / "collapsed_response_grid_reference.csv"
REPO_ROOT
/ "tests"
/ "test_data"
/ "swapi"
/ "collapsed_response_grid_reference.csv"
)

_ESA_VOLTAGE = 5000.0
Expand Down
6 changes: 3 additions & 3 deletions docs/swapi/figure_src/plot_fit_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _plot_results(data: pd.DataFrame) -> None:
marker="o",
zorder=2,
label="Initial guess",
rasterized=True
rasterized=True,
)
ax.errorbar(
truth[good],
Expand Down Expand Up @@ -344,7 +344,7 @@ def _plot_results(data: pd.DataFrame) -> None:
edgecolors="k",
linewidths=0.4,
zorder=4,
rasterized=True
rasterized=True,
)
ax.scatter(
truth[~good],
Expand All @@ -356,7 +356,7 @@ def _plot_results(data: pd.DataFrame) -> None:
edgecolors="k",
linewidths=0.4,
zorder=4,
rasterized=True
rasterized=True,
)

ax.set_xlabel(f"True {label}", fontsize=9)
Expand Down
4 changes: 1 addition & 3 deletions docs/swapi/figure_src/plot_passband_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def plot_region_panel(
grid, grid.max_boundary, active_elevations, np.maximum
)

image = draw_transmission_heatmap(
axis, grid.values, elevations, speed_ratios
)
image = draw_transmission_heatmap(axis, grid.values, elevations, speed_ratios)
draw_integration_window_outline(
axis, active_elevations, lower_speed_ratios, upper_speed_ratios
)
Expand Down
65 changes: 45 additions & 20 deletions docs/swapi/figure_src/plot_pui_cutoff_staircase.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@

from figure_utils import FIGURES_DIR, load_swapi_response

from imap_l3_processing.constants import HE_PUI_PARTICLE_MASS_PER_CHARGE_M_P_PER_E, ONE_AU_IN_KM
from imap_l3_processing.constants import (
HE_PUI_PARTICLE_MASS_PER_CHARGE_M_P_PER_E,
ONE_AU_IN_KM,
)
from imap_l3_processing.swapi.l3a.science.pickup_ion.calculate_coincidence_rate import (
apply_partial_heaviside_at_cutoff,
calculate_coincidence_rate,
Expand All @@ -53,7 +56,9 @@
FittingParameters,
VasyliunasSiscoeDistribution,
)
from imap_l3_processing.swapi.l3a.utils import velocity_components_to_angles_in_instrument_frame
from imap_l3_processing.swapi.l3a.utils import (
velocity_components_to_angles_in_instrument_frame,
)

_SW_SPEED_KMS = 450.0
_SW_AZIMUTH_DEG = 0.0
Expand Down Expand Up @@ -90,9 +95,13 @@ def _params(cutoff_speed_kms: float) -> FittingParameters:


def main():
voltages = pd.read_csv(
REPO_ROOT / "tests" / "test_data" / "swapi" / "pui_count_rate_reference.csv"
).iloc[:, 0].to_numpy()
voltages = (
pd.read_csv(
REPO_ROOT / "tests" / "test_data" / "swapi" / "pui_count_rate_reference.csv"
)
.iloc[:, 0]
.to_numpy()
)
voltage_index = int(np.argmin(np.abs(voltages - _ESA_VOLTAGE_V)))

swapi_response = load_swapi_response()
Expand All @@ -109,11 +118,13 @@ def main():

azimuth_rad = np.radians(_SW_AZIMUTH_DEG)
elevation_rad = np.radians(_SW_ELEVATION_DEG)
bulk_vec = _SW_SPEED_KMS * np.array([
-np.cos(elevation_rad) * np.sin(azimuth_rad),
-np.cos(elevation_rad) * np.cos(azimuth_rad),
-np.sin(elevation_rad),
])
bulk_vec = _SW_SPEED_KMS * np.array(
[
-np.cos(elevation_rad) * np.sin(azimuth_rad),
-np.cos(elevation_rad) * np.cos(azimuth_rad),
-np.sin(elevation_rad),
]
)
bulk_per_bin = np.broadcast_to(bulk_vec, (1, voltages.size, 3)).copy()

chunk_response = build_chunk_collapsed_response(
Expand All @@ -130,8 +141,10 @@ def main():
bin_weights = chunk_response.bin_weights[0, voltage_index, :]

# Fine-grid reference response for the same voltage step.
bulk_azimuth_deg, bulk_elevation_deg = velocity_components_to_angles_in_instrument_frame(
bulk_vec[0], bulk_vec[1], bulk_vec[2]
bulk_azimuth_deg, bulk_elevation_deg = (
velocity_components_to_angles_in_instrument_frame(
bulk_vec[0], bulk_vec[1], bulk_vec[2]
)
)
fine_grid = np.linspace(1.0, _GRID_MAX_KMS, _FINE_GRID_POINTS)
fine_collapsed = build_collapsed_response_grid(
Expand All @@ -145,9 +158,7 @@ def main():
bulk_elevation_deg,
speed_in_sw_frame=fine_grid,
)
fine_weights = (
fine_collapsed.values * fine_grid**2 * (fine_grid[1] - fine_grid[0])
)
fine_weights = fine_collapsed.values * fine_grid**2 * (fine_grid[1] - fine_grid[0])

# Below the neutral-helium LUT support the distribution is physically zero;
# the LUT extrapolation returns non-finite values there, so clamp them.
Expand Down Expand Up @@ -190,15 +201,26 @@ def sampled_distribution(grid, params, apply_cutoff):
axis.axvline(grid_edges[0], color="0.85", lw=0.8, zorder=0, label="$v'$ grid edges")

axis.plot(
_CUTOFF_SWEEP_KMS, rate_reference, "-", color="0.4", lw=1,
label=f"fine-grid reference",
_CUTOFF_SWEEP_KMS,
rate_reference,
"-",
color="0.4",
lw=1,
label="fine-grid reference",
)
axis.scatter(
_CUTOFF_SWEEP_KMS, rate_without, color="tab:red", s=10,
_CUTOFF_SWEEP_KMS,
rate_without,
color="tab:red",
s=10,
label="no correction",
)
axis.scatter(
_CUTOFF_SWEEP_KMS, rate_with, color="tab:blue", s=10, marker='x',
_CUTOFF_SWEEP_KMS,
rate_with,
color="tab:blue",
s=10,
marker="x",
label="with correction",
)

Expand All @@ -207,7 +229,10 @@ def sampled_distribution(grid, params, apply_cutoff):
axis.set_xlim(_CUTOFF_SWEEP_KMS[0], _CUTOFF_SWEEP_KMS[-1])
axis.annotate(
rf"grid $\Delta v' = {delta_v_prime:.2f}$ km/s",
xy=(0.02, 0.04), xycoords="axes fraction", fontsize=9, color="0.3",
xy=(0.02, 0.04),
xycoords="axes fraction",
fontsize=9,
color="0.3",
)
axis.grid(True, alpha=0.3)
axis.legend(loc="upper left")
Expand Down
4 changes: 3 additions & 1 deletion docs/swapi/figure_src/plot_pui_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def main():
label=r"cutoff speed $v_b$",
)
axis.set_yscale("log")
axis.set_xlabel(r"Comoving speed $v' = \|\mathbf{v} - \mathbf{v}_\text{sw}\|$ [km/s]")
axis.set_xlabel(
r"Comoving speed $v' = \|\mathbf{v} - \mathbf{v}_\text{sw}\|$ [km/s]"
)
axis.set_ylabel(r"$f_\text{PUI}(v')$ [s$^3$ km$^{-6}$]")
axis.set_xlim(speed_in_sw_frame[0], speed_in_sw_frame[-1])
axis.set_ylim(1e0, 1e4)
Expand Down
38 changes: 23 additions & 15 deletions docs/swapi/figure_src/plot_pui_reference_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def compute_production_rates(voltages_v: np.ndarray) -> np.ndarray:

sw_az_rad = np.radians(_SW_AZIMUTH_DEG)
sw_el_rad = np.radians(_SW_ELEVATION_DEG)
bulk_vec = _SW_SPEED_KMS * np.array([
-np.cos(sw_el_rad) * np.sin(sw_az_rad),
-np.cos(sw_el_rad) * np.cos(sw_az_rad),
-np.sin(sw_el_rad),
])
bulk_sw_per_bin = np.broadcast_to(
bulk_vec, (1, voltages_v.size, 3)
).copy()
bulk_vec = _SW_SPEED_KMS * np.array(
[
-np.cos(sw_el_rad) * np.sin(sw_az_rad),
-np.cos(sw_el_rad) * np.cos(sw_az_rad),
-np.sin(sw_el_rad),
]
)
bulk_sw_per_bin = np.broadcast_to(bulk_vec, (1, voltages_v.size, 3)).copy()

swapi_response = load_swapi_response()
swapi_response.warm_cache(voltages_v)
Expand All @@ -115,7 +115,9 @@ def compute_production_rates(voltages_v: np.ndarray) -> np.ndarray:
min_speed_kms=min_speed_kms,
central_effective_area_scale=_HELIUM_EFFICIENCY_RATIO,
)
return calculate_coincidence_rate(chunk_response, vasyliunas_siscoe_distribution, fitting_params)[0]
return calculate_coincidence_rate(
chunk_response, vasyliunas_siscoe_distribution, fitting_params
)[0]


def main():
Expand All @@ -133,11 +135,17 @@ def main():
)
sw_az_rad = np.radians(_SW_AZIMUTH_DEG)
sw_el_rad = np.radians(_SW_ELEVATION_DEG)
bulk_vec = _SW_SPEED_KMS * np.array([
-np.cos(sw_el_rad) * np.sin(sw_az_rad),
-np.cos(sw_el_rad) * np.cos(sw_az_rad),
-np.sin(sw_el_rad),
]) + 0.0 # normalize -0.0 to +0.0 for display
bulk_vec = (
_SW_SPEED_KMS
* np.array(
[
-np.cos(sw_el_rad) * np.sin(sw_az_rad),
-np.cos(sw_el_rad) * np.cos(sw_az_rad),
-np.sin(sw_el_rad),
]
)
+ 0.0
) # normalize -0.0 to +0.0 for display
axes[0].set_title(
f"PUI He coincidence rate — m/q={_HELIUM_MASS_PER_CHARGE_M_P_PER_E:.0f}, "
f"efficiency ratio={_HELIUM_EFFICIENCY_RATIO:.2f}\n"
Expand Down Expand Up @@ -165,7 +173,7 @@ def main():
".",
color="red",
label="Optimized",
markersize=4
markersize=4,
)
rel_err = np.abs(production_rate_hz - count_rate_hz) / count_rate_hz
axes[1].semilogy(voltage_v, rel_err, ".", color="red")
Expand Down
Loading
Loading