Commit f61de360 authored by qiongying's avatar qiongying
Browse files

tst

parent 1d681ec8
Loading
Loading
Loading
Loading
+1.65 KiB (2.44 KiB)

File changed.

No diff preview for this file type.

+64 −8
Original line number Diff line number Diff line
import jinja2
# import jinja2
#this is test message 0523

def test():
    try:
import numpy as np
import matplotlib.pyplot as plt
import ephem

        template = jinja2.Template("Hello {{ name }}!")
        assert template.render(name="World") == "Hello World!"
        print("✅ Jinja2 模板渲染测试通过")
    except Exception as e:
        print("❌ Jinja2 测试失败:", e)

# def test():
#     try:
      
#         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")

# try:
#     import jsonschema
+25 −23
Original line number Diff line number Diff line
import os
import shutil
#from codesp import test
from codesp import simulate_star_trajectory



@@ -8,28 +8,30 @@ import shutil

def main():
    # test()
    # 定义初始路径和目标路径
    source_dir = '/workspace/input/'
    target_dir = '/workspace/output/'

    # 确保源路径存在
    if not os.path.exists(source_dir):
        print(f"错误:源路径 {source_dir} 不存在。")
    else:
        # 创建目标路径(如果不存在)
        os.makedirs(target_dir, exist_ok=True)

        # 获取源路径下的所有文件(不递归子目录)
        for file_name in os.listdir(source_dir):
            source_file = os.path.join(source_dir, file_name)
            target_file = os.path.join(target_dir, file_name)

            # 只拷贝文件,忽略子目录
            if os.path.isfile(source_file):
                shutil.copy2(source_file, target_file)  # copy2 保留元数据(如修改时间)
                print(f"已拷贝: {source_file} -> {target_file}")

        print("拷贝完成。")
    simulate_star_trajectory(semi_major_axis=1.0, eccentricity=0.1, period=365.25, start_date='2023/1/1', end_date='2024/1/1', step_days=10)

    # # 定义初始路径和目标路径
    # source_dir = '/workspace/input/'
    # target_dir = '/workspace/output/'

    # # 确保源路径存在
    # if not os.path.exists(source_dir):
    #     print(f"错误:源路径 {source_dir} 不存在。")
    # else:
    #     # 创建目标路径(如果不存在)
    #     os.makedirs(target_dir, exist_ok=True)

    #     # 获取源路径下的所有文件(不递归子目录)
    #     for file_name in os.listdir(source_dir):
    #         source_file = os.path.join(source_dir, file_name)
    #         target_file = os.path.join(target_dir, file_name)

    #         # 只拷贝文件,忽略子目录
    #         if os.path.isfile(source_file):
    #             shutil.copy2(source_file, target_file)  # copy2 保留元数据(如修改时间)
    #             print(f"已拷贝: {source_file} -> {target_file}")

    #     print("拷贝完成。")

if __name__ == '__main__':
    main()

star_trajectory.png

0 → 100644
+31.1 KiB
Loading image diff...