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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/src/lgdo/_version.py

#uv
uv.lock

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ repos:
rev: "v2.4.1"
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.10.0.1"
Expand Down
9 changes: 5 additions & 4 deletions src/lgdo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from __future__ import annotations

from ._version import version as __version__
from .lh5_store import LH5Iterator, LH5Store, load_dfs, load_nda, ls, show
from .lh5 import LH5Iterator, ls, read, read_as, read_n_rows, show, write
from .types import (
LGDO,
Array,
Expand All @@ -69,16 +69,17 @@
"FixedSizeArray",
"Histogram",
"LH5Iterator",
"LH5Store",
"Scalar",
"Struct",
"Table",
"VectorOfEncodedVectors",
"VectorOfVectors",
"WaveformTable",
"__version__",
"load_dfs",
"load_nda",
"ls",
"read",
"read_as",
"read_n_rows",
"show",
"write",
]
4 changes: 1 addition & 3 deletions src/lgdo/lh5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
from .core import read, read_as, write
from .iterator import LH5Iterator
from .store import LH5Store
from .tools import load_dfs, load_nda, ls, show
from .tools import ls, show
from .utils import read_n_rows

__all__ = [
"DEFAULT_HDF5_SETTINGS",
"LH5Iterator",
"LH5Store",
"concat",
"load_dfs",
"load_nda",
"ls",
"read",
"read_as",
Expand Down
111 changes: 0 additions & 111 deletions src/lgdo/lh5/tools.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from __future__ import annotations

import fnmatch
import glob
import logging
import os
from copy import copy
from warnings import warn

import h5py
import numpy as np
import pandas as pd
from numpy.typing import NDArray

from . import utils
from .store import LH5Store
Expand Down Expand Up @@ -223,108 +217,3 @@ def show(
break

key = k_new


def load_nda(
f_list: str | list[str],
par_list: list[str],
lh5_group: str = "",
idx_list: list[NDArray | list | tuple] | None = None,
) -> dict[str, NDArray]:
r"""Build a dictionary of :class:`numpy.ndarray`\ s from LH5 data.

Given a list of files, a list of LH5 table parameters, and an optional
group path, return a NumPy array with all values for each parameter.

Parameters
----------
f_list
A list of files. Can contain wildcards.
par_list
A list of parameters to read from each file.
lh5_group
group path within which to find the specified parameters.
idx_list
for fancy-indexed reads. Must be one index array for each file in
`f_list`.

Returns
-------
par_data
A dictionary of the parameter data keyed by the elements of `par_list`.
Each entry contains the data for the specified parameter concatenated
over all files in `f_list`.
"""
warn(
"load_nda() is deprecated. "
"Please replace it with LH5Store.read(...).view_as('np'), "
"or just read_as(..., 'np'). "
"load_nda() will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)

if isinstance(f_list, str):
f_list = [f_list]
if idx_list is not None:
idx_list = [idx_list]
if idx_list is not None and len(f_list) != len(idx_list):
msg = f"f_list length ({len(f_list)}) != idx_list length ({len(idx_list)})!"
raise ValueError(msg)

# Expand wildcards
f_list = [f for f_wc in f_list for f in sorted(glob.glob(os.path.expandvars(f_wc)))]

sto = LH5Store()
par_data = {par: [] for par in par_list}
for ii, ff in enumerate(f_list):
f = sto.gimme_file(ff, "r")
for par in par_list:
if f"{lh5_group}/{par}" not in f:
msg = f"'{lh5_group}/{par}' not in file {ff}"
raise RuntimeError(msg)

if idx_list is None:
data, _ = sto.read(f"{lh5_group}/{par}", f)
else:
data, _ = sto.read(f"{lh5_group}/{par}", f, idx=idx_list[ii])
if not data:
continue
par_data[par].append(data.nda)
return {par: np.concatenate(par_data[par]) for par in par_list}


def load_dfs(
f_list: str | list[str],
par_list: list[str],
lh5_group: str = "",
idx_list: list[NDArray | list | tuple] | None = None,
) -> pd.DataFrame:
"""Build a :class:`pandas.DataFrame` from LH5 data.

Given a list of files (can use wildcards), a list of LH5 columns, and
optionally the group path, return a :class:`pandas.DataFrame` with all
values for each parameter.

See Also
--------
:func:`load_nda`

Returns
-------
dataframe
contains columns for each parameter in `par_list`, and rows containing
all data for the associated parameters concatenated over all files in
`f_list`.
"""
warn(
"load_dfs() is deprecated. "
"Please replace it with LH5Store.read(...).view_as('pd'), "
"or just read_as(..., 'pd'). "
"load_dfs() will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
return pd.DataFrame(
load_nda(f_list, par_list, lh5_group=lh5_group, idx_list=idx_list)
)
Loading