h5rdmtoolbox 2.5.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. h5rdmtoolbox/__init__.py +424 -0
  2. h5rdmtoolbox/_cfg.py +104 -0
  3. h5rdmtoolbox/_repr.py +747 -0
  4. h5rdmtoolbox/_version.py +6 -0
  5. h5rdmtoolbox/cli.py +61 -0
  6. h5rdmtoolbox/consts.py +3 -0
  7. h5rdmtoolbox/convention/__init__.py +41 -0
  8. h5rdmtoolbox/convention/cfg.py +2 -0
  9. h5rdmtoolbox/convention/consts.py +28 -0
  10. h5rdmtoolbox/convention/core.py +817 -0
  11. h5rdmtoolbox/convention/errors.py +34 -0
  12. h5rdmtoolbox/convention/generate.py +385 -0
  13. h5rdmtoolbox/convention/ontology/__init__.py +3 -0
  14. h5rdmtoolbox/convention/ontology/h5ontocls.py +133 -0
  15. h5rdmtoolbox/convention/ontology/hdf_datatypes.py +64 -0
  16. h5rdmtoolbox/convention/references.py +23 -0
  17. h5rdmtoolbox/convention/standard_attributes.py +383 -0
  18. h5rdmtoolbox/convention/toolbox_validators.py +175 -0
  19. h5rdmtoolbox/convention/utils.py +216 -0
  20. h5rdmtoolbox/data/def_icon.png +0 -0
  21. h5rdmtoolbox/data/fluid-v1.yml +36 -0
  22. h5rdmtoolbox/data/h5tbx.yaml +28 -0
  23. h5rdmtoolbox/data/id_icon.png +0 -0
  24. h5rdmtoolbox/data/iri_icon.png +0 -0
  25. h5rdmtoolbox/data/ld_icon.png +0 -0
  26. h5rdmtoolbox/data/piv-v1.yml +35 -0
  27. h5rdmtoolbox/data/style.css +216 -0
  28. h5rdmtoolbox/data/tutorial_convention.yaml +91 -0
  29. h5rdmtoolbox/data/tutorial_standard_name_table.yaml +390 -0
  30. h5rdmtoolbox/data/type_icon.png +0 -0
  31. h5rdmtoolbox/database/__init__.py +75 -0
  32. h5rdmtoolbox/database/hdfdb/__init__.py +4 -0
  33. h5rdmtoolbox/database/hdfdb/filedb.py +129 -0
  34. h5rdmtoolbox/database/hdfdb/objdb.py +520 -0
  35. h5rdmtoolbox/database/hdfdb/query.py +133 -0
  36. h5rdmtoolbox/database/hdfdb/utils.py +51 -0
  37. h5rdmtoolbox/database/interface.py +59 -0
  38. h5rdmtoolbox/database/lazy.py +183 -0
  39. h5rdmtoolbox/database/mongo.py +374 -0
  40. h5rdmtoolbox/errors.py +4 -0
  41. h5rdmtoolbox/extensions/__init__.py +0 -0
  42. h5rdmtoolbox/extensions/magnitude.py +67 -0
  43. h5rdmtoolbox/extensions/normalize.py +103 -0
  44. h5rdmtoolbox/extensions/onto.py +52 -0
  45. h5rdmtoolbox/extensions/units.py +48 -0
  46. h5rdmtoolbox/extensions/vector.py +138 -0
  47. h5rdmtoolbox/gui/__init__.py +0 -0
  48. h5rdmtoolbox/gui/fairify.py +446 -0
  49. h5rdmtoolbox/gui/src/__init__.py +0 -0
  50. h5rdmtoolbox/gui/src/main.py +131 -0
  51. h5rdmtoolbox/identifiers.py +257 -0
  52. h5rdmtoolbox/layout/__init__.py +4 -0
  53. h5rdmtoolbox/layout/core.py +624 -0
  54. h5rdmtoolbox/ld/__init__.py +129 -0
  55. h5rdmtoolbox/ld/globals.py +3 -0
  56. h5rdmtoolbox/ld/hdf/__init__.py +0 -0
  57. h5rdmtoolbox/ld/hdf/attributes.py +36 -0
  58. h5rdmtoolbox/ld/hdf/datasets.py +160 -0
  59. h5rdmtoolbox/ld/hdf/file.py +54 -0
  60. h5rdmtoolbox/ld/hdf/groups.py +47 -0
  61. h5rdmtoolbox/ld/rdf.py +883 -0
  62. h5rdmtoolbox/ld/shacl.py +221 -0
  63. h5rdmtoolbox/ld/user/__init__.py +0 -0
  64. h5rdmtoolbox/ld/user/attributes.py +241 -0
  65. h5rdmtoolbox/ld/user/datasets.py +22 -0
  66. h5rdmtoolbox/ld/user/file.py +58 -0
  67. h5rdmtoolbox/ld/user/groups.py +58 -0
  68. h5rdmtoolbox/ld/user/utils.py +8 -0
  69. h5rdmtoolbox/ld/utils.py +133 -0
  70. h5rdmtoolbox/plotting.py +168 -0
  71. h5rdmtoolbox/protected_attributes.py +9 -0
  72. h5rdmtoolbox/protocols.py +268 -0
  73. h5rdmtoolbox/repository/__init__.py +11 -0
  74. h5rdmtoolbox/repository/default_metamapper.py +55 -0
  75. h5rdmtoolbox/repository/interface.py +214 -0
  76. h5rdmtoolbox/repository/utils.py +131 -0
  77. h5rdmtoolbox/repository/zenodo/__init__.py +5 -0
  78. h5rdmtoolbox/repository/zenodo/core.py +616 -0
  79. h5rdmtoolbox/repository/zenodo/metadata.py +276 -0
  80. h5rdmtoolbox/repository/zenodo/tokens.py +118 -0
  81. h5rdmtoolbox/repository/zenodo/utils.py +16 -0
  82. h5rdmtoolbox/tutorial.py +374 -0
  83. h5rdmtoolbox/user.py +158 -0
  84. h5rdmtoolbox/utils.py +743 -0
  85. h5rdmtoolbox/wrapper/__init__.py +8 -0
  86. h5rdmtoolbox/wrapper/accessor.py +97 -0
  87. h5rdmtoolbox/wrapper/accessors/__init__.py +0 -0
  88. h5rdmtoolbox/wrapper/accessors/provenance.py +36 -0
  89. h5rdmtoolbox/wrapper/core.py +2528 -0
  90. h5rdmtoolbox/wrapper/ds_decoder.py +113 -0
  91. h5rdmtoolbox/wrapper/h5attr.py +519 -0
  92. h5rdmtoolbox/wrapper/h5ext.py +20 -0
  93. h5rdmtoolbox/wrapper/h5utils.py +32 -0
  94. h5rdmtoolbox/wrapper/h5yaml.py +116 -0
  95. h5rdmtoolbox/wrapper/jsonld.py +1189 -0
  96. h5rdmtoolbox/wrapper/xr2hdf.py +106 -0
  97. h5rdmtoolbox-2.5.3.dist-info/METADATA +379 -0
  98. h5rdmtoolbox-2.5.3.dist-info/RECORD +144 -0
  99. h5rdmtoolbox-2.5.3.dist-info/WHEEL +5 -0
  100. h5rdmtoolbox-2.5.3.dist-info/entry_points.txt +2 -0
  101. h5rdmtoolbox-2.5.3.dist-info/licenses/LICENSE +20 -0
  102. h5rdmtoolbox-2.5.3.dist-info/top_level.txt +2 -0
  103. tests/__init__.py +0 -0
  104. tests/clean_zenodo_sandbox.py +23 -0
  105. tests/conventions/__init__.py +0 -0
  106. tests/conventions/test_convention_vfuncs.py +98 -0
  107. tests/conventions/test_conventions.py +697 -0
  108. tests/conventions/test_engmeta.py +55 -0
  109. tests/conventions/test_references.py +22 -0
  110. tests/conventions/test_toolbox_validators.py +138 -0
  111. tests/conventions/test_utils.py +94 -0
  112. tests/database/__init__.py +0 -0
  113. tests/database/test_find_rdf.py +36 -0
  114. tests/database/test_hdfDB.py +619 -0
  115. tests/database/test_mongo.py +229 -0
  116. tests/layouts/__init__.py +0 -0
  117. tests/layouts/test_core.py +362 -0
  118. tests/layouts/test_docs.py +66 -0
  119. tests/ld/__init__.py +0 -0
  120. tests/ld/test_ld.py +904 -0
  121. tests/ld/test_rdf.py +688 -0
  122. tests/ld/test_shacl.py +223 -0
  123. tests/ld/test_user_graph.py +278 -0
  124. tests/ld/test_utils.py +13 -0
  125. tests/repository/__init__.py +0 -0
  126. tests/repository/test_zenodo.py +728 -0
  127. tests/test_cli.py +69 -0
  128. tests/test_config.py +80 -0
  129. tests/test_extensions.py +148 -0
  130. tests/test_identifiers.py +85 -0
  131. tests/test_plotting.py +155 -0
  132. tests/test_repr.py +114 -0
  133. tests/test_user.py +100 -0
  134. tests/test_utils.py +143 -0
  135. tests/test_version.py +72 -0
  136. tests/test_xarray_export.py +47 -0
  137. tests/wrapper/__init__.py +0 -0
  138. tests/wrapper/test_core.py +994 -0
  139. tests/wrapper/test_dump.py +77 -0
  140. tests/wrapper/test_file.py +411 -0
  141. tests/wrapper/test_h5ext.py +22 -0
  142. tests/wrapper/test_lazy.py +62 -0
  143. tests/wrapper/test_namespaces.py +46 -0
  144. tests/wrapper/test_xr2df.py +41 -0
