-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_package.py
More file actions
173 lines (145 loc) Β· 6.44 KB
/
verify_package.py
File metadata and controls
173 lines (145 loc) Β· 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
"""
SOPRA Python Standalone - Package Verification Script
This script verifies that the SOPRA Python standalone package is complete
and ready to use. Run this script to check package integrity before using
the main demonstration notebook.
"""
import os
import sys
from pathlib import Path
def check_package_integrity():
"""
Verify that all required files are present and accessible.
"""
print("π SOPRA PYTHON PACKAGE VERIFICATION")
print("=" * 40)
# Required files and directories
required_items = [
('grapholita_fun_utils.py', 'file', 'Core SOPRA model functions'),
('sopra_meteo_utils.py', 'file', 'Meteorological utilities'),
('stations.txt', 'file', 'Station configuration'),
('README.md', 'file', 'Documentation'),
('SOPRA_Demo.ipynb', 'file', 'Demo notebook'),
('sopra_in/', 'dir', 'Meteorological input data directory'),
('output_run_Pascal/', 'dir', 'Pascal reference data directory'),
('output_run_Pascal/gfu_all_years.csv', 'file', 'Pascal validation data')
]
missing_items = []
present_items = []
for item, item_type, description in required_items:
if os.path.exists(item):
present_items.append((item, description))
if item_type == 'dir':
file_count = len([f for f in os.listdir(item) if os.path.isfile(os.path.join(item, f))])
print(f" β
{item:<25} - {description} ({file_count} files)")
else:
file_size = os.path.getsize(item)
size_str = f"{file_size:,} bytes" if file_size < 1024*1024 else f"{file_size/(1024*1024):.1f} MB"
print(f" β
{item:<25} - {description} ({size_str})")
else:
missing_items.append((item, description))
print(f" β {item:<25} - {description} (MISSING)")
print(f"\nπ VERIFICATION SUMMARY")
print("-" * 25)
print(f"β
Present: {len(present_items)}/{len(required_items)}")
print(f"β Missing: {len(missing_items)}")
if missing_items:
print(f"\nβ οΈ MISSING ITEMS:")
for item, description in missing_items:
print(f" β’ {item} - {description}")
return False
# Check meteorological data files
print(f"\nπ METEOROLOGICAL DATA VERIFICATION")
print("-" * 35)
sopra_in_dir = Path("sopra_in")
if sopra_in_dir.exists():
std_files = list(sopra_in_dir.glob("*.std"))
if std_files:
print(f"π Found {len(std_files)} .std files:")
station_count = 0
total_records = 0
for std_file in sorted(std_files):
try:
with open(std_file, 'r') as f:
lines = f.readlines()
record_count = len(lines)
total_records += record_count
# Extract station info
filename = std_file.stem
if filename.startswith('met') and filename.endswith('24'):
station_code = filename[3:-2].upper()
print(f" π {station_code}: {record_count:,} records")
station_count += 1
else:
print(f" π {filename}: {record_count:,} records")
except Exception as e:
print(f" β {std_file.name}: Error reading file - {e}")
print(f"\nπ Total: {station_count} stations, {total_records:,} meteorological records")
else:
print("β No .std files found in sopra_in directory")
return False
# Test imports
print(f"\nπ§ͺ IMPORT VERIFICATION")
print("-" * 20)
try:
import grapholita_fun_utils as gfu
func_count = len([f for f in dir(gfu) if not f.startswith('_')])
print(f" β
grapholita_fun_utils: {func_count} functions available")
except ImportError as e:
print(f" β grapholita_fun_utils: Import failed - {e}")
return False
except Exception as e:
print(f" β grapholita_fun_utils: Error - {e}")
return False
try:
import sopra_meteo_utils as smu
print(f" β
sopra_meteo_utils: Module loaded successfully")
except ImportError as e:
print(f" β sopra_meteo_utils: Import failed - {e}")
return False
except Exception as e:
print(f" β sopra_meteo_utils: Error - {e}")
return False
# Test basic functionality
print(f"\nπ§ FUNCTIONALITY TEST")
print("-" * 20)
try:
# Test basic SOPRA functions
constants = gfu.assign_const_and_var_gfune()
values = gfu.init_value_gfune()
print(f" β
Model initialization: {len(constants)} constants, {len(values)} initial values")
# Test with dummy data
result = gfu.update_gfune(
values=values,
day=1, hour=0, temp_air=10.0, solar_rad=100.0, temp_soil=8.0,
curr_param=None, constants=constants
)
if 'updated_values' in result and 'current_param' in result:
print(f" β
Model simulation: Single step executed successfully")
else:
print(f" β Model simulation: Unexpected output format")
return False
except Exception as e:
print(f" β Model simulation: Error - {e}")
return False
# Final verdict
print(f"\nπ PACKAGE VERIFICATION COMPLETE")
print("=" * 35)
print(f"β
Package is complete and functional!")
print(f"π Ready to run SOPRA_Demo.ipynb")
print(f"π See README.md for detailed usage instructions")
return True
if __name__ == "__main__":
print(__doc__)
success = check_package_integrity()
if success:
print(f"\nπ‘ Next steps:")
print(f" 1. Open SOPRA_Demo.ipynb in Jupyter")
print(f" 2. Run all cells for complete demonstration")
print(f" 3. Explore the validation results")
sys.exit(0)
else:
print(f"\nβ Package verification failed")
print(f" Please check missing files and try again")
sys.exit(1)