CCSDS_study project

This commit is contained in:
2026-05-05 21:54:35 +08:00
commit 9be41f9270
585 changed files with 91275 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
"""0.fix import problem"""
import sys
from pathlib import Path
# 获取项目根目录(自动适配 Windows/Linux/Mac
sys.path.append(str(Path(__file__).parent.parent))
"""1.import libs"""
import numpy as np
import matplotlib
matplotlib.use('Agg')
# Agg 是非交互式后端,不需要 display图片可通过 plt.savefig() 保存为文件。现在可以恢复 matplotlib import 并正常调试了。
import matplotlib.pyplot as plt
# uv pip install construct
from construct import *
# uv pip install scipy
import scipy.signal
import Tianwen.ccsds as ccsds
import Tianwen.tianwen1_tm as tianwen1_tm
import struct
import collections
"""2.define some functions"""
def get_packet(p):
return p[0] if type(p) is tuple else p
def packets_asarray(packets):
return np.array([np.frombuffer(get_packet(p)[ccsds.SpacePacketPrimaryHeader.sizeof():], 'uint8')
for p in packets])
def plot_apids(apids, sc, vc):
for apid in sorted(apids.keys()):
plt.figure(figsize = (16,16), facecolor = 'w')
ps = packets_asarray(apids[apid])
plt.imshow(ps, aspect = ps.shape[1]/ps.shape[0])
plt.title(f'APID {apid} Spacecraft {sc} Virtual channel {vc}')
def get_timestamps(aos):
return np.array([tianwen1_tm.parse_timestamp_datetime64(a.insert_zone.timestamp) for a in aos])
def get_packet_timestamps(packets):
return np.array([tianwen1_tm.parse_timestamp_datetime64(p[1]) for p in packets])
"""3.set some frame vars"""
frame_size = 220
frames = np.fromfile('/home/zjz/CCSDS_study/Tianwen/tianwen1_frames_20200730.u8', dtype = 'uint8')
frames = frames[:frames.size//frame_size*frame_size].reshape((-1, frame_size))
print("frames.shape[0]: ", frames.shape[0])
print("\n")
"""4.AOS header"""
aos = [ccsds.AOSFrame.parse(f) for f in frames]
collections.Counter([a.primary_header.transfer_frame_version_number for a in aos])
collections.Counter([a.primary_header.spacecraft_id for a in aos])
collections.Counter([a.primary_header.virtual_channel_id for a in aos
if a.primary_header.spacecraft_id == 245])
collections.Counter([a.primary_header.virtual_channel_id for a in aos
if a.primary_header.spacecraft_id == 82])
print([(a.primary_header.spacecraft_id, a.primary_header.virtual_channel_id) for a in aos[:20]])
"""5.Spacecraft 82 Virtual channel 1"""
print([a.primary_header for a in aos if a.primary_header.spacecraft_id == 82][:10])
"""for test"""
# def main():
# frame_size = 220
# frames = np.fromfile('/home/zjz/CCSDS_study/Tianwen/tianwen1_frames_20200730.u8', dtype = 'uint8')
# frames = frames[:frames.size//frame_size*frame_size].reshape((-1, frame_size))
# print("frames.shape[0]: ", frames.shape[0])
# print("\n")
# if __name__ == "__main__":
# print("hello world!")
# main()