Datasets

This module contains the useful functions to deal with candidates datasets and individual candidate.

Datasets

Fundamental class


IdsEvents

 IdsEvents (name:str='events', data:polars.lazyframe.frame.LazyFrame=None,
            mag_meta:space_analysis.core.MagVariable=MagVariable(name=None
            , description=None, unit=None, ts=None, timerange=None,
            dataset=None, parameter=None, B_cols=None),
            ts:datetime.timedelta=None,
            events:polars.dataframe.frame.DataFrame=None,
            detect_func:Callable=<function detect_variance>,
            detect_kwargs:dict=<factory>,
            method:Literal['fit','derivative']='fit',
            file_fmt:str='arrow', file_path:pathlib.Path=Path('/home/runne
            r/work/discontinuitypy/discontinuitypy/data'),
            **extra_data:Any)

Core class to handle discontinuity events in a dataset.


IDsDataset

 IDsDataset (name:str='events',
             mag_data:polars.lazyframe.frame.LazyFrame=None, mag_meta:spac
             e_analysis.core.MagVariable=MagVariable(name=None,
             description=None, unit=None, ts=None, timerange=None,
             dataset=None, parameter=None, B_cols=None),
             ts:datetime.timedelta=None,
             events:polars.dataframe.frame.DataFrame=None,
             detect_func:Callable=<function detect_variance>,
             detect_kwargs:dict=<factory>,
             method:Literal['fit','derivative']='fit',
             file_fmt:str='arrow', file_path:pathlib.Path=Path('/home/runn
             er/work/discontinuitypy/discontinuitypy/data'),
             plasma_data:polars.lazyframe.frame.LazyFrame=None, plasma_met
             a:space_analysis.meta.PlasmaDataset=PlasmaDataset(timerange=N
             one, variables=None, name=None, dataset=None,
             parameters=None, ts=None, temperature_col=None,
             para_col=None, perp_cols=None, velocity_cols=None,
             speed_col=None, density_col=None),
             ion_temp_data:polars.lazyframe.frame.LazyFrame=None, ion_temp
             _meta:space_analysis.meta.TempDataset=TempDataset(timerange=N
             one, variables=None, name=None, dataset=None,
             parameters=None, ts=None, temperature_col=None,
             para_col=None, perp_cols=None),
             e_temp_data:polars.lazyframe.frame.LazyFrame=None, e_temp_met
             a:space_analysis.meta.TempDataset=TempDataset(timerange=None,
             variables=None, name=None, dataset=None, parameters=None,
             ts=None, temperature_col=None, para_col=None,
             perp_cols=None), **extra_data:Any)

Extend the IdsEvents class to handle plasma and temperature data.

Code
from loguru import logger


def log_event_change(event, logger=logger):
    logger.debug(
        f"""CHANGE INFO
        n.change: {event.get('n.change')}
        v.ion.change: {event.get('v.ion.change')}
        T.change: {event.get('T.change')}
        v.Alfven.change: {event.get('v.Alfven.change')}
        v.ion.change.l: {event.get('v.ion.change.l')}
        v.Alfven.change.l: {event.get('v.Alfven.change.l')}
        """
    )


# def overview_plot(
#     self, event: dict, start=None, stop=None, offset=timedelta(seconds=1), **kwargs
# ):
#     # BUG: to be fixed
#     start = start or event["tstart"]
#     stop = stop or event["tstop"]

#     start -= offset
#     stop += offset

#     _plasma_data = self.plasma_data.filter(
#         pl.col("time").is_between(start, stop)
#     ).collect()

#     _mag_data = (
#         self.data.filter(pl.col("time").is_between(start, stop))
#         .collect()
#         .melt(
#             id_vars=["time"],
#             value_vars=self.bcols,
#             variable_name="B comp",
#             value_name="B",
#         )
#     )

#     v_df = _plasma_data.melt(
#         id_vars=["time"],
#         value_vars=self.plasma_meta.velocity_cols,
#         variable_name="veloity comp",
#         value_name="v",
#     )

#     panel_mag = _mag_data.hvplot(
#         x="time", y="B", by="B comp", ylabel="Magnetic Field", **kwargs
#     )
#     panel_n = _plasma_data.hvplot(
#         x="time", y=self.plasma_meta.density_col, **kwargs
#     ) * _plasma_data.hvplot.scatter(
#         x="time", y=self.plasma_meta.density_col, **kwargs
#     )

#     panel_v = v_df.hvplot(
#         x="time", y="v", by="veloity comp", ylabel="Plasma Velocity", **kwargs
#     )
#     panel_temp = _plasma_data.hvplot(
#         x="time", y=self.plasma_meta.temperature_col, **kwargs
#     )

#     mag_vlines = hv.VLine(event["t_us"]) * hv.VLine(event["t_ds"])
#     plasma_vlines = hv.VLine(event.get("time_before")) * hv.VLine(
#         event.get("time_after")
#     )

#     logger.info(f"Overview plot: {event['tstart']} - {event['tstop']}")
#     log_event_change(event)

#     return (
#         panel_mag * mag_vlines
#         + panel_n * plasma_vlines
#         + panel_v * plasma_vlines
#         + panel_temp * plasma_vlines
#     ).cols(1)