e15190.runlog.query

Classes

AmBeQuery()

CosmicQuery()

ElogQuery([load_run_batches, ...])

MySqlQuery()

Query()

A class of query methods for the database.

ReactionParser([beams, targets, energies])

class e15190.runlog.query.Query

A class of query methods for the database.

Runlog queries are made from both the Elog database and the MySQL database.

For Elog queries, one can either directly make a query on the elog.df dataframe or use functions like get_run_info() to get the run information.

For MySQL queries, one can utilize the class MySqlQuery() or functions like get_runscalers(). Bear in mind that the entire MySQL database is huge. If you just want to explore the database, use clauses like LIMIT and WHERE to select a subset of the database for inspection.

Examples

Single run info can easily be queried as following:

>>> from e15190.runlog.query import Query
>>> Query.get_run_info(4100)
{'run': 4100,
 'begin_time': Timestamp('2018-03-11 03:40:40'),
 'end_time': Timestamp('2018-03-11 04:12:19'),
 'elapse': Timedelta('0 days 00:31:39'),
 'target': 'Ni64',
 'beam': 'Ca48',
 'beam_energy': 140.0,
 'shadow_bar': 'in',
 'trigger_rate': 2463.0,
 'comment': '140MeV 64Ni, coincidence trigger, uB DS, RF trig'}

Batch info is queried as following:

>>> from e15190.runlog.query import Query
>>> Query.get_batch_info(2)
{'ibatch': 2,
 'run_range': [2142, 2152],
 'n_runs': 9,
 'n_skipped_runs': 2,
 'begin_time': Timestamp('2018-02-12 22:06:15'),
 'end_time': Timestamp('2018-02-13 03:25:30'),
 'total_elapse': Timedelta('0 days 04:39:29'),
 'total_gap_time': Timedelta('0 days 00:39:46'),
 'target': 'Ni58',
 'beam': 'Ca40',
 'beam_energy': 140.0,
 'shadow_bar': 'out',
 'trigger_rate_range': [1861.0, 2044.0],
 'trigger_rate_stdev': 70.8092115790343,
 'comment': ['Ni 58 Ca40 140MeV/u, coincidence data delayed triggers 150ns',
  'Ni 58 Ca40 140MeV/u, coincidence data delayed triggers 150ns(1) Before
  this run: 1) delayed hira+NW master by 150 ns, 2) dleayed fast clear by
  150ns; 3)increased the fast busy by 150 ns.']}

Run scalers can be queried as following:

>>> from e15190.runlog.query import Query
>>> Query.get_runscalers(4100, 'nw')
      run              datetime  VW-TOP-OR  VW-BOT-OR  VW-TOP-BOT-OR  VW-GATE \
0    4100   2018-03-11 03:41:16      22180      10953          15913    88002
1    4100   2018-03-11 03:41:18      22357      10921          16020    87246
2    4100   2018-03-11 03:41:20      22450      11015          16040    86622
3    4100   2018-03-11 03:41:22      22343      11032          16013    86232
4    4100   2018-03-11 03:41:24      22285      10985          15920    86526
..    ...                   ...        ...        ...            ...      ...
881  4100   2018-03-11 04:12:03      21756      10761          15676    86893
882  4100   2018-03-11 04:12:05      21774      10732          15644    87262
883  4100   2018-03-11 04:12:08      21759      10772          15713    86451
884  4100   2018-03-11 04:12:10      22263      11032          16027    86564
885  4100   2018-03-11 04:12:12      22271      10727          16023    88343
---
     VW-FCLR  MASTER  MASTER2  VW-DELAY   FA-OR  DSS-OR  NW-RAW  NW-LIVE \
0      85224    5023     5023         0  808973       0  213598    88002
1      84507    4940     4940         0  804762       0  210173    87246
2      83929    4972     4972         0  800139       0  210713    86622
3      83446    5040     5040         0  796532       0  211062    86232
4      83829    5024     5024         0  796509       0  211055    86526
..       ...     ...      ...       ...     ...     ...     ...      ...
881    84172    4929     4929         0  793584       0  207542    86893
882    84657    4882     4882         0  796243       0  207361    87262
883    83769    4907     4907         0  790993       0  206080    86451
884    83803    4986     4986         0  792586       0  208633    86564
885    85664    4871     4871         0  808603       0  208472    88343
elog = <e15190.runlog.query.ElogQuery object>

Class attribute ElogQuery object loaded with run batches.

static get_ibatch(run) → int

Returns the batch number of the run

Parameters

run (int) –

static _get_run_query(run) → pandas.core.frame.DataFrame

Returns sub-dataframe of ElogQuery.df in Query.elog for a given run.

Parameters

run (int) – Run number.

static get_run_info(run, include_ibatch=True) → Dict[str, Any]

Returns a dictionary of properties for a given run.

Parameters

run (int) –

static _get_batch_query(ibatch) → pandas.core.frame.DataFrame

Returns a sub-dataframe of ElogQuery.df in Query.elog for a given batch number.

Parameters

ibatch (int) – Batch number (0-indexed).

static is_good(run) → bool

Returns whether a given run is good.

Parameters

run (int) – Run number.

Returns

is_good_ – Whether the run is good. Not good would mean this run should be skipped in data analysis.

Return type

bool

static are_good(runs) → List[bool]

Returns whether a list of runs are good.

Parameters

runs (list) – List of runs.

Returns

are_good_ – Whether the runs are good. Bad would mean the runs should be skipped in data analysis.

Return type

list of bool

static get_batch(ibatch) → pandas.core.frame.DataFrame

