-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_hourly_ncwf.py
More file actions
74 lines (58 loc) · 2.3 KB
/
generate_hourly_ncwf.py
File metadata and controls
74 lines (58 loc) · 2.3 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import os
from dateutil import parser
import datetime
# 从gridded_storm.npz生成小时级NCWF文件
print("=== 生成小时级NCWF文件 ===")
# 加载主要的NCWF数据
gridded_storm_path = 'data_sampled/NCWF/gridded_storm.npz'
if not os.path.exists(gridded_storm_path):
print(f"错误:文件不存在 {gridded_storm_path}")
exit(1)
print(f"加载文件: {gridded_storm_path}")
gridded_storm = np.load(gridded_storm_path)
ncwf_arr = gridded_storm['ncwf_arr'] # (743, 13, 138934)
start_time = gridded_storm['start_time'] # (743, 4)
unique_alt = gridded_storm['unique_alt'] # (13,)
smallgrid = gridded_storm['smallgrid'] # (138934, 2)
print(f"NCWF数组形状: {ncwf_arr.shape}")
print(f"时间数组形状: {start_time.shape}")
print(f"总共有 {len(start_time)} 个时间点")
# 创建输出目录
output_dir = 'data_sampled/NCWF'
os.makedirs(output_dir, exist_ok=True)
# 生成前几个小时的文件作为示例
max_files = 10 # 只生成前10个文件作为测试
generated_files = []
for i in range(min(max_files, len(start_time))):
time_info = start_time[i]
year, month, day, hour = time_info
# 生成文件名
fname = f'{year}_{month:02d}_{day:02d}_{hour:02d}00Z.npz'
output_path = os.path.join(output_dir, fname)
# 提取该时间点的NCWF数据
ncwf_data = ncwf_arr[i] # 形状: (13, 138934)
# 保存为单独的文件
np.savez_compressed(output_path,
ncwf_arr=ncwf_data,
unique_alt=unique_alt,
smallgrid=smallgrid,
time_info=time_info)
generated_files.append(fname)
print(f"生成文件: {fname}")
print(f"\n成功生成 {len(generated_files)} 个NCWF文件:")
for fname in generated_files:
print(f" {fname}")
# 验证生成的文件
test_file = os.path.join(output_dir, generated_files[1]) # 测试第二个文件
if os.path.exists(test_file):
print(f"\n验证文件: {generated_files[1]}")
test_data = np.load(test_file)
print(f"文件中的键: {list(test_data.keys())}")
print(f"ncwf_arr形状: {test_data['ncwf_arr'].shape}")
print(f"时间信息: {test_data['time_info']}")
else:
print(f"错误:无法找到测试文件 {test_file}")
print("\n完成!")