@@ -0,0 +1,6 @@
1
+ try:
2
+ from importlib.metadata import version as _version
3
+ except ImportError as e:
4
+ raise ImportError('Most likely you have python<3.8 installed. At least 3.8 is required.') from e
5
+
6
+ __version__ = _version('h5rdmtoolbox')
h5rdmtoolbox/cli.py ADDED
@@ -0,0 +1,61 @@
1
+ import pathlib
2
+
3
+ import click
4
+
5
+
6
+ @click.group(invoke_without_command=True)
7
+ @click.option('--fairify', type=str, help='Starts the app helping you to make the file FAIRer')
8
+ def h5tbx(fairify):
9
+ if fairify:
10
+ filename = pathlib.Path(fairify)
11
+ from h5rdmtoolbox.gui.fairify import start
12
+ print(f'Opening GUI to fairify the file {filename}')
13
+ start(filename=filename)
14
+ print(f'GUI closed')
15
+
16
+
17
+ @h5tbx.command()
18
+ @click.argument('filename', type=click.Path(exists=True))
19
+ @click.option(
20
+ '-o', '--output',
21
+ type=click.Path(exists=False),
22
+ help='Filename to write the JSON-LD data to.'
23
+ )
24
+ @click.option("--format", type=str, help="The output format, e.g. jsonld.",
25
+ default="ttl")
26
+ @click.option("--graph", is_flag=True,
27
+ help="Generates a graph and stores it in OUTPUT-graph.html. Uses pyvis and kglab. "
28
+ "Please Make sure it is installed")
29
+ def ld(filename, output, format, graph):
30
+ """Linked-Data command"""
31
+
32
+ content = None
33
+
34
+ def _serialize(filename):
35
+ from h5rdmtoolbox import serialize
36
+ return serialize(filename, fmt=format, indent=2)
37
+
38
+ if output:
39
+ output = pathlib.Path(output)
40
+ if not format:
41
+ format = output.suffix[1:]
42
+ if output:
43
+ valid_extension = (".jsonld", ".json-ld", ".ttl", ".turtle")
44
+ if output.suffix not in valid_extension:
45
+ raise ValueError(f"Please use one of the following extensions: {valid_extension}")
46
+ if not content:
47
+ content = _serialize(filename)
48
+ with open(output, "w") as f:
49
+ f.write(content)
50
+ else:
51
+ if not content:
52
+ content = _serialize(filename)
53
+ print(content)
54
+
55
+ if graph:
56
+ from h5rdmtoolbox import build_pyvis_graph
57
+ build_pyvis_graph(filename, output_filename=filename.with_suffix("-graph.html"))
58
+
59
+
60
+ if __name__ == '__main__':
61
+ h5tbx(obj={})
h5rdmtoolbox/consts.py ADDED
@@ -0,0 +1,3 @@
1
+ """constants used by the h5rdmtoolbox package"""
2
+
3
+ ANCILLARY_DATASET = 'ANCILLARY_DATASETS'
@@ -0,0 +1,41 @@
1
+ """"
2
+
3
+ This sub-package provides convention such as standard_names
4
+
5
+ The concept of standard_names is adopted from the climate forecast community (see cfconventions.org)
6
+
7
+ A convention (class `Convention` includes a set of standard attributes, which are defined in a YAML file.
8
+
9
+ Helpful functions:
10
+ - `get_registered_conventions`
11
+ - `get_current_convention`
12
+ """
13
+
14
+ import pathlib
15
+
16
+ from .core import Convention, from_yaml, from_repo, get_current_convention, from_zenodo, get_registered_conventions, \
17
+ yaml2jsonld
18
+ from .standard_attributes import StandardAttribute
19
+ from .toolbox_validators import get_list_of_validators
20
+ from ..user import UserDir
21
+
22
+ __this_dir__ = pathlib.Path(__file__).parent
23
+
24
+ convention_user_dir = UserDir['convention'] / 'h5tbx'
25
+
26
+
27
+ def build_convention():
28
+ """Build the toolbox convention from the yaml file"""
29
+ from . import generate
30
+ h5tbx_convention_yaml = __this_dir__.parent / f'data/h5tbx.yaml'
31
+ convention_user_dir.mkdir(parents=True, exist_ok=True)
32
+ generate.write_convention_module_from_yaml(h5tbx_convention_yaml)
33
+
34
+
35
+ if not (convention_user_dir / f'h5tbx.py').exists():
36
+ build_convention()
37
+
38
+ __all__ = ['Convention', 'from_yaml', 'from_zenodo', 'from_repo',
39
+ 'get_current_convention', 'get_registered_conventions',
40
+ 'from_zenodo', 'StandardAttribute', 'yaml2jsonld',
41
+ 'get_list_of_validators']
@@ -0,0 +1,2 @@
1
+ _current_convention = None
2
+ _registered_conventions = {}
@@ -0,0 +1,28 @@
1
+ import enum
2
+
3
+
4
+ class _SpecialDefaults(enum.Enum):
5
+ NONE = 0
6
+ EMPTY = 1
7
+
8
+
9
+ class DefaultValue:
10
+ """Helper class to distinguish between optional and obligatory standard attributes."""
11
+
12
+ EMPTY = _SpecialDefaults.EMPTY
13
+ NONE = _SpecialDefaults.NONE
14
+
15
+ def __init__(self, value):
16
+ if value.lower() == '$none':
17
+ self.value = _SpecialDefaults.NONE
18
+ elif value.lower() == '$optional':
19
+ self.value = _SpecialDefaults.NONE
20
+ elif value.lower() == '$obligatory':
21
+ self.value = _SpecialDefaults.EMPTY
22
+ elif value == '$empty':
23
+ self.value = _SpecialDefaults.EMPTY
24
+ else:
25
+ self.value = value
26
+
27
+ def __eq__(self, other):
28
+ return self.value == other