Skip to content

Commit 009f2eb

Browse files
committed
add json generation constellation
1 parent 83fbf83 commit 009f2eb

9 files changed

Lines changed: 218 additions & 1 deletion

File tree

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/StarPerf_Simulator_nolfs.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StarPerf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
def main():
1212
print("Starting StarPerf...")
1313

14+
import src.constellation_generation.by_manual.constellation_information as constellation_information
15+
constellation_information.constellation_information("config/manual_constellation_generation_json_file/Example.json")
1416

1517
print("Starting XML Constellations Testing...")
1618
# test the core module functionality of various XML constellations
@@ -85,5 +87,10 @@ def main():
8587

8688

8789
if __name__ == '__main__':
88-
main()
90+
#main()
91+
92+
import src.constellation_generation.by_manual.constellation_information as constellation_information
93+
94+
constellation_information.constellation_information("config/manual_constellation_generation_json_file/Example.json")
95+
8996

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"Shells": [
3+
{
4+
"timeslots": [
5+
{
6+
"position": [
7+
{
8+
"latitude": 56.5,
9+
"longitude": -20.1,
10+
"altitude": 550
11+
},
12+
{
13+
"latitude": 57.5,
14+
"longitude": -23.1,
15+
"altitude": 545
16+
}
17+
],
18+
"links":[
19+
{
20+
"sat1":0,
21+
"sat2":1
22+
}
23+
]
24+
},
25+
{
26+
"position": [
27+
{
28+
"latitude": 56.5,
29+
"longitude": -20.1,
30+
"altitude": 550
31+
},
32+
{
33+
"latitude": 57.5,
34+
"longitude": -23.1,
35+
"altitude": 545
36+
}
37+
],
38+
"links":[]
39+
},
40+
{
41+
"position": [
42+
{
43+
"latitude": 56.5,
44+
"longitude": -20.1,
45+
"altitude": 550
46+
},
47+
{
48+
"latitude": 57.5,
49+
"longitude": -23.1,
50+
"altitude": 545
51+
}
52+
],
53+
"links":[
54+
{
55+
"sat1":0,
56+
"sat2":1
57+
}
58+
]
59+
}
60+
]
61+
}
62+
]
63+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
3+
Author : yunanhou
4+
5+
Date : 2025/12/11
6+
7+
Function : Generate constellations from JSON files
8+
9+
"""
10+
11+
import os
12+
import json
13+
import h5py
14+
15+
16+
def constellation_information(constellation_json_file):
17+
"""
18+
Read constellation information from a JSON file and generate an .h5 structure.
19+
20+
JSON format example:
21+
{
22+
"Shells": [
23+
{
24+
"timeslots": [
25+
{
26+
"position": [
27+
{ "latitude": 56.5, "longitude": -20.1, "altitude": 550 },
28+
{ "latitude": 57.5, "longitude": -23.1, "altitude": 545 }
29+
],
30+
"links": [
31+
{ "sat1": 0, "sat2": 1 }
32+
]
33+
},
34+
...
35+
]
36+
}
37+
]
38+
}
39+
"""
40+
41+
# 1. read JSON file
42+
with open(constellation_json_file, "r", encoding="utf-8") as f:
43+
data = json.load(f)
44+
45+
46+
shells_data = data["Shells"]
47+
number_of_shells = len(shells_data)
48+
49+
# 2. The constellation name is derived from the JSON filename
50+
constellation_name = os.path.splitext(os.path.basename(constellation_json_file))[0]
51+
52+
# 3. .h5 file path
53+
file_path = os.path.join("data", "Manual_constellation", f"{constellation_name}.h5")
54+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
55+
56+
# If old files exist, delete them.
57+
if os.path.exists(file_path):
58+
os.remove(file_path)
59+
60+
# 4. Create an empty .h5 file and a position/shellX structure.
61+
with h5py.File(file_path, "w") as h5f:
62+
position_group = h5f.create_group("position")
63+
for shell_idx in range(1, number_of_shells + 1):
64+
position_group.create_group(f"shell{shell_idx}")
65+
66+
67+
# 6. Iterate through each shell layer and write the timeslot dataset.
68+
for shell_idx, shell_obj in enumerate(shells_data, start=1):
69+
timeslots = shell_obj.get("timeslots", [])
70+
number_of_timeslots = len(timeslots)
71+
72+
shell_info = {
73+
"shell_id": shell_idx,
74+
"number_of_timeslots": number_of_timeslots,
75+
"number_of_satellites": None,
76+
"timeslots": []
77+
}
78+
79+
for t_idx, ts in enumerate(timeslots, start=1):
80+
positions = ts.get("position", [])
81+
links = ts.get("links", [])
82+
83+
if shell_info["number_of_satellites"] is None:
84+
shell_info["number_of_satellites"] = len(positions)
85+
86+
# Construct a two-dimensional array to be written to the .h5 file: [[lon, lat, alt], ...]
87+
satellite_position = []
88+
for sat in positions:
89+
lat = sat.get("latitude")
90+
lon = sat.get("longitude")
91+
alt = sat.get("altitude")
92+
satellite_position.append([str(lon), str(lat), str(alt)])
93+
94+
# Write the current timeslot dataset to h5
95+
with h5py.File(file_path, "a") as h5f:
96+
position_group = h5f["position"]
97+
current_shell_group = position_group[f"shell{shell_idx}"]
98+
current_shell_group.create_dataset(f"timeslot{t_idx}", data=satellite_position)
99+
100+

0 commit comments

Comments
 (0)