codesp.py 3.33 KB
Newer Older
qiongying's avatar
tst    
qiongying committed
1
# import jinja2
Zheng Gaoshan's avatar
Zheng Gaoshan committed
2
#this is test message 0523
qiongying.jia's avatar
test    
qiongying.jia committed
3

qiongying's avatar
tst    
qiongying committed
4
5
6
7
8
9
10
import numpy as np
import matplotlib.pyplot as plt
import ephem


# def test():
#     try:
qiongying.jia's avatar
qiongying.jia committed
11
      
qiongying's avatar
tst    
qiongying committed
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
#         template = jinja2.Template("Hello {{ name }}!")
#         assert template.render(name="World") == "Hello World!"
#         print("✅ Jinja2 模板渲染测试通过")
#     except Exception as e:
#         print("❌ Jinja2 测试失败:", e)




def simulate_star_trajectory(semi_major_axis, eccentricity, period, start_date, end_date, step_days):
    # Initialize observer location (e.g., Earth location)
    observer = ephem.Observer()
    observer.lat, observer.lon = '0', '0'

    # Create a body using orbital elements
    star = ephem.EllipticalBody()
    star._a = semi_major_axis         # Semi-major axis in AU
    star._e = eccentricity            # Eccentricity of the orbit
    star._Om = 0.0                    # Longitude of ascending node
    star._om = 0.0                    # Argument of perihelion
    star._inc = 0.0                   # Inclination to the ecliptic
    star._M = 0.0                     # Mean anomaly
    star._epoch = ephem.Date(start_date)  # Epoch of perihelion

    # Date range
    date_range = np.arange(ephem.Date(start_date), ephem.Date(end_date), step_days)

    # Store positions
    positions = []

    for date in date_range:
        observer.date = date
        star.compute(observer)
        #将天体坐标转换为黄道坐标
        ecliptic_coords = ephem.Ecliptic(star)

        # 获取黄道坐标
        x, y = ecliptic_coords.lon, ecliptic_coords.lat # lon 对应黄道经度,lat 对应黄道纬度
        # x, y = ephem.Ecliptic(star).suun()
        positions.append((x, y))

    # Extract x and y coordinates
    x_coords, y_coords = zip(*positions)

    # Visualization
    plt.plot(x_coords, y_coords, label='Star trajectory')
    plt.scatter(x_coords[0], y_coords[0], color='red', label='Start')
    plt.scatter(x_coords[-1], y_coords[-1], color='green', label='End')
    plt.xlabel('X (AU)')
    plt.ylabel('Y (AU)')
    plt.title('Simulated Star Trajectory')
    plt.legend()
    plt.grid()
    plt.show()
    plt.savefig("star_trajectory.png")
    print("图像已保存为 star_trajectory.png")
qiongying.jia's avatar
qiongying.jia committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

# try:
#     import jsonschema
#     from jsonschema import validate
#     schema = {"type": "object", "required": ["name"], "properties": {"name": {"type": "string"}}}
#     instance = {"name": "test"}
#     validate(instance=instance, schema=schema)
#     print("✅ jsonschema 验证测试通过")
# except Exception as e:
#     print("❌ jsonschema 测试失败:", e)

# try:
#     import numpy
#     a = numpy.array([1, 2, 3])
#     assert len(a) == 3
#     print("✅ Numpy 数组测试通过")
# except Exception as e:
#     print("❌ Numpy 测试失败:", e)

# try:
#     import pandas
#     df = pandas.DataFrame({"col": [1, 2, 3]})
#     assert len(df) == 3
#     print("✅ Pandas DataFrame 测试通过")
# except Exception as e:
#     print("❌ Pandas 测试失败:", e)

# try:
#     import loguru
#     from loguru import logger
#     logger.add("test.log")
#     logger.info("Test log message")
#     with open("test.log", "r") as f:
#         content = f.read()
#         assert "Test log message" in content
#     print("✅ Loguru 日志测试通过")
# except Exception as e:
#     print("❌ Loguru 测试失败:", e)

# print("\n🎉 所有测试完成")