Returns a sub-dataframe of ElogQuery.df in Query.elog for a given batch number.

The sub-dataframe has been re-indexed from zero.

Parameters

ibatch (int) – Batch number (0-indexed).

static get_batch_runs(ibatch) → List[int]

Returns runs in a given batch.

Parameters

ibatch (int) – Batch number (0-indexed).

static get_batch_info(ibatch, include_comments=True, include_runs=True) → Dict[str, Any]

Returns a dictionary of properties for a given batch.

This function basically reads off from the ElogQuery.df_batches dataframe.

Parameters
  • ibatch (int) – Batch number (0-indexed).

  • include_comments (bool, default True) – Whether to include the comments in the returned dictionary. If True, the comments are included as a list of strings, sorted from the most common to the least common; if there is only one comment, the list is reduced into a string. If False, the comments are not included, i.e. the key 'comment' is mapped to None.

  • include_runs (bool, default True) – Whether to include the runs in the returned dictionary. If True, the runs are included as a list of integers, sorted from the smallest to the largest. If False, the runs are not included, and the key 'runs' will not be found in the returned dictionary.

static get_n_batches() → int

Returns the number of batches in the database.

static targets() → List[str]

Returns all distinct target names in the database.

static beams() → List[str]

Returns all distinct beam names in the database.

static beam_energies() → List[float]

Returns all distinct beam energies in the database.

static select_runs(cut, comment_cut=None, **kw_comment) → List[int]

Returns a list of run numbers that satisfy the given cuts.

Parameters
  • cut (str) – A string that can be evaluated as a boolean expression. The following variables are can be specified in the expression: - ibatch (int) - run (int) - begin_time (Timestamp) - end_time (Timestamp) - elapse (Timedelta) - target (str) - beam (str) - beam_energy (float) - shadow_bar (“in” or “out”) - trigger_rate (float) - comment (str)

  • comment_cut (str, default None) –

    Character sequence or regular expression to match the comment.

    While the variable comment can be specified in the argument cut, it is usually more helpful to use comment_cut, which invokes a simple wrapper around the Series.str.contains method. This allows more complex string matching like case insensitive matching and regular expressions.

  • **kw_comment (dict) – Keyword arguments to be passed to the Series.str.contains method.

Returns

runs – A list of run numbers that satisfy the given cuts.

Return type

list

Examples

As our first example, we select all runs with target Ni58:

>>> from e15190.runlog.query import Query
>>> Query.select_runs('target == "Ni58"')
[2134, 2135, 2142, ..., 4617, 4618, 4619]

In the second example, we select all runs with Ca40 + Ni58 at 140 MeV/u with shadow bars:

>>> from e15190.runlog.query import Query
>>> Query.select_runs('beam == "Ca40" & target == "Ni64"\
...  & beam_energy == 56 & shadow_bar == "in"')
[2512, 2513, 2514, 2515, 2517, 2518, 2519, 2520, 2521, 2522, 2523]

In the last example, we select runs that have comments that contain substring 'mb singles 301':

>>> from e15190.runlog.query import Query
>>> Query.select_runs(
...     'beam == "Ca48" & beam_energy == 56',
...      comment_cut='mb singles 301',
...      case=False, # case insensitive matching
... )
[4593, 4594, 4595, ..., 4659, 4660, 4661]
static select_batches(cut) → List[int]

Returns a list of batch numbers that satisfy the given cuts.

Comment cut is not supported. But users can easily use this function to first select the batches of interest, then invoke Query.select_runs() to further select on the comments with more complicated matching patterns.

Parameters

cut (str) –

A string that can be evaluated as a boolean expression. The following variables are can be specified in the expression:

  • ibatch (int): batch number (0-indexed)

  • run_min (int): first run numbe

  • run_max (int): last run number

  • n_runs (int): number of runs in the batch

  • n_skipped_runs (int): number of runs skipped in the batch

  • begin_time (Timestamp): start time of the first run

  • end_time (Timestamp): end time of the last run

  • total_elapse (Timedelta): total elapsed time of all the runs

  • total_gap_time (Timedelta): total gap time of between all the runs

  • target (str): e.g. Ni58, Ni64, Sn112, Sn124

  • beam (str): e.g. Ca40, Ca48

  • beam_energy (float): beam energy in MeV/u

  • shadow_bar (str): “in” or “out”

  • trigger_rate_min (float): minimum trigger rate

  • trigger_rate_max (float): maximum trigger rate

  • trigger_rate_mean (float): mean trigger rate

Returns

ibatches – A list of batch numbers that satisfy the given cuts.

Return type

list

Examples

>>> from e15190.runlog.query import Query
>>> Query.select_batches('n_runs > 35')
[22, 33, 49]
static get_runscalers(run, source) → pandas.core.frame.DataFrame
Parameters
  • run (int) – Run number.

  • source (str or int) – Source name ('hira' or 'nw') or number (0 or 1), respectively.

Returns

scalers – A dataframe containing datetime and scaler values.

Return type

pd.DataFrame

static get_runscalernames(source) → List[str]
Parameters

source (str or int) – Source name ('hira' or 'nw') or number (0 or 1), respectively.

Returns

scaler_names – A list of scaler names, i.e. all the columns except 'run' and 'datetime'.

Return type

list of str

static get_runscalernames_channel_map() → pandas.core.frame.DataFrame
Returns

channel_map – A dataframe containing the mapping between scaler names and channels. Other columns like 'description' and 'wmu_name' are also included; ‘’wmu_name’’ is the name used by Western Michigan University (WMU).

Return type

pd.DataFrame