Skip to content

Commit ea012d9

Browse files
kelledr-rodriguez
andauthored
Drop 3.10, improve/fix scheduled test (#584)
* add python matrix, drop 3.10 * add simbad check * restrict action to upstream repo * remove internet check. format output * up to 3.11 --------- Co-authored-by: David Rodriguez <[email protected]>
1 parent 72288c8 commit ea012d9

File tree

9 files changed

+115
-105
lines changed

9 files changed

+115
-105
lines changed

.github/workflows/gen-db.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323

24-
- name: Set up Python 3.11
24+
- name: Set up Python 3.13
2525
uses: actions/setup-python@v5
2626
with:
27-
python-version: '3.11'
27+
python-version: '3.13'
2828

2929
- name: Install dependencies
3030
run: |

.github/workflows/scheduled-tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Scheduled Checks
52

63
on:
74
schedule:
8-
- cron: '30 1 1 * *'
5+
- cron: '30 1 1 * *' # Runs at 1:30 AM on the first of every month
96
workflow_dispatch: # manual execution
107

118
jobs:
129
build:
13-
10+
if: github.repository == 'SIMPLE-AstroDB/SIMPLE-db'
1411
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.11, 3.12, 3.13]
1515

1616
steps:
1717
- uses: actions/checkout@v4
1818

19-
- name: Set up Python 3.11
19+
- name: Set up Python ${{ matrix.python-version }}
2020
uses: actions/setup-python@v5
2121
with:
22-
python-version: '3.11'
22+
python-version: ${{ matrix.python-version }}
2323

