Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install pnpm 📦
uses: pnpm/action-setup@v4
with:
version: "9"
version: "10"
run_install: false

- name: Install and Build 🔧
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
onlyBuiltDependencies:
- canvas
Empty file added prototype/core/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions prototype/core/astro_coord/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_HaDec_by_RaDec(
raDec: 赤经赤纬J2000
date: 日期
observer: 观测者地理坐标

Returns:
haDec: 时角和赤纬(角度)
"""
Expand All @@ -40,7 +40,7 @@ def get_HaDec_in_solar(
starName: 天体名称
date: 日期
observer: 观察者地理坐标

Returns:
haDec: 时角和赤纬(角度)
"""
Expand All @@ -65,7 +65,7 @@ def get_HaDecs_by_names(
star_names: 恒星名称数组
timestamp: 时间戳
observer: 观察者地理坐标

Returns:
haDec: 时角和赤纬字典(角度)
is_success: 是否成功获取恒星赤经赤纬
Expand Down
4 changes: 2 additions & 2 deletions prototype/core/astro_coord/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def get_RaDec_by_name(
根据恒星名称获取其赤经和赤纬
Params:
starName: 恒星名称

Returns:
raDec: J2000赤经(时)和赤纬(角度)
"""
Expand Down Expand Up @@ -52,7 +52,7 @@ async def get_RaDecs_by_names(
根据恒星名称数组获取其赤经和赤纬
Params:
star_names: 恒星名称列表

Returns:
raDecs: 赤经和赤纬字典(角度)
"""
Expand Down
8 changes: 3 additions & 5 deletions prototype/core/astrometry/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ async def find_star(
timeout=10,
)
# 处理返回结果
ra, dec = (
field_rd.split("-") if "-" in field_rd else field_rd.split("+")
)
ra, dec = field_rd.split("-") if "-" in field_rd else field_rd.split("+")

if response.text.startswith("!! No astronomical object found :"):
# 如果找不到,就返回原来的坐标
Expand Down Expand Up @@ -343,7 +341,7 @@ def recognize(
content = httpx.get(rdls_url).content
xy2field_rd = dict() # 星点坐标到图中赤道坐标的映射
with fits.open(BytesIO(content)) as hdul:
hdul_data = hdul[1].data # type: ignore
hdul_data = hdul[1].data # type: ignore
for i in range(len(xy)):
xy2field_rd[
(
Expand All @@ -363,7 +361,7 @@ def recognize(
hd_names = []
assert type(round_xy) == list
for xy_item in round_xy:
rd_name = xy2rd_names[(float(xy_item[0]), float(xy_item[1]))] # type: ignore
rd_name = xy2rd_names[(float(xy_item[0]), float(xy_item[1]))] # type: ignore
ra, dec = rd_name[:2]
hour_ra = get_HaDec_by_RaDec((ra / 15, dec), stamp2ast_time(timestamp))
star_name = rd_name[2]
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions prototype/core/positioning/find_z/methods/fix_refraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_z(data: dict, z0: float, zenith: np.ndarray) -> float:
ra_decs: list of ra and dec in radians.
z0: initial guess of zenith point
zenith: zenith point, 2d array

Returns:
z: zenith point
"""
Expand Down Expand Up @@ -85,7 +85,7 @@ def rotate(vector: np.ndarray, zenith_vec: np.ndarray, angle: float) -> np.ndarr
vector: vector to rotate
zenith_vec: zenith vector
angle: angle to rotate in degrees

Returns:
rotated element vector
"""
Expand Down
4 changes: 3 additions & 1 deletion prototype/core/positioning/latitude/method/series2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import numpy as np


def astronomic_latitude_to_geodetic_latitude(astronomic_latitudes_in_degree: np.ndarray) -> np.ndarray:
def astronomic_latitude_to_geodetic_latitude(
astronomic_latitudes_in_degree: np.ndarray,
) -> np.ndarray:
bn = [
0.0016248797304581834,
-1.5959025318697836e-06,
Expand Down
45 changes: 26 additions & 19 deletions prototype/core/positioning/top_point/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
使用 python 来进行一组直线交点算法的验证。所提供的直线实际上交于一点,每条直线由两个端点坐标表示,含一定噪声,需要计算它们的真实交点。

## 排行榜

### 无畸变

**参数**:

```python
args.num_lines = 10 # 线的数量
args.num_tests = 100 # 测试次数
args.num_lines = 10 # 线的数量
args.num_tests = 100 # 测试次数
args.scope_x = (-300, 300)
args.scope_y = (-2000, -1000)
args.alpha = 0.2 # 0~1,越大时两点的距离越接近
Expand All @@ -18,18 +21,19 @@ args.k2 = 0 # 畸变系数
args.noise_std = 1 # 高斯噪声标准差
```

|排名|方法|平均误差|95%置信区间|
|---|---|---|---|
| 1 | [matrix_inverse](methods/matrix_inverse.py) | 7.684 | (6.496, 8.872) |
| 2 | [sphere](methods/sphere.py) | 7.687 | (6.498, 8.875) |
| 3 | [median2](methods/median2.py) | 8.987 | (7.709, 10.266) |
| 4 | [median](methods/median.py) | 9.203 | (7.899, 10.506) |
| 5 | [nearest_l2](methods/nearest_l2.py) | 11.375 | (8.062, 14.688) |
| 6 | [least_square](methods/least_square.py) | 11.570 | (8.128, 15.013) |
| 7 | [square_weight](methods/square_weight.py) | 45.755 | (31.688, 59.822) |
| 排名 | 方法 | 平均误差 | 95%置信区间 |
|----|-------------------------------------------------------------------|--------|------------------|
| 1 | [matrix_inverse_normalized](methods/matrix_inverse_normalized.py) | 3.953 | (3.831, 4.076) |
| 2 | [matrix_inverse](methods/matrix_inverse.py) | 8.022 | (7.807, 8.237) |
| 3 | [sphere](methods/sphere.py) | 8.025 | (7.810, 8.240) |
| 4 | [median2](methods/median2.py) | 9.375 | (9.114, 9.635) |
| 5 | [median](methods/median.py) | 9.548 | (9.283, 9.812) |
| 6 | [least_square](methods/least_square.py) | 11.964 | (11.057, 12.872) |

### 有畸变

**参数**:

```python
args.num_lines = 10 # 线的数量
args.num_tests = 3000 # 测试次数
Expand All @@ -41,23 +45,26 @@ args.k2 = 1e-14 # 畸变系数
args.noise_std = 1 # 高斯噪声标准差
```

|排名|方法|平均误差|95%置信区间|
|---|---|---|---|
| 1 | [matrix_inverse](methods/matrix_inverse.py) | 37.326 | (36.728, 37.923) |
| 2 | [sphere](methods/sphere.py) | 37.359 | (36.761, 37.957) |
| 3 | [median2](methods/median2.py) | 47.079 | (46.180, 47.977) |
| 4 | [median](methods/median.py) | 49.681 | (48.733, 50.629) |
| 5 | [least_square](methods/least_square.py) | 61.402 | (60.303, 62.501) |
| 排名 | 方法 | 平均误差 | 95%置信区间 |
|----|-------------------------------------------------------------------|--------|------------------|
| 1 | [matrix_inverse_normalized](methods/matrix_inverse_normalized.py) | 10.628 | (10.226, 11.030) |
| 2 | [matrix_inverse](methods/matrix_inverse.py) | 37.666 | (37.043, 38.289) |
| 3 | [sphere](methods/sphere.py) | 37.699 | (37.076, 38.323) |
| 4 | [median2](methods/median2.py) | 47.518 | (46.607, 48.430) |
| 5 | [median](methods/median.py) | 50.080 | (49.129, 51.031) |
| 6 | [least_square](methods/least_square.py) | 62.304 | (61.098, 63.511) |

## 使用方法

1. 在`core`目录下运行

```bash
python -m positioning.top_point.benchmark
```

## 贡献方法

1. 在 `methods` 目录下新建一个文件,实现一个算法。
需实现一个函数`intersection`,接受一个`numpy.ndarray`的`shape=(n, 2, 2)`的直线两点数组,返回一个`numpy.ndarray`的`shape=(2,)`的交点坐标数组。
需实现一个函数`intersection`,接受一个`numpy.ndarray`的`shape=(n, 2, 2)`的直线两点数组,返回一个`numpy.ndarray`的`shape=(2,)`的交点坐标数组。
2. 在 `benchmark.py` 的`methods`列表中添加你的方法。
3. 运行 `python benchmark.py` 来测试你的方法。
Empty file.
2 changes: 2 additions & 0 deletions prototype/core/positioning/top_point/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .methods.optim import intersection as optim
from .methods.sphere import intersection as sphere
from .methods.square_weight import intersection as square_weight
from .methods.matrix_inverse_normalized import intersection as matrix_inverse_normalized


def generate_lines(args):
Expand Down Expand Up @@ -178,6 +179,7 @@ def main(methods, args):
# "nearest_l2": nearest_l2,
"matrix_inverse": matrix_inverse,
# "optim": optim,
"matrix_inverse_normalized": matrix_inverse_normalized,
}

main(methods, args)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np


def intersection(lines: np.ndarray) -> np.ndarray:
"""
在 matrix_inverse 基础上改良:对直线方程的系数进行归一化
Find the intersection point of given lines.
params:
lines: numpy array, each row contains two points. [((x1, y1), (x2, y2)), ...]
return:
intersection point (x, y)
"""
V = lines[:, 1] - lines[:, 0]

A = np.zeros_like(V)
A[:, 0] = V[:, 1]
A[:, 1] = -V[:, 0]

lines_3d = np.dstack((lines, np.zeros((lines.shape[0], 2, 1))))
C = np.cross(lines_3d[:, 0], lines_3d[:, 1])[:, 2]

# 对直线方程的系数进行归一化
for i in range(len(A)):
a, b = A[i]
c = C[i]
m = a + b + c
A[i] /= m
C[i] /= m

A_inv = np.linalg.pinv(A)

point = A_inv @ C

return point
2 changes: 1 addition & 1 deletion prototype/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# 限流
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) # type: ignore
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) # type: ignore

# 分发路由
app.include_router(positioning.router, prefix="/api/positioning", tags=["positioning"])
Expand Down
2 changes: 1 addition & 1 deletion prototype/routers/astro_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def http_astro_coord(request: Request, data: astro_coord.AstroTime):
data:
star_names: list[str] 天体名称列表
timestamp: number 时间戳

Returns:
a dict:
detail: str, 计算情况
Expand Down
2 changes: 1 addition & 1 deletion prototype/routers/moon_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def http_time_by_moon(request: Request, data: moon_time.MoonTimeRequest):
scopeDays: number, date search range size (in days)
isFixRefraction: whether to fix refraction
isFixGravity: whether to fix gravity

Returns:
a dict:
time: float, the timestamp
Expand Down
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[project]
name = "starlocator"
version = "2.1.0"
description = "照片测星定位 网页app(地平论吧)"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"astronomy-engine>=2.1.19",
"astropy>=7.1.0",
"async-lru>=2.0.5",
"fastapi>=0.116.1",
"httpx>=0.28.1",
"numpy>=2.3.2",
"python-multipart>=0.0.20",
"scipy>=1.16.1",
"sep-pjw>=1.3.8",
"slowapi>=0.1.9",
"uvicorn[standard]>=0.35.0",
]

[[tool.uv.index]]
url = "https://mirrors.aliyun.com/pypi/simple"
default = true

[dependency-groups]
dev = [
"black>=25.1.0",
"matplotlib>=3.10.5",
"pytest>=8.4.1",
]
3 changes: 0 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-disable no-undef */
import './css/site.css';
import { InteractPhoto } from './interface/classes/interact.js';
import { EventManager } from './interface/classes/EventManager.js';

let interactPhoto = new InteractPhoto();
// eslint-disable-next-line no-unused-vars
let eventManager = new EventManager(interactPhoto);

/* eslint-enable no-undef */
Loading