Skip to content

Commit

Permalink
find and find_one available at h5tbx.__init__
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Oct 24, 2023
1 parent bed9c4b commit 616a36f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
13 changes: 11 additions & 2 deletions h5rdmtoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""h5rdtoolbox repository"""
import atexit
import pathlib
import shutil
from typing import Union, Callable

# noinspection PyUnresolvedReferences
import pint_xarray
import shutil
import xarray as xr
from typing import Union, Callable

from h5rdmtoolbox._cfg import set_config, get_config, get_ureg

Expand Down Expand Up @@ -67,6 +68,14 @@ def __new__(cls, path, rec=False, **kwargs):
return database.File(path, **kwargs)


def find(hdf_filename, *args, **kwargs):
return FileDB(hdf_filename).find(*args, **kwargs)


def find_one(hdf_filename, *args, **kwargs):
return FileDB(hdf_filename).find_one(*args, **kwargs)


def dump(src: Union[str, File, pathlib.Path]) -> None:
"""Call h5.dump() on the provided HDF5 file
Expand Down
24 changes: 0 additions & 24 deletions h5rdmtoolbox/conventions/_my_valiator.py

This file was deleted.

15 changes: 14 additions & 1 deletion tests/database/test_filequery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import unittest

import numpy as np

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox.wrapper.core import File

Expand Down Expand Up @@ -260,6 +261,18 @@ def test_compare_to_dataset_values_2(self):
res = h5.find({'$eq': [1.2, 3.4, 4.0]}, rec=False)
self.assertEqual(0, len(res))

def test_find_init_function(self):
with h5tbx.File() as h5:
h5.create_dataset('u', data=[1.2, 3.4, 4.5], attrs=dict(units='m/s', standard_name='x_velocity'))
h5.create_dataset('v', data=[4.0, 13.5, -3.4], attrs=dict(units='m/s', standard_name='y_velocity'))
res = h5tbx.find_one(h5.hdf_filename, {'$eq': [1.2, 3.4, 4.5]}, rec=False)
self.assertEqual(res.basename, 'u')
res = sorted(h5tbx.find(h5.hdf_filename, {}))
self.assertEqual(len(res), 3)
self.assertEqual(res[0].basename, '')
self.assertEqual(res[1].basename, 'u')
self.assertEqual(res[2].basename, 'v')

def test_compare_to_dataset_values_mean(self):
with h5tbx.use('h5tbx'):
with h5tbx.File() as h5:
Expand Down

0 comments on commit 616a36f

Please sign in to comment.