2424
- name: Install dependencies
2525
run: |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ authors = [
1616
{name = "Kelle Cruz", email = "[email protected]"},
1717
{name = "David Rodriguez", email = "[email protected]"},
1818
]
19-
requires-python = ">= 3.10"
19+
requires-python = ">= 3.11"
2020
dependencies = [
2121
"astrodbkit",
2222
"astrodb_utils",

simple/utils/astrometry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from astropy.units import Quantity
77
from astropy.table import Table
88
from astrodbkit.astrodb import Database
9-
from astrodb_utils import AstroDBError, find_source_in_db, find_publication
9+
from astrodb_utils import AstroDBError
10+
from astrodb_utils.sources import find_source_in_db
11+
from astrodb_utils.publications import find_publication
1012

1113

1214
__all__ = [

simple/utils/companions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
22
import sqlalchemy.exc
3-
from astrodb_utils import (
4-
AstroDBError, find_source_in_db
5-
)
6-
3+
from astrodb_utils import AstroDBError
4+
from astrodb_utils.sources import find_source_in_db
75

86
__all__ = [
97
"ingest_companion_relationships",

simple/utils/spectra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import sqlalchemy.exc
77
from astrodb_utils import (
88
AstroDBError,
9-
find_source_in_db,
109
internet_connection,
1110
)
11+
from astrodb_utils.sources import find_source_in_db
1212
from astrodb_utils.spectra import check_spectrum_plottable
1313
from astrodbkit.astrodb import Database
1414
from astropy.io import fits

simple/utils/spectral_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from simple.schema import SpectralTypes
77
from astrodb_utils import (
88
AstroDBError,
9-
find_source_in_db,
109
)
10+
from astrodb_utils.sources import find_source_in_db
1111

1212

1313
__all__ = [

tests/scheduled_checks.py

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,126 @@
33

44
import pytest
55
import requests
6-
from astrodb_utils.utils import internet_connection
7-
from astrodbkit.astrodb import Database, create_database
6+
from astrodb_utils import load_astrodb
87
from tqdm import tqdm
8+
from astroquery.simbad import Simbad
9+
from astrodbkit.utils import _name_formatter
910

1011
sys.path.append(".")
11-
from simple.schema import *
1212
from simple.schema import REFERENCE_TABLES
1313

14-
DB_NAME = "temp.sqlite"
14+
DB_NAME = "temp_SIMPLE.sqlite"
1515
DB_PATH = "data"
1616

1717

18-
# Load the database for use in individual tests
18+
# Load the SIMPLE database
1919
@pytest.fixture(scope="module")
2020
def db():
21-
# Create a fresh temporary database and assert it exists
22-
# Because we've imported simple.schema, we will be using that schema for the database
23-
24-
if os.path.exists(DB_NAME):
25-
os.remove(DB_NAME)
26-
connection_string = "sqlite:///" + DB_NAME
27-
create_database(connection_string)
28-
assert os.path.exists(DB_NAME)
2921

3022
# Connect to the new database and confirm it has the Sources table
31-
db = Database(connection_string, reference_tables=REFERENCE_TABLES)
32-
assert db
33-
assert "source" in [c.name for c in db.Sources.columns]
34-
35-
# Load data into an in-memory sqlite database first, for performance
36-
37-
# create and connects to a temporary in-memory database
38-
temp_db = Database("sqlite://", reference_tables=REFERENCE_TABLES)
23+
db = load_astrodb(DB_NAME, data_path=DB_PATH, reference_tables=REFERENCE_TABLES)
3924

40-
# load the data from the data files into the database
41-
temp_db.load_database(DB_PATH, verbose=False)
25+
return db
4226

43-
# dump in-memory database to file
44-
temp_db.dump_sqlite(DB_NAME)
45-
# replace database object with new file version
46-
db = Database("sqlite:///" + DB_NAME, reference_tables=REFERENCE_TABLES)
4727

48-
return db
28+
def test_db(db):
29+
assert os.path.exists(DB_NAME)
30+
assert db
31+
assert "source" in [c.name for c in db.Sources.columns]
4932

5033

5134
def test_spectra_urls(db):
5235
spectra_urls = db.query(db.Spectra.c.access_url).astropy()
5336
broken_urls = []
5437
codes = []
55-
internet, _ = internet_connection()
56-
if internet:
57-
for spectrum_url in tqdm(spectra_urls["access_url"]):
58-
request_response = requests.head(spectrum_url)
59-
status_code = request_response.status_code
60-
# The website is up if the status code is 200
61-
# cuny academic commons links give 301 status code
62-
if status_code != 200 and status_code != 301:
63-
broken_urls.append(spectrum_url)
64-
codes.append(status_code)
38+
39+
for spectrum_url in tqdm(spectra_urls["access_url"]):
40+
request_response = requests.head(spectrum_url)
41+
status_code = request_response.status_code
42+
# The website is up if the status code is 200
43+
# cuny academic commons links give 301 status code
44+
if status_code not in (200, 301):
45+
broken_urls.append(spectrum_url)
46+
codes.append(status_code)
6547

6648
# Display broken spectra regardless if it's the number we expect or not
6749
print(f"found {len(broken_urls)} broken spectra urls: {broken_urls}, {codes}")
6850

69-
assert 4 <= len(broken_urls) <= 4
51+
assert 5 == len(broken_urls)
52+
53+
# Expected fails:
54+
# 11123099-7653342.txt',
55+
# L1_OPT_2MASS_J10595138-2113082_Cruz2003.txt
56+
# 0000%252B2554_IRS_spectrum.fits'
57+
# 0415-0935.fits',
58+
# 2MASS+J22541892%2B3123498.fits'])
59+
60+
61+
def test_source_simbad(db):
62+
# Query Simbad and confirm that there are no duplicates with different names
63+
64+
# Get list of all source names
65+
results = db.query(db.Sources.c.source).all()
66+
name_list = [s[0] for s in results]
67+
68+
# Add all IDS to the Simbad output as well as the user-provided id
69+
Simbad.add_votable_fields("ids")
70+
71+
print("Querying SIMBAD for all SIMPLE sources")
72+
simbad_results = Simbad.query_objects(name_list)
73+
74+
duplicate_count = 0
75+
not_in_simbad = []
76+
in_simbad = []
77+
78+
print("Checking all SIMPLE sources for Simbad names")
79+
for row in tqdm(simbad_results[["main_id", "ids", "user_specified_id"]].iterrows()):
80+
simple_name = row[2]
81+
try:
82+
simbad_ids = row[1].decode("utf-8")
83+
except AttributeError:
84+
# Catch decoding error
85+
simbad_ids = row[1]
86+
87+
# Get a nicely formatted list of Simbad names for each input row
88+
simbad_names = [
89+
_name_formatter(s)
90+
for s in simbad_ids.split("|")
91+
if _name_formatter(s) != "" and _name_formatter(s) is not None
92+
]
93+
94+
if len(simbad_names) == 0:
95+
not_in_simbad.append(simple_name)
96+
continue
97+
else:
98+
in_simbad.append(simple_name)
99+
100+
# Examine DB for each input, displaying results when more than one source matches
101+
t = db.search_object(
102+
simbad_names,
103+
output_table="Sources",
104+
fmt="astropy",
105+
fuzzy_search=False,
106+
verbose=False,
107+
)
108+
if len(t) > 1:
109+
print(f"Multiple matches for {simple_name}: {simbad_names}")
110+
print(
111+
db.query(db.Names).filter(db.Names.c.source.in_(t["source"])).astropy()
112+
)
113+
duplicate_count += 1
114+
115+
assert duplicate_count == 0, "Duplicate sources identified via Simbad queries"
116+
assert (
117+
len(not_in_simbad) == 425
118+
), f"Expecting {len(not_in_simbad)} sources not found in Simbad"
119+
120+
assert len(in_simbad) == 3012, "Sources found in Simbad"
121+
print(f"Found {len(in_simbad)} SIMPLE sources in Simbad")
122+
123+
assert len(not_in_simbad) + len(in_simbad) == len(
124+
name_list
125+
), "Not all sources checked"
126+
127+
print(f"Found {len(not_in_simbad)} SIMPLE sources not in Simbad")
128+
print("\n".join(not_in_simbad))

tests/test_integrity.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Test to verify database integrity
22
# database object 'db' defined in conftest.py
3-
import pytest
43
from astrodbkit.astrodb import or_
5-
from astrodbkit.utils import _name_formatter
64
from astropy import units as u
75
from astropy.table import unique
8-
from astroquery.simbad import Simbad
96
from sqlalchemy import and_, func
107

118
from simple.schema import ParallaxView # , PhotometryView
@@ -247,52 +244,6 @@ def test_source_uniqueness2(db):
247244
assert len(duplicate_names) == 0
248245

249246

250-
@pytest.mark.skip(reason="SIMBAD unreliable")
251-
def test_source_simbad(db):
252-
# Query Simbad and confirm that there are no duplicates with different names
253-
254-
# Get list of all source names
255-
results = db.query(db.Sources.c.source).all()
256-
name_list = [s[0] for s in results]
257-
258-
# Add all IDS to the Simbad output as well as the user-provided id
259-
Simbad.add_votable_fields("ids")
260-
Simbad.add_votable_fields("typed_id")
261-
262-
simbad_results = Simbad.query_objects(name_list)
263-
# Get a nicely formatted list of Simbad names for each input row
264-
duplicate_count = 0
265-
for row in simbad_results[["TYPED_ID", "IDS"]].iterrows():
266-
try:
267-
name, ids = row[0].decode("utf-8"), row[1].decode("utf-8")
268-
except AttributeError:
269-
# Catch decoding error
270-
name, ids = row[0], row[1]
271-
272-
simbad_names = [
273-
_name_formatter(s)
274-
for s in ids.split("|")
275-
if _name_formatter(s) != "" and _name_formatter(s) is not None
276-
]
277-
278-
if len(simbad_names) == 0:
279-
print(f"No Simbad names for {name}")
280-
continue
281-
282-
# Examine DB for each input, displaying results when more than one source matches
283-
t = db.search_object(
284-
simbad_names, output_table="Sources", fmt="astropy", fuzzy_search=False
285-
)
286-
if len(t) > 1:
287-
print(f"Multiple matches for {name}: {simbad_names}")
288-
print(
289-
db.query(db.Names).filter(db.Names.c.source.in_(t["source"])).astropy()
290-
)
291-
duplicate_count += 1
292-
293-
assert duplicate_count == 0, "Duplicate sources identified via Simbad queries"
294-
295-
296247
def test_photometry(db):
297248
# Tests for Photometry table
298249

0 commit comments

Comments
 (0)