shancx 1.9.33.172__py3-none-any.whl → 1.9.33.174__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.
- shancx/H9/__init__.py +126 -0
- shancx/H9/ahi_read_hsd.py +877 -0
- shancx/H9/ahisearchtable.py +298 -0
- shancx/H9/geometry.py +2439 -0
- shancx/NN/__init__.py +21 -0
- {shancx-1.9.33.172.dist-info → shancx-1.9.33.174.dist-info}/METADATA +1 -1
- {shancx-1.9.33.172.dist-info → shancx-1.9.33.174.dist-info}/RECORD +9 -5
- {shancx-1.9.33.172.dist-info → shancx-1.9.33.174.dist-info}/WHEEL +0 -0
- {shancx-1.9.33.172.dist-info → shancx-1.9.33.174.dist-info}/top_level.txt +0 -0
shancx/H9/__init__.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from shancx.H9.ahisearchtable import ahisearchtable
|
|
2
|
+
from shancx.H9.ahi_read_hsd import ahi_read_hsd
|
|
3
|
+
from tqdm import tqdm
|
|
4
|
+
import os
|
|
5
|
+
import numpy as np
|
|
6
|
+
import datetime
|
|
7
|
+
import time
|
|
8
|
+
import warnings
|
|
9
|
+
warnings.filterwarnings("ignore", category=UserWarning)
|
|
10
|
+
class AHIScene(ahi_read_hsd, ahisearchtable) :
|
|
11
|
+
def __init__(self, subpoint=140.7, resolution=0.02):
|
|
12
|
+
super().__init__(subpoint=subpoint, resolution=resolution)
|
|
13
|
+
self.Tempfile = []
|
|
14
|
+
def hsdBlock(self, srcHSDfiles, tmppath, fillvalue=65535) :
|
|
15
|
+
''' 对H8、H9的HSD文件进行解析、拼接成NOM '''
|
|
16
|
+
# HS_H09_20230115_0400_B01_FLDK_R10_S0110.DAT.bz2
|
|
17
|
+
BandID, BlockIDMin, BlockIDMax, SegmentTotal = self.setHSDInfo(srcHSDfiles)
|
|
18
|
+
outdata = None
|
|
19
|
+
BlockIDs = []
|
|
20
|
+
with tqdm(total=len(srcHSDfiles), iterable='iterable',
|
|
21
|
+
desc = '正在进行第%i波段块合成' %(BandID), mininterval=1) as pbar:
|
|
22
|
+
for hsdname in srcHSDfiles :
|
|
23
|
+
if not os.path.isfile(hsdname):
|
|
24
|
+
print('文件不存在【%s】' %(hsdname))
|
|
25
|
+
pbar.update(1)
|
|
26
|
+
continue
|
|
27
|
+
|
|
28
|
+
# 获取文件名信息
|
|
29
|
+
nameinfo = self.getHSDNameInfo(hsdname)
|
|
30
|
+
if nameinfo is None :
|
|
31
|
+
pbar.update(1)
|
|
32
|
+
continue
|
|
33
|
+
SegmentNum = nameinfo['SegmemtID']
|
|
34
|
+
|
|
35
|
+
# print('正在解压bz2文件【%s】' %(hsdname))
|
|
36
|
+
self._unzipped = self.unzip_file(hsdname, tmppath)
|
|
37
|
+
if self._unzipped:
|
|
38
|
+
self.is_zipped = True
|
|
39
|
+
filename = self._unzipped
|
|
40
|
+
|
|
41
|
+
self.Tempfile.append(filename)
|
|
42
|
+
else:
|
|
43
|
+
filename = hsdname
|
|
44
|
+
|
|
45
|
+
if filename.endswith('.bz2') :
|
|
46
|
+
print('解压bz2文件失败【%s】' %(filename))
|
|
47
|
+
pbar.update(1)
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
# 根据块号对数据进行拼接
|
|
51
|
+
data = self.readhsd(filename, SegmentNum)
|
|
52
|
+
if data is None :
|
|
53
|
+
pbar.update(1)
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
if outdata is None :
|
|
57
|
+
line, pixel = data.shape
|
|
58
|
+
outdata = np.full(shape=(line*SegmentTotal, pixel),
|
|
59
|
+
fill_value=fillvalue, dtype=np.uint16)
|
|
60
|
+
|
|
61
|
+
data[np.isnan(data)] = fillvalue/100.0
|
|
62
|
+
outdata[(SegmentNum-BlockIDMin)*line:(SegmentNum-BlockIDMin+1)*line, :] \
|
|
63
|
+
= np.array(data*100.0, dtype=np.uint16)
|
|
64
|
+
BlockIDs.append(SegmentNum)
|
|
65
|
+
pbar.update(1)
|
|
66
|
+
pbar.close()
|
|
67
|
+
self.__del__()
|
|
68
|
+
return outdata
|
|
69
|
+
|
|
70
|
+
def setHSDInfo(self, filelist):
|
|
71
|
+
|
|
72
|
+
BandID = None
|
|
73
|
+
BlockIDs = []
|
|
74
|
+
for filename in filelist :
|
|
75
|
+
nameinfo = self.getHSDNameInfo(filename)
|
|
76
|
+
if nameinfo is None :
|
|
77
|
+
continue
|
|
78
|
+
|
|
79
|
+
if BandID is None :
|
|
80
|
+
BandID = nameinfo['BandID']
|
|
81
|
+
elif BandID != nameinfo['BandID'] :
|
|
82
|
+
raise Exception('输入的文件列表中有多个波段的块数据文件【%s】' %(filename))
|
|
83
|
+
BlockIDs.append(nameinfo['SegmemtID'])
|
|
84
|
+
|
|
85
|
+
BlockIDMin = np.nanmin(BlockIDs)
|
|
86
|
+
BlockIDMax = np.nanmax(BlockIDs)
|
|
87
|
+
|
|
88
|
+
SegmentTotal = int(BlockIDMax-BlockIDMin+1)
|
|
89
|
+
|
|
90
|
+
return BandID, BlockIDMin, BlockIDMax, SegmentTotal
|
|
91
|
+
|
|
92
|
+
def getHSDNameInfo(self, filename):
|
|
93
|
+
|
|
94
|
+
basename = os.path.basename(filename)
|
|
95
|
+
basename = basename.split('.')[0]
|
|
96
|
+
if len(basename) != 39 :
|
|
97
|
+
print('非标准文件名,需要输入文件名【HS_H09_YYYYMMDD_HHMM_BXX_FLDK_R20_S0810】')
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
nameinfo = {}
|
|
101
|
+
namelist = basename.split('_')
|
|
102
|
+
|
|
103
|
+
nameinfo['SatID'] = namelist[1]
|
|
104
|
+
nameinfo['StartTime'] = datetime.datetime.strptime('%s %s' %(namelist[2], namelist[3]), '%Y%m%d %H%M')
|
|
105
|
+
nameinfo['BandID'] = int(namelist[4][1:]) # 2-digit band number (varies from "01" to "16");
|
|
106
|
+
nameinfo['ObsType'] = namelist[5]
|
|
107
|
+
nameinfo['Resolution'] = float(namelist[6][1:])/10.0/100 # spatial resolution ("05": 0.5km, "10": 1.0km, "20": 2.0km);
|
|
108
|
+
nameinfo['SegmemtID'] = int(namelist[7][1:3])
|
|
109
|
+
nameinfo['SegmemtTotal'] = int(namelist[7][3:5]) # total number of segments (fixed to "10")
|
|
110
|
+
|
|
111
|
+
return nameinfo
|
|
112
|
+
|
|
113
|
+
def __del__(self):
|
|
114
|
+
# pass
|
|
115
|
+
for filename in self.Tempfile :
|
|
116
|
+
if os.path.isfile(filename) :
|
|
117
|
+
try:
|
|
118
|
+
os.remove(filename)
|
|
119
|
+
except BaseException as e :
|
|
120
|
+
time.sleep(1)
|
|
121
|
+
try:
|
|
122
|
+
fp = open(filename, 'r')
|
|
123
|
+
fp.close()
|
|
124
|
+
os.remove(filename)
|
|
125
|
+
except BaseException as e :
|
|
126
|
+
pass
|