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
4 changes: 2 additions & 2 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ backend:
- [slowapi](https://github.com/laurents/slowapi): MIT License
- [sep](http://github.com/kbarbary/sep): LGPL-3.0 License
- [astropy](https://www.astropy.org/): BSD 3-Clause License
- [astrometry.net](https://astrometry.net): Custom License. The [client.py](./prototype/core/star_recognition/client.py) file of this project contains some content from astrometry and has been modified based on it, mainly integrating the star recognition function.
- [astrometry.net](https://astrometry.net): Custom License. The [client.py](./backend/core/star_recognition/client.py) file of this project contains some content from astrometry and has been modified based on it, mainly integrating the star recognition function.

data:
- [SIMBAD](https://simbad.u-strasbg.fr/simbad/): This project has made use of the SIMBAD database, operated at CDS, Strasbourg, France
- [stellarium](https://github.com/Stellarium/stellarium): GPL-2.0 license. The [data.py](./prototype/core/astro_coord/data.py) and [starZH2EN.js](./src/interface/starZH2EN.js) files of this project contains some content from stellarium and has been modified based on it, mainly integrating the Chinese and English star name tables.
- [stellarium](https://github.com/Stellarium/stellarium): GPL-2.0 license. The [data.py](./backend/core/astro_coord/data.py) and [starZH2EN.js](./src/interface/starZH2EN.js) files of this project contains some content from stellarium and has been modified based on it, mainly integrating the Chinese and English star name tables.
1 change: 1 addition & 0 deletions backend/.pythen-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
File renamed without changes.
3 changes: 0 additions & 3 deletions prototype/config.py → backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
LOG_LEVEL = "info"

# API_KEY
## 百度地图 JS API KEY
BMAP_API_KEY = "******"
## astrometry API_KEY
ASTROMETRY_API_KEY = "******"

Expand All @@ -45,5 +43,4 @@
CORS_ALLOW_ORIGIN = [
FRONTEND_BASEURL,
BACKEND_BASEURL,
"https://api.map.baidu.com",
]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,37 @@ def get_HaDec_in_solar(
return (hour_angle, equ_ofdate.dec)


def get_HaDecs_by_names(
def get_HaDecs_sync(
star_names: list[str],
timestamp: float,
observer: ast.Observer,
pre_fetched_ra_decs: dict[str, tuple[float | None, float | None]],
) -> tuple[dict[str, tuple[float | None, float | None]], str]:
"""同步计算天体时角和赤纬(不涉及网络请求)"""
ha_desc = dict()
detail = "success"
ast_time = stamp2ast_time(timestamp)

for star_name in star_names:
operate_name = star_name
if operate_name in starZH2EN:
operate_name = starZH2EN[operate_name]
operate_name = operate_name.lower()

if operate_name in solar_bodies:
ha_desc[star_name] = get_HaDec_in_solar(operate_name, ast_time, observer)
else:
ra_dec = pre_fetched_ra_decs.get(operate_name, (None, None))
ha_desc[star_name] = get_HaDec_by_RaDec(ra_dec, ast_time, observer)

for star_name in star_names:
if ha_desc[star_name][0] is None or ha_desc[star_name][1] is None:
detail = f"未能获取天体 '{star_name}' 的坐标信息,请检查拼写或稍后重试"
break

return ha_desc, detail

async def get_HaDecs_by_names(
star_names: list[str],
timestamp: float,
observer: ast.Observer = ast.Observer(0, 0, 0),
Expand All @@ -71,40 +101,16 @@ def get_HaDecs_by_names(
is_success: 是否成功获取恒星赤经赤纬
"""

ha_desc = dict() # 时角和赤纬数组(角度)
fixed_star_names = dict() # 太阳系外要查询的恒星名(查询名: 操作名)
solar_star_names = dict() # 太阳系内要查询的天体名(查询名: 操作名)
detail = "success" # 是否成功获取恒星赤经赤纬
ast_time = stamp2ast_time(timestamp)

fixed_star_names = []
for star_name in star_names:
operate_name = star_name
# 如果匹配到汉英对照星表,则转换为英文名
if operate_name in starZH2EN:
operate_name = starZH2EN[operate_name]
operate_name = operate_name.lower()
if operate_name in solar_bodies:
solar_star_names[star_name] = operate_name
else:
fixed_star_names[star_name] = operate_name
if operate_name not in solar_bodies:
fixed_star_names.append(operate_name)

# 异步获取恒星的赤经和赤纬
ra_decs = asyncio.run(get_RaDecs_by_names(list(fixed_star_names.values())))
# 同步计算天体的时角和赤纬
# 计算太阳系外天体的时角和赤纬
for star_name in fixed_star_names.keys():
ha_desc[star_name] = get_HaDec_by_RaDec(
ra_decs[fixed_star_names[star_name]], ast_time, observer
)

# 计算太阳系内天体的时角和赤纬
for star_name, operate_name in solar_star_names.items():
ha_desc[star_name] = get_HaDec_in_solar(operate_name, ast_time, observer)

# 检查是否成功获取恒星赤经赤纬
for star_name in star_names:
if ha_desc[star_name][0] is None or ha_desc[star_name][1] is None:
detail = "fail"
break

return ha_desc, detail
ra_decs = await get_RaDecs_by_names(fixed_star_names)

return get_HaDecs_sync(star_names, timestamp, observer, ra_decs)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import re
import httpx
import asyncio
from .data import solar_bodies
from async_lru import alru_cache
from config import CACHE_SIZE, MAX_CONNECTIONS

# 设置最大并发数
limits = httpx.Limits(
max_connections=MAX_CONNECTIONS,
max_keepalive_connections=MAX_CONNECTIONS,
)

from config import CACHE_SIZE
from core.utils.http import get_http_client
import httpx

@alru_cache(maxsize=CACHE_SIZE)
async def get_RaDec_by_name(
Expand All @@ -30,19 +24,20 @@ async def get_RaDec_by_name(
return (None, None)

star_name_base64 = re.sub(r"\s+", "+", star_name)
client = get_http_client()

async with httpx.AsyncClient(limits=limits) as client:
response = await client.get(
f"https://simbad.u-strasbg.fr/simbad/sim-nameresolver?ident={star_name_base64}&output=json&data=J&option=strict"
response = await client.get(
f"https://simbad.u-strasbg.fr/simbad/sim-nameresolver?ident={star_name_base64}&output=json&data=J&option=strict",
timeout=10,
)
if response.status_code != 200:
raise ValueError(
f"Failed request astrocoord with status code {response.status_code}"
)
if response.status_code != 200:
raise ValueError(
f"Failed request astrocoord with status code {response.status_code}"
)
data = response.json()
ra = data[0]["ra"] / 15
dec = data[0]["dec"]
return (star_name, (ra, dec))
data = response.json()
ra = data[0]["ra"] / 15
dec = data[0]["dec"]
return (star_name, (ra, dec))


async def get_RaDecs_by_names(
Expand All @@ -63,7 +58,7 @@ async def get_RaDecs_by_names(
try:
raDec = await task
raDecs_tmp.append(raDec)
except ValueError:
except (httpx.HTTPError, ValueError, KeyError, IndexError, TypeError):
pass
raDecs_tmp = dict(raDecs_tmp)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def overlay_plot(self, service, outfn, wcsfn, wcsext=0):
imageh=wcs.imageh,
)
result = self.send_request(service, {"wcs": params})
logging.info(f"Result status: {result["status"]}")
logging.info(f"Result status: {result['status']}")
plotdata = result["plot"]
plotdata = base64.b64decode(plotdata)
open(outfn, "wb").write(plotdata)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from PIL import Image
import sep_pjw as sep
import sep


def extract_stars(
Expand Down Expand Up @@ -41,8 +41,8 @@ def extract_stars(
clean=clean,
clean_param=clean_param,
)
except Exception as e:
return str(e), None
except Exception:
return "图片噪点过高或无法在图像中提取到有效星点", None
# 提取星星位置
positions = np.around(
np.array([objects["x"], objects["y"]]),
Expand Down
Loading
Loading