zabgrab.cli.reading

Options and helpers shared by commands that read a file’s merged data.

zabgrab export, zabgrab info and zabgrab plot select items, times and groups the same way.

Functions

bin_option(function)

Add the --bin option.

check_readable(file, verb)

Refuse delimited files, which commands reading merged data can't read.

log_option(help)

Make the --log option, with its old name --log-y hidden.

nothing_selected(file)

Suggest how to find what to select in a file, when nothing was.

read_dataset(app, file, *, verb, items, ...)

Read a file's merged data, limited to the selected items, times and groups.

selection_options(function)

Add the --item, --match, --from, --to and --group options.

time_range(app, from_, to)

Parse --from and --to, in the configured time zone.

use_log(app, log, log_y)

Combine --log and its old name, warning about the old one.

zabgrab.cli.reading.selection_options(function)[source]

Add the --item, --match, --from, --to and --group options.

Parameters:

function (callable) – The click command to add them to.

Returns:

callable – The command, taking items, match, from_, to and groups arguments.

Return type:

F

zabgrab.cli.reading.bin_option(function)[source]

Add the --bin option.

Parameters:

function (callable) – The click command to add it to.

Returns:

callable – The command, taking a bins argument (a Bins, or None).

Return type:

F

zabgrab.cli.reading.log_option(help)[source]

Make the --log option, with its old name --log-y hidden.

--log-y was renamed --log in 1.1.0, since with --bin it applies to the counts, along the horizontal axis. The old name still works, with a warning, until 2.0.

Parameters:

help (str) – The option’s help.

Returns:

callable – A decorator adding the options, which the command takes as log and log_y arguments; pass them to use_log().

Return type:

Callable[[F], F]

zabgrab.cli.reading.use_log(app, log, log_y)[source]

Combine --log and its old name, warning about the old one.

Parameters:
  • app (AppContext) – For the UI.

  • log (bool) – Whether --log and --log-y were given.

  • log_y (bool) – Whether --log and --log-y were given.

Returns:

bool – Whether to use log scales.

Return type:

bool

zabgrab.cli.reading.read_dataset(app, file, *, verb, items, match, from_, to, groups)[source]

Read a file’s merged data, limited to the selected items, times and groups.

Parameters:
  • app (AppContext) – For the config (the time zone --from/--to are in), clock and UI.

  • file (Path) – A .mat or .h5 file written by zabgrab.

  • verb ((str, str)) – What the command does, and its past participle, for messages (e.g. ("export", "exported")).

  • items (Sequence[ItemSpec]) – The --item, --match, --from, --to and --group values. Items are kept if any --item or --match selects them.

  • match (Sequence[str]) – The --item, --match, --from, --to and --group values. Items are kept if any --item or --match selects them.

  • from – The --item, --match, --from, --to and --group values. Items are kept if any --item or --match selects them.

  • to (str | None) – The --item, --match, --from, --to and --group values. Items are kept if any --item or --match selects them.

  • groups (Sequence[str]) – The --item, --match, --from, --to and --group values. Items are kept if any --item or --match selects them.

  • from_ (str | None)

Returns:

  • Dataset – The merged, filtered data.

  • tzinfo or None – The configured time zone (None for local time).

Raises:
Return type:

tuple[Dataset, tzinfo | None]

zabgrab.cli.reading.check_readable(file, verb)[source]

Refuse delimited files, which commands reading merged data can’t read.

Parameters:
  • file (Path) – The file.

  • verb ((str, str)) – What the command does, and its past participle, for the message.

Raises:

ZabgrabError – If file is a delimited file.

Return type:

None

zabgrab.cli.reading.time_range(app, from_, to)[source]

Parse --from and --to, in the configured time zone.

Parameters:
  • app (AppContext) – For the config (the time zone) and the clock.

  • from (str or None) – The options’ values, if given.

  • to (str or None) – The options’ values, if given.

  • from_ (str | None)

Returns:

  • start, end (datetime or None) – The times, if given.

  • tz (tzinfo or None) – The configured time zone (None for local time).

Raises:

click.BadParameter – If a time can’t be parsed.

Return type:

tuple[datetime | None, datetime | None, tzinfo | None]

zabgrab.cli.reading.nothing_selected(file)[source]

Suggest how to find what to select in a file, when nothing was.

Parameters:

file (Path) – The file.

Returns:

str – The hint.

Return type:

str