我对 python 很陌生,对 pandas、numpy 更陌生。我正在尝试格式化 GPS RINEX 文件,以便将文件拆分为卫星(总共 32 个)。然后每个文件(即卫星)应按纪元(30 秒间隔)格式化,然后每个信号的数据(总共 7 个)显示在相应的列中。例如:
SV1
2014-11-07 00:00:00 L1 L2 P1 P2 C1 S1 S2
2014-11-07 00:00:30 L1 L2 P1 P2 C1 S1 S2
2014-11-07 00:00:30 L1 L2 P1 P2 C1 S1 S2
我正在处理的代码,特别是函数是:
def read_data_chunk(self, RINEXfile, CHUNK_SIZE = 10000):
obss = np.empty((CHUNK_SIZE, TOTAL_SATS, len(self.obs_types)), dtype=np.float64) * np.NaN
llis = np.zeros((CHUNK_SIZE, TOTAL_SATS, len(self.obs_types)), dtype=np.uint8)
signal_strengths = np.zeros((CHUNK_SIZE, TOTAL_SATS, len(self.obs_types)), dtype=np.uint8)
epochs = np.zeros(CHUNK_SIZE, dtype='datetime64[us]')
flags = np.zeros(CHUNK_SIZE, dtype=np.uint8)
i = 0
while True:
hdr = self.read_epoch_header(RINEXfile)
#print hdr
if hdr is None:
break
epoch, flags[i], sats = hdr
epochs[i] = np.datetime64(epoch)
sat_map = np.ones(len(sats)) * -1
for n, sat in enumerate(sats):
if sat[0] == 'G':
sat_map[n] = int(sat[1:]) - 1
obss[i], llis[i], signal_strengths[i] = self.read_obs(RINEXfile, len(sats), sat_map)
i += 1
if i >= CHUNK_SIZE:
break
print "obss.ndim: {0}".format(obss.ndim)
print "obss.shape: {0}" .format(obss.shape)
print "obss.size: {0}".format(obss.size)
print "obss.dtype: {0}".format(obss.dtype)
print "obss.itemsize: {0}".format(obss.itemsize)
print "obss: {0}".format(obss)
y = np.split(obss, 32, 1)
print "y.ndim: {0}".format(y[3].ndim)
print "y.shape: {0}" .format(y[3].shape)
print "y.size: {0}".format(y[3].size)
print "y_0: {0}".format(y[3])
return obss[:i], llis[:i], signal_strengths[:i], epochs[:i], flags[:i]
打印语句只是为了了解所涉及的维度,其结果:
obss.ndim: 3
obss.shape: (10000L, 32L, 7L)
obss.size: 2240000
obss.dtype: float64
obss.itemsize: 8
y.ndim: 3
y.shape: (10000L, 1L, 7L)
y.size: 70000
我遇到的确切问题是如何精确操作,以便将阵列分成后续的 32 个部分(即卫星)。以下是到目前为止的输出示例:
sats = np.rollaxis(obss, 1, 0)
sat = sats[5] #sv6
sat.shape: (10000L, 7L)
sat.ndim: 2
sat.size: 70000
sat.dtype: float64
sat.item
size: 8
sat: [[ -7.28308440e+06 -5.66279406e+06 2.38582902e+07 ..., 2.38582906e+07 4.70000000e+01 4.20000000e+01] [ -7.32362993e+06 -5.69438797e+06 2.38505736e+07 ..., 2.38505742e+07 4.70000000e+01 4.20000000e+01] [ -7.36367675e+06 -5.72559325e+06 2.38429526e+07 ..., 2.38429528e+07 4.60000000e+01 4.20000000e+01]
上面的输出是第 6 颗卫星(“sat”)的输出,显示了前 3 个时期的信号。我尝试使用以下代码分别打开新文件,但生成的文本文件仅显示以下输出:
Mã số:
for i in range(32):
sat = obss[:, i]
open(((("sv{0}").format(sat)),'w').writelines(sat))
在文本文件中输出:
ø ø ø ø ø ø ø
很明显,我忽略了对数组的操作有问题。 read_data_chunk
函数从 read_data
函数调用:
def read_data(self, RINEXfile):
obs_data_chunks = []
while True:
obss, _, _, epochs, _ = self.read_data_chunk(RINEXfile)
if obss.shape[0] == 0:
break
obs_data_chunks.append(pd.Panel( np.rollaxis(obss, 1, 0), items=['G%02d' % d for d in range(1, 33)], major_axis=epochs,minor_axis=self.obs_types).dropna(axis=0, how='all').dropna(axis=2, how='all'))
print "obs_data_chunks: {0}".format(obs_data_chunks)
self.data = pd.concat(obs_data_chunks, axis=1)
我尝试的下一步是在上面的代码中,因为我认为这个数组可能是要被操作的正确数组。最终打印语句:
obs_data_chunks: [
Dimensions: 32 (items) x 2880 (major_axis) x 7 (minor_axis)
Items axis: G01 to G32
Major_axis axis: 2014-04-27 00:00:00 to 2014-04-27 23:59:30
Minor_axis axis: L1 to S2]
我试图弄清楚如何使用以下方法处理 obs_data_chunks
Mảng:
odc = np.rollaxis(obs_data_chunks, 1)
odc_temp = odc[5]
但收到错误:AttributeError: 'list' object has no attribute 'ndim'
Tôi là một lập trình viên xuất sắc, rất giỏi!