Discontinuities examples

Code

#| echo: false
#| output: false
from juno.config import JunoConfig
import polars as pl
from datetime import timedelta
from discontinuitypy.utils.plot import plot_candidates
from beforerr.project import plotsdir
from beforerr.matplotlib import hide_fig_legend, hide_y_axes_label

Discontinuities in different AU from Juno

::: {#cell-4 .cell 0=‘e’ 1=‘x’ 2=‘p’ 3=‘o’ 4=‘r’ 5=‘t’ execution_count=9}

Code
from importlib.util import find_spec
import matplotlib.pyplot as plt

if find_spec("scienceplots"):
    import scienceplots as scienceplots
    plt.style.use(["science", "nature", "notebook"])

:::

Code
j_config = JunoConfig().find_events()
events = j_config.events.with_columns(pl.col("radial_distance").round())
shape: (1, 92)
time tstart tstop t.d_end t.d_start t.d_time index_diff len std std_prev std_next index_std index_fluctuation B.after B.before b_mag b_n bn_over_b d_star db_mag db_over_b db_over_b_max fit.stat.chisqr fit.stat.rsquared fit.vars.amplitude fit.vars.c fit.vars.sigma rotation_angle dB_x dB_y dB_z dB_lmn_x dB_lmn_y dB_lmn_z k_x k_y k_z B_background_y B_background_z n.before v_x_before v_y_before v_z_before n.after v_x_after v_y_after v_z_after v_l v_n v_k L_k j0_k ion_inertial_length Alfven_speed j_Alfven L_k_norm j0_k_norm v.ion.before.l v.ion.after.l B.vec.before.l B.vec.before.m B.vec.before.n B.vec.after.l B.vec.after.m B.vec.after.n v.Alfven.before v.Alfven.after v.Alfven.before.l v.Alfven.after.l n.change v.ion.change.l B.change v.Alfven.change v.Alfven.change.l
datetime[ns] datetime[ns] datetime[ns] datetime[ns] datetime[ns] datetime[ns] f64 u32 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64
2011-08-25 15:25:30 2011-08-25 15:25:00 2011-08-25 15:26:00 2011-08-25 15:25:44.503 2011-08-25 15:25:13.503 2011-08-25 15:25:31.189079012 1.28895 60 2.59028 0.892715 0.907528 2.854216 1.245153 3.41785 3.179654 3.247682 -0.698155 -0.21497 1.037873 0.238196 0.073343 0.128613 0.418534 0.997957 5.609134 -2.6382 1.351113 128.296648 -5.15 2.05 2.13 -5.913075 0.192051 -0.510453 0.491886 0.705298 0.510493 2.057567 1.459172 null null null null null null null null -396.585303 169.76004 200.265667 541.162948 4.124088 134.823335 41.927135 19.165405 4.013867 0.215184 NaN NaN -2.826809 -1.260165 -0.728927 3.086266 -1.452216 -0.218474 NaN NaN NaN NaN null NaN 0.238196 NaN NaN
Code
predicate = [
    pl.col("index_diff") > 1,
    pl.col("db_over_b_max") < 0.3,
]
rs = [1, 3, 5]

figure_opts = {
    "figwidth": 3.3,
    "figheight": 3,
}
fmt = "svg"

for r in rs:
    temp_predicate = predicate + [pl.col("radial_distance").round() == r]
    fig, ax = plot_candidates(
        j_config,
        predicate=temp_predicate,
        num=1,
        random=False,
        add_ids_properties=False,
        add_timebars=False,
    )[0]
    
    path = plotsdir() / "examples" / f"juno_id_example_r={r}.{fmt}"
    
    hide_fig_legend(fig)
    hide_y_axes_label(ax)
    fig.set(**figure_opts)
    fig.savefig(path)
2024-07-12 12:09:11.502 | INFO     | discontinuitypy.utils.plot:plot_candidates:265 - Candidates indices: [0]
12-Jul-24 12:09:12: UserWarning: Converting non-nanosecond precision datetime values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.

2024-07-12 12:09:12.312 | INFO     | discontinuitypy.utils.plot:plot_candidates:265 - Candidates indices: [66480]
12-Jul-24 12:09:12: UserWarning: Converting non-nanosecond precision datetime values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.

2024-07-12 12:09:12.867 | INFO     | discontinuitypy.utils.plot:plot_candidates:265 - Candidates indices: [78081]
12-Jul-24 12:09:13: UserWarning: Converting non-nanosecond precision datetime values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.

Strong current density in 5AU

Strong current density in 5AU from derivative method

Large derivative current density but small when using fitting

Code
j_config = JunoConfig(ts=0.125)
j_fit_config = JunoConfig(ts=0.125).load()
j_der_config = JunoConfig(ts=0.125, method='derivative').load()

print(
    len(j_fit_config.events),
    len(j_der_config.events)
)

j_config.events = j_fit_config.events.join(j_der_config.events, on='time').with_row_index()
print(len(j_config.events))

j_config.events = j_config.events.filter(
    pl.col("radial_distance") > 5,
    pl.col("j0_k_right") > 3
)
print(len(j_config.events))

# j_fit_config.events.join(j_der_config.events, on='time')
72656 94095
156532
1168
Code
indices = [153101, 156356, 156046]
offset = timedelta(seconds=0)
figs = j_config.plot_candidates(
    indices=indices,
    offset=offset,
    add_plasma_params=True,
    plot_current_density=True,
    plot_fit_data=True,
)
04-Mar-24 15:57:37: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 15:57:37: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 15:57:38: deriv_data was applied to: fgm_rot_tot_0-der

Random picking

Code
offset = timedelta(seconds=0)
figs = j_config.plot_candidates(
    num=3,
    add_plasma_params=True,
    offset=offset,
    plot_fit_data=True,
    plot_current_density=True,
    start_col = "tstart",
    end_col = "tstop"
)
2024-03-04 15:57:07.447 | INFO     | discontinuitypy.datasets:plot_candidates:245 - Candidates indices: [156049 156046 154208]
04-Mar-24 15:57:07: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 15:57:08: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 15:57:08: deriv_data was applied to: fgm_rot_tot_0-der

Fitting

Code
j_config = JunoConfig(ts=0.125).load()
j_config.events = j_config.events.with_row_index().filter(
    pl.col("radial_distance") > 5,
    # pl.col("j0_k") > 2
)
Code
indices = [72643, 72280, 69537]
offset = timedelta(seconds=2)
figs = j_config.plot_candidates(
    indices=indices,
    offset=offset,
    add_plasma_params=True,
    plot_current_density=True,
    plot_fit_data=True,
)
04-Mar-24 12:01:19: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.6/migration/

04-Mar-24 12:01:24: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 12:01:25: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 12:01:25: deriv_data was applied to: fgm_rot_tot_0-der

Code
offset = timedelta(seconds=2)
figs = j_config.plot_candidates(
    num=3,
    add_plasma_params=True,
    offset=offset,
    plot_fit_data=True,
    plot_current_density=True,
)
2024-03-04 14:41:02.337 | INFO     | discontinuitypy.datasets:plot_candidates:243 - Candidates indices: [71263 71875 71222]
04-Mar-24 14:41:02: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 14:41:03: deriv_data was applied to: fgm_rot_tot_0-der
04-Mar-24 14:41:03: deriv_data was applied to: fgm_rot_tot_0-der

Derivative

Code
j_config = JunoConfig(ts=0.125, method='derivative').load()
j_config.events = j_config.events.with_row_index().filter(
    pl.col("radial_distance") > 5,
    pl.col("j0_k") > 4
)
02-Mar-24 16:24:50: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.6/migration/
Code
offset  = timedelta(seconds=2)
Code
indices=[91384, 93825, 93618, 92389]
figs = j_config.plot_candidates(indices=indices, add_plasma_params=True, offset=offset, plot_current_density=True)
02-Mar-24 16:52:58: deriv_data was applied to: fgm_rot_tot_0-der
02-Mar-24 16:52:58: deriv_data was applied to: fgm_rot_tot_0-der
02-Mar-24 16:52:58: deriv_data was applied to: fgm_rot_tot_0-der
02-Mar-24 16:52:59: deriv_data was applied to: fgm_rot_tot_0-der

Code
figs = j_config.plot_candidates(num=3, add_plasma_params=True, offset=offset, plot_current_density=True)
2024-03-02 16:53:51.076 | INFO     | discontinuitypy.datasets:plot_candidates:243 - Candidates indices: [90260 92835 92303]
02-Mar-24 16:53:51: deriv_data was applied to: fgm_rot_tot_0-der
02-Mar-24 16:53:51: deriv_data was applied to: fgm_rot_tot_0-der
02-Mar-24 16:53:52: deriv_data was applied to: fgm_rot_tot_0-der

Code
offset  = timedelta(seconds=30)
figs = j_config.plot_candidates(num=15, add_plasma_params=True, offset=offset)
2024-03-02 16:53:24.688 | INFO     | discontinuitypy.datasets:plot_candidates:243 - Candidates indices: [92436 90663 92303 90640 92616 93261 93834 94014 94032 93294 92471 92343
 92972 93732 92478]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[35], line 4
      1 #| layout-ncol: 3
      2 #| column: screen
      3 offset  = timedelta(seconds=30)
----> 4 figs = j_config.plot_candidates(num=15, add_plasma_params=True, offset=offset)

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/discontinuitypy/datasets.py:245, in IDsDataset.plot_candidates(self, indices, num, random, predicate, **kwargs)
    242         indices = indices.head(num).to_numpy()
    243     logger.info(f"Candidates indices: {indices}")
--> 245 return [self.plot_candidate(index=i, **kwargs) for i in indices]

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/discontinuitypy/datasets.py:245, in <listcomp>(.0)
    242         indices = indices.head(num).to_numpy()
    243     logger.info(f"Candidates indices: {indices}")
--> 245 return [self.plot_candidate(index=i, **kwargs) for i in indices]

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/discontinuitypy/datasets.py:224, in IDsDataset.plot_candidate(self, event, index, **kwargs)
    222 if event is None:
    223     event = self.get_event(index)
--> 224 data = self.get_event_data(event, **kwargs)
    226 return _plot_candidate(event, data, **kwargs)

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/discontinuitypy/datasets.py:100, in IdsEvents.get_event_data(self, event, offset, **kwargs)
     97 end = event["t.d_end"] + offset
     99 _data = self.data.filter(pl.col("time").is_between(start, end))
--> 100 return df2ts(_data, self.bcols)

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/discontinuitypy/utils/basic.py:292, in df2ts(df, cols, time_col, attrs, name)
    289         cols = df.columns.tolist()
    291 if isinstance(df, pl.LazyFrame):
--> 292     df = df.collect()
    294 # Prepare data
    295 data = df[cols].to_numpy()

File ~/micromamba/envs/psp_conjunction/lib/python3.11/site-packages/polars/lazyframe/frame.py:1940, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, no_optimization, streaming, background, _eager)
   1937 if background:
   1938     return InProcessQuery(ldf.collect_concurrently())
-> 1940 return wrap_df(ldf.collect())

KeyboardInterrupt: