Skip to content

Commit 670c412

Browse files
authored
Merge pull request #130 from SNEWS2/integrate-snews-data-formats
Integrate snews-data-formats into snews-cs
2 parents 6044eac + d2704d3 commit 670c412

16 files changed

+2609
-1834
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: tests
66
# events but only for the main branch
77
on:
88
push:
9-
branches:
9+
branches:
1010
- main
1111
- release_*
1212
pull_request:
@@ -22,14 +22,7 @@ jobs:
2222
matrix:
2323
# Test all supported Python versions under Ubuntu
2424
os: [ubuntu-latest]
25-
# python-version: ['3.9', '3.10', '3.11']
2625
python-version: ['3.11', '3.12']
27-
# # Additionally, test one Python version under MacOS and Windows, to detect OS-specific issues
28-
# include:
29-
# - os: macos-latest
30-
# python-version: '3.12'
31-
# - os: windows-latest
32-
# python-version: '3.12'
3326

3427
# The type of runner that the job will run on.
3528
runs-on: ${{ matrix.os }}
@@ -56,7 +49,7 @@ jobs:
5649
- name: Install hop-client
5750
run: |
5851
python -m pip install setuptools wheel
59-
python -m pip install hop-client==0.9.0
52+
python -m pip install hop-client==0.10.0
6053
cd /home/runner/work/SNEWS_Coincidence_System/SNEWS_Coincidence_System
6154
6255
- shell: bash

poetry.lock

Lines changed: 1197 additions & 894 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ snews_cs = "snews_cs.__main__:main"
3131
[tool.poetry.dependencies]
3232
python = ">=3.11, <3.13"
3333
click = "^8.1.7"
34-
hop-client = "^0.9.0"
34+
hop-client = "^0.10.0"
3535
ipython = "<7.33.0" # Constrained by snews_pt
3636
numpy = "^1.26.0"
3737
pandas = "^2.1.1"
38-
python-dotenv = "0.19.2" # Constrained by snews_pt
38+
python-dotenv = "^0.19" # Constrained by snews_pt
3939
pymongo = "^4.5.0"
4040
slack-sdk = "^3.26.2"
4141
matplotlib = "^3.8.0"
4242
scipy = "^1.11.3"
4343
sqlalchemy = "^2.0.32"
4444
tabulate = "^0.9.0"
4545
snews-pt = { git = "https://github.com/SNEWS2/SNEWS_Publishing_Tools.git", branch = "main" }
46+
snews-data-formats = "^1.0.0"
4647

4748
[tool.poetry.group.dev.dependencies]
4849
autopep8 = "^2.0.4"

