integrate_module 0.99.1__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.
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ INTEGRATE HDF5 Info CLI
4
+
5
+ Command-line interface for analyzing HDF5 files used in INTEGRATE.
6
+ Provides fast inspection of DATA, PRIOR, POST, and FORWARD files.
7
+
8
+ Author: Thomas Mejer Hansen
9
+ Email: tmeha@geo.au.dk
10
+ """
11
+
12
+ import argparse
13
+ import sys
14
+ import os
15
+
16
+ # Import the integrate module
17
+ try:
18
+ import integrate as ig
19
+ except ImportError:
20
+ print("Error: Could not import integrate module. Please ensure it is properly installed.")
21
+ sys.exit(1)
22
+
23
+ def main():
24
+ """Entry point for the hdf5_info command."""
25
+
26
+ # Create argument parser
27
+ parser = argparse.ArgumentParser(
28
+ description='Analyze HDF5 files used in the INTEGRATE module',
29
+ formatter_class=argparse.RawDescriptionHelpFormatter,
30
+ epilog="""
31
+ Examples:
32
+ hdf5_info DATA.h5
33
+ hdf5_info --load-data PRIOR.h5
34
+ hdf5_info -q *.h5
35
+ hdf5_info --load-data PRIOR.h5 POST.h5
36
+
37
+ File Types:
38
+ DATA.h5 - Observed data and geometry
39
+ PRIOR.h5 - Prior model realizations and forward data
40
+ POST.h5 - Posterior results and statistics
41
+ FORWARD.h5 - Forward model configuration
42
+
43
+ Performance:
44
+ By default, only metadata is read (fast).
45
+ Use --load-data to include data ranges (slower).
46
+
47
+ For more information, see the INTEGRATE documentation.
48
+ """
49
+ )
50
+
51
+ # Required arguments (unless --version is used)
52
+ parser.add_argument('files',
53
+ nargs='*',
54
+ help='HDF5 file(s) to analyze')
55
+
56
+ # Optional arguments
57
+ parser.add_argument('--load-data', '-d',
58
+ action='store_true',
59
+ help='Load actual data to compute ranges and statistics (slower)')
60
+
61
+ parser.add_argument('--quiet', '-q',
62
+ action='store_true',
63
+ help='Only show summary information (no detailed output)')
64
+
65
+ parser.add_argument('--version', '-v',
66
+ action='store_true',
67
+ help='Show version information')
68
+
69
+ # Parse arguments
70
+ args = parser.parse_args()
71
+
72
+ # Handle version request
73
+ if args.version:
74
+ try:
75
+ from integrate import __version__
76
+ print(f"INTEGRATE version: {__version__}")
77
+ except (ImportError, AttributeError):
78
+ print("INTEGRATE version: unknown")
79
+ return 0
80
+
81
+ # Validate that files are provided
82
+ if not args.files:
83
+ parser.error("the following arguments are required: files")
84
+ return 1
85
+
86
+ # Track success
87
+ all_success = True
88
+
89
+ # Process each file
90
+ for i, file_path in enumerate(args.files):
91
+ # Check if file exists
92
+ if not os.path.exists(file_path):
93
+ print(f"ERROR: File not found: {file_path}")
94
+ all_success = False
95
+ continue
96
+
97
+ # Add separator between multiple files
98
+ if i > 0 and not args.quiet:
99
+ print("\n" + "=" * 80)
100
+ print()
101
+
102
+ try:
103
+ # Analyze the file
104
+ info = ig.hdf5_info(file_path, verbose=not args.quiet, load_data=args.load_data)
105
+
106
+ # Print summary if in quiet mode
107
+ if args.quiet and info:
108
+ print(f"{os.path.basename(file_path):50s} | "
109
+ f"Type: {info['file_type']:8s} | "
110
+ f"Datasets: {len(info['datasets']):3d} | "
111
+ f"Size: {os.path.getsize(file_path)/(1024**2):6.2f} MB")
112
+
113
+ except Exception as e:
114
+ print(f"ERROR analyzing file {file_path}: {str(e)}")
115
+ all_success = False
116
+ continue
117
+
118
+ # Return appropriate exit code
119
+ return 0 if all_success else 1
120
+
121
+ if __name__ == "__main__":
122
+ sys.exit(main())