requirements.txt

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,72 @@
11
adc-streaming==2.4.0 ; python_version >= "3.11" and python_version < "3.13"
2+
annotated-types==0.7.0 ; python_version >= "3.11" and python_version < "3.13"
23
ansicon==1.89.0 ; python_version >= "3.11" and python_version < "3.13" and platform_system == "Windows"
34
appnope==0.1.4 ; python_version >= "3.11" and python_version < "3.13" and sys_platform == "darwin"
4-
authlib==1.3.1 ; python_version >= "3.11" and python_version < "3.13"
5+
authlib==1.3.2 ; python_version >= "3.11" and python_version < "3.13"
56
backcall==0.2.0 ; python_version >= "3.11" and python_version < "3.13"
67
blessed==1.20.0 ; python_version >= "3.11" and python_version < "3.13"
7-
certifi==2024.7.4 ; python_version >= "3.11" and python_version < "3.13"
8-
cffi==1.17.0 ; python_version >= "3.11" and python_version < "3.13" and platform_python_implementation != "PyPy"
9-
charset-normalizer==3.3.2 ; python_version >= "3.11" and python_version < "3.13"
8+
certifi==2024.8.30 ; python_version >= "3.11" and python_version < "3.13"
9+
cffi==1.17.1 ; python_version >= "3.11" and python_version < "3.13" and platform_python_implementation != "PyPy"
10+
charset-normalizer==3.4.0 ; python_version >= "3.11" and python_version < "3.13"
1011
click==8.1.7 ; python_version >= "3.11" and python_version < "3.13"
1112
colorama==0.4.6 ; python_version >= "3.11" and python_version < "3.13" and (platform_system == "Windows" or sys_platform == "win32")
12-
confluent-kafka==2.5.0 ; python_version >= "3.11" and python_version < "3.13"
13-
contourpy==1.2.1 ; python_version >= "3.11" and python_version < "3.13"
14-
cryptography==43.0.0 ; python_version >= "3.11" and python_version < "3.13"
13+
confluent-kafka==2.6.1 ; python_version >= "3.11" and python_version < "3.13"
14+
contourpy==1.3.1 ; python_version >= "3.11" and python_version < "3.13"
15+
cryptography==43.0.3 ; python_version >= "3.11" and python_version < "3.13"
1516
cycler==0.12.1 ; python_version >= "3.11" and python_version < "3.13"
1617
decorator==5.1.1 ; python_version >= "3.11" and python_version < "3.13"
17-
dnspython==2.6.1 ; python_version >= "3.11" and python_version < "3.13"
18-
fastavro==1.9.5 ; python_version >= "3.11" and python_version < "3.13"
19-
fonttools==4.53.1 ; python_version >= "3.11" and python_version < "3.13"
20-
greenlet==3.0.3 ; python_version < "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version >= "3.11"
21-
hop-client==0.9.0 ; python_version >= "3.11" and python_version < "3.13"
22-
idna==3.7 ; python_version >= "3.11" and python_version < "3.13"
18+
dnspython==2.7.0 ; python_version >= "3.11" and python_version < "3.13"
19+
fastavro==1.9.7 ; python_version >= "3.11" and python_version < "3.13"
20+
fonttools==4.55.0 ; python_version >= "3.11" and python_version < "3.13"
21+
greenlet==3.1.1 ; python_version < "3.13" and (platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64") and python_version >= "3.11"
22+
hop-client==0.10.0 ; python_version >= "3.11" and python_version < "3.13"
23+
idna==3.10 ; python_version >= "3.11" and python_version < "3.13"
2324
inquirer==2.10.1 ; python_version >= "3.11" and python_version < "3.13"
2425
ipython==7.32.0 ; python_version >= "3.11" and python_version < "3.13"
25-
jedi==0.19.1 ; python_version >= "3.11" and python_version < "3.13"
26+
jedi==0.19.2 ; python_version >= "3.11" and python_version < "3.13"
2627
jinxed==1.3.0 ; python_version >= "3.11" and python_version < "3.13" and platform_system == "Windows"
27-
kiwisolver==1.4.5 ; python_version >= "3.11" and python_version < "3.13"
28+
kiwisolver==1.4.7 ; python_version >= "3.11" and python_version < "3.13"
2829
matplotlib-inline==0.1.7 ; python_version >= "3.11" and python_version < "3.13"
2930
matplotlib==3.9.2 ; python_version >= "3.11" and python_version < "3.13"
3031
numpy==1.26.4 ; python_version >= "3.11" and python_version < "3.13"
31-
packaging==24.1 ; python_version >= "3.11" and python_version < "3.13"
32-
pandas==2.2.2 ; python_version >= "3.11" and python_version < "3.13"
32+
packaging==24.2 ; python_version >= "3.11" and python_version < "3.13"
33+
pandas==2.2.3 ; python_version >= "3.11" and python_version < "3.13"
3334
parso==0.8.4 ; python_version >= "3.11" and python_version < "3.13"
3435
pexpect==4.9.0 ; python_version >= "3.11" and python_version < "3.13" and sys_platform != "win32"
3536
pickleshare==0.7.5 ; python_version >= "3.11" and python_version < "3.13"
36-
pillow==10.4.0 ; python_version >= "3.11" and python_version < "3.13"
37+
pillow==11.0.0 ; python_version >= "3.11" and python_version < "3.13"
3738
pluggy==1.5.0 ; python_version >= "3.11" and python_version < "3.13"
38-
prompt-toolkit==3.0.47 ; python_version >= "3.11" and python_version < "3.13"
39+
prompt-toolkit==3.0.48 ; python_version >= "3.11" and python_version < "3.13"
3940
ptyprocess==0.7.0 ; python_version >= "3.11" and python_version < "3.13" and sys_platform != "win32"
41+
pycountry==22.3.5 ; python_version >= "3.11" and python_version < "3.13"
4042
pycparser==2.22 ; python_version >= "3.11" and python_version < "3.13" and platform_python_implementation != "PyPy"
43+
pydantic-core==2.23.4 ; python_version >= "3.11" and python_version < "3.13"
44+
pydantic-extra-types==2.10.0 ; python_version >= "3.11" and python_version < "3.13"
45+
pydantic==2.9.2 ; python_version >= "3.11" and python_version < "3.13"
4146
pygments==2.18.0 ; python_version >= "3.11" and python_version < "3.13"
42-
pymongo==4.8.0 ; python_version >= "3.11" and python_version < "3.13"
43-
pyparsing==3.1.2 ; python_version >= "3.11" and python_version < "3.13"
47+
pymongo==4.10.1 ; python_version >= "3.11" and python_version < "3.13"
48+
pyparsing==3.2.0 ; python_version >= "3.11" and python_version < "3.13"
4449
python-dateutil==2.9.0.post0 ; python_version >= "3.11" and python_version < "3.13"
4550
python-dotenv==0.19.2 ; python_version >= "3.11" and python_version < "3.13"
4651
python-editor==1.0.4 ; python_version >= "3.11" and python_version < "3.13"
47-
pytz==2024.1 ; python_version >= "3.11" and python_version < "3.13"
48-
readchar==4.2.0 ; python_version >= "3.11" and python_version < "3.13"
52+
pytz==2024.2 ; python_version >= "3.11" and python_version < "3.13"
53+
readchar==4.2.1 ; python_version >= "3.11" and python_version < "3.13"
4954
requests==2.32.3 ; python_version >= "3.11" and python_version < "3.13"
50-
scipy==1.14.0 ; python_version >= "3.11" and python_version < "3.13"
55+
scipy==1.14.1 ; python_version >= "3.11" and python_version < "3.13"
5156
setuptools==62.1.0 ; python_version >= "3.11" and python_version < "3.13"
57+
single-version==1.6.0 ; python_version >= "3.11" and python_version < "3.13"
5258
six==1.16.0 ; python_version >= "3.11" and python_version < "3.13"
53-
slack-sdk==3.31.0 ; python_version >= "3.11" and python_version < "3.13"
54-
snews-pt @ git+https://github.com/SNEWS2/SNEWS_Publishing_Tools.git@e513fb7561ad1a037c06489a8e4ecb20ef5efb88 ; python_version >= "3.11" and python_version < "3.13"
55-
sqlalchemy==2.0.32 ; python_version >= "3.11" and python_version < "3.13"
59+
slack-sdk==3.33.4 ; python_version >= "3.11" and python_version < "3.13"
60+
snews-data-formats==1.0.0 ; python_version >= "3.11" and python_version < "3.13"
61+
snews-pt @ git+https://github.com/SNEWS2/SNEWS_Publishing_Tools.git@main ; python_version >= "3.11" and python_version < "3.13"
62+
sqlalchemy==2.0.36 ; python_version >= "3.11" and python_version < "3.13"
5663
tabulate==0.9.0 ; python_version >= "3.11" and python_version < "3.13"
5764
toml==0.10.2 ; python_version >= "3.11" and python_version < "3.13"
58-
tqdm==4.66.5 ; python_version >= "3.11" and python_version < "3.13"
65+
tqdm==4.67.0 ; python_version >= "3.11" and python_version < "3.13"
5966
traitlets==5.14.3 ; python_version >= "3.11" and python_version < "3.13"
6067
typing-extensions==4.12.2 ; python_version >= "3.11" and python_version < "3.13"
61-
tzdata==2024.1 ; python_version >= "3.11" and python_version < "3.13"
62-
urllib3==2.2.2 ; python_version >= "3.11" and python_version < "3.13"
68+
tzdata==2024.2 ; python_version >= "3.11" and python_version < "3.13"
69+
urllib3==2.2.3 ; python_version >= "3.11" and python_version < "3.13"
6370
wcwidth==0.2.13 ; python_version >= "3.11" and python_version < "3.13"
6471
wheel==0.34.2 ; python_version >= "3.11" and python_version < "3.13"
65-
xmltodict==0.13.0 ; python_version >= "3.11" and python_version < "3.13"
72+
xmltodict==0.14.2 ; python_version >= "3.11" and python_version < "3.13"

snews_cs/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1+
from ._version import version as __version__
12
from .core.logging import initialize_logging
23

34
initialize_logging("debug")
4-
import pandas as pd
5-
pd.options.mode.chained_assignment = None
6-
7-
try:
8-
from ._version import version as __version__
9-
except ImportError:
10-
pass

snews_cs/__main__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
88
"""
99

10+
import os
11+
from pathlib import Path
12+
from socket import gethostname
13+
1014
# https://click.palletsprojects.com/en/8.0.x/utils/
11-
import click, os
12-
from . import __version__
13-
from . import cs_utils
15+
import click
16+
17+
from . import __version__, cs_utils
1418
from . import snews_coinc as snews_coinc
15-
from . heartbeat_feedbacks import FeedBack
16-
from socket import gethostname
19+
from .database import Database
20+
from .heartbeat_feedbacks import FeedBack
21+
22+
# Database initialized before any command is called
23+
db = Database(db_file_path=Path(__file__).parent.parent / "snews_cs.db")
24+
db.initialize_database(sql_schema_path=Path(__file__).parent / "db_schema.sql")
1725

1826

1927
@click.group(invoke_without_command=True)
@@ -38,17 +46,18 @@ def main(ctx, env):
3846
@click.option('--email/--no-email', default=True, show_default='True', help='Whether to send emails along with the alert')
3947
@click.option('--slackbot/--no-slackbot', default=True, show_default='True', help='Whether to send the alert on slack')
4048
def run_coincidence(firedrill, dropdb, email, slackbot):
41-
""" Initiate Coincidence Decider
49+
""" Initiate Coincidence Decider
4250
"""
51+
4352
HOST = gethostname()
4453
coinc = snews_coinc.CoincidenceDistributor(drop_db=dropdb,
4554
firedrill_mode=firedrill,
4655
server_tag=HOST,
4756
send_email=email,
4857
send_slack=slackbot)
49-
try:
58+
try:
5059
coinc.run_coincidence()
51-
except KeyboardInterrupt:
60+
except KeyboardInterrupt:
5261
pass
5362
except Exception as e:
5463
print(e)

snews_cs/cs_alert_schema.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from .cs_utils import set_env
21
from datetime import datetime
32

3+
from .cs_utils import set_env
4+
5+
46
class CoincidenceTierAlert:
57
""" The Message scheme for the alert and observations
68
@@ -20,13 +22,13 @@ def id_format(self, num_detectors):
2022
time format should always be same for all detectors.
2123
num_detectors: `int`
2224
Number of detectors in the alert. If more than 2,
23-
it is an update to an earlier alert, and will be
25+
it is an update to an earlier alert, and will be
2426
appended with -UPDATE_ string
2527
2628
Returns
2729
:`str`
2830
The formatted id as a string
29-
31+
3032
"""
3133
date_time = datetime.utcnow().isoformat()
3234
if num_detectors == 2:
@@ -37,32 +39,30 @@ def id_format(self, num_detectors):
3739
def get_cs_alert_schema(self, data, is_test=False):
3840
""" Create a message schema for alert.
3941
Internally called in hop_pub
40-
42+
4143
Parameters
4244
----------
4345
data : `named tuple`
4446
cs_utils data tuple with predefined field.
45-
47+
4648
Returns
4749
-------
4850
:`dict`
49-
message with the correct scheme
51+
message with the correct scheme
5052
5153
"""
5254
id = self.id_format(len(data['detector_names']))
53-
alert_type = "TEST "+ data['alert_type'] if is_test else data['alert_type']
54-
try:
55-
far = f"Would happen every {data['false_alarm_prob']:.2e} year"
56-
except:
57-
far = data['false_alarm_prob']
58-
return {"_id": id,
59-
"alert_type":alert_type,
60-
"server_tag": data['server_tag'],
61-
"False Alarm Prob": far,
62-
"detector_names": data['detector_names'],
63-
"sent_time": id.split(' ')[1],
64-
"p_values": data['p_vals'],
65-
"neutrino_times": data['neutrino_times'],
66-
"p_values average": data['p_val_avg'],
67-
"sub list number": data['sub_list_num']
68-
}
55+
alert_type = "TEST " + data['alert_type'] if is_test else data['alert_type']
56+
57+
return {
58+
"id": id,
59+
"alert_type": alert_type,
60+
"server_tag": data['server_tag'],
61+
"False Alarm Prob": data['false_alarm_prob'],
62+
"detector_names": data['detector_names'],
63+
"sent_time": id.split(' ')[1],
64+
"p_values": data['p_vals'],
65+
"neutrino_times": data['neutrino_times'],
66+
"p_values average": data['p_val_avg'],
67+
"sub list number": data['sub_list_num'],
68+
}

0 commit comments

Comments
 (0)