Skip to content

Commit

Permalink
feat(email): Added functionality to send a voe email
Browse files Browse the repository at this point in the history
  • Loading branch information
tabbott36 committed May 2, 2024
1 parent 90314b4 commit d55725b
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 158 deletions.
46 changes: 13 additions & 33 deletions frbvoe/models/email.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""format a VOE for a TNS submission."""

from typing import Any, Dict

import picologging as logging
from pydantic import Field, SecretStr
from typing import Any, Dict
from pydantic import Field, SecretStr, StrictStr

from frbvoe.models.voe import VOEvent
from frbvoe.utilities.email import report, retract, update
from frbvoe.utilities.email import send

logging.basicConfig()
log = logging.getLogger()
Expand All @@ -16,44 +15,25 @@ class Email(VOEvent):
"""Represents an email object for sending VOEvents.
Tokenized Attributes:
email_username (SecretStr) : VOEvent author email account username. Optional.
email_password (SecretStr) : VOEvent author email account password. Optional.
"""

email_username: SecretStr = Field(
default=None, description="VOEvent author email account username. Optional."
)
email_password: SecretStr = Field(
default=None, description="VOEvent author email account password. Optional."
default=None,
description="VOEvent author email account password. Optional."
)
update_message: StrictStr = Field(
default=None,
description="Custom email message to send in an update VOEvent. Optional."
)

@property
def report(voevent: Dict[str, Any]):
def send_to_subscribers(email_report: Dict[str, Any]):
"""Sends the VOEvent email.
Args:
voevent (Dict[str, Any]): The VOEvent data.
Returns:
None
status (str): The status of the email.
"""
# subject = "Subject"
# email_message = "This is the email"
log.info("Sending VOE payload to Email as a report.")
report(voevent)

@property
def retract(voevent: Dict[str, Any]):
"""Retract the FRB from the Comet server."""
# subject = "Subject"
# email_message = "This is the email"
log.info("Sending VOE payload to Email as a retraction.")
retract(voevent)

@property
def update(voevent: Dict[str, Any]):
"""Update the FRB on the Comet server."""
# subject = "Subject"
# email_message = "This is the email"
log.info("Sending VOE payload to Email as an update.")
update(voevent)
log.info("Emailing VOE payload to subscribers.")
send(email_report)
11 changes: 7 additions & 4 deletions frbvoe/models/tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class TNS(VOEvent):
description="API key for the TNS. Required.",
)
tns_report_id: int = Field(
..., description="Report ID for the TNS submission. Required."
...,
description="Report ID for the TNS submission. Required."
)
tns_bot_name: SecretStr = Field(
...,
description="Name of the TNS bot. Required."
)
tns_bot_name: SecretStr = Field(..., description="Name of the TNS bot. Required.")

@property
def submit(tns_report: Dict[str, Any]):
def submit(tns_report: Dict[str, Any]): #TODO
"""Submits a VOEvent to the TNS API.
Args:
Expand Down
47 changes: 20 additions & 27 deletions frbvoe/models/voe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@ class VOEvent(BaseSettings):
Args:
BaseSettings (BaseSettings): Pydantic BaseSettings.
Note:
The selection priority for attributes in descending order is:
- Arguments passed to the `VOEvent` Object.
- Environment variables with `FRB_VOE_` prefix.
- The default values in the class constructor.
Tokenized Attributes:
TODO: DB interaction tokens? (Q4 Shiny)
Attributes:
kind (str): Which kind of VOEvent. Required.
- One of: detection, subsequent, retraction, or update
author (str): Name of the VOEvent author. Required.
observatory_name (str): Name of the host observatory. Required.
date (datetime): Detection time of the FRB. Required.
email (EmailStr): Email address of the VOEvent author. Required.
semi_major (float): Semi-major axis of the error ellipse of the
Expand All @@ -41,8 +31,10 @@ class VOEvent(BaseSettings):
bandwidth (float): Bandwidth of the observation. Optional.
central_frequency (float): Central frequency of the observation. Optional.
npol (int): Number of polarizations of the observation. Optional.
bits_per_sample (int) : Bits per sample of the observation. Optional.
gain (float): Gain of the observation. Optional.
tsys (float): System temperature of the observation. Optional.
internal_id (str): Internal ID of the FRB. Optional.
dm (float): Dispersion measure of the observation. Optional.
dm_error (float): Error in the dispersion measure. Optional.
width (float): Width of the pulse. Optional.
Expand All @@ -52,7 +44,7 @@ class VOEvent(BaseSettings):
time (datetime): Time of the observation. Required.
right_ascension (float): Right ascension of the observation. Required.
declination (float): Declination of the observation. Required.
localization_error (float): Localization error of the observation. Optional.
pos_error_deg_95 (float): 95% localization error of the observation. Optional.
importance (float): Importance of the observation between 0 and 1. Optional.
website (str): Website of the host observatory. Optional.
tns_name (str): TNS name of the event. Optional.
Expand All @@ -64,12 +56,11 @@ class VOEvent(BaseSettings):
VOEvent: VOEvent object.
"""

model_config = SettingsConfigDict(
model_config = SettingsConfigDict( #TODO: Shiny, do I need this since there are no tokens used?
title="FRB VOEvent",
validate_assignment=True,
validate_return=True,
revalidate_instances="always",
env_prefix="FRB_VOE_",
# This parameter ignores any extra fields that are not defined in the model
extra="ignore",
)
Expand All @@ -79,8 +70,8 @@ class VOEvent(BaseSettings):
"retraction",
"update",
] = Field(..., description="Which kind of VOEvent. Required.", example="detection")
author: StrictStr = Field(
..., description="Name of the VOEvent author. Required.", example="John Smith"
observatory_name: StrictStr = Field(
..., description="Name of the host observatory. Required.", example="CHIME"
)
date: datetime = Field(
...,
Expand Down Expand Up @@ -124,13 +115,19 @@ class VOEvent(BaseSettings):
gt=0.0,
description="Central frequency of the observatory in MHz. Optional.",
example=600,
)
)
npol: StrictInt = Field(
default=None,
gt=0,
description="Number of polarizations of the observation. Optional.",
example=2,
)
bits_per_sample: int = Field(
default=None,
gt=0,
description="Bits per sample of the observatory. Optional.",
example=8,
)
gain: float = Field(
default=None,
description="Gain of the observatory in dB. Optional.",
Expand All @@ -142,6 +139,10 @@ class VOEvent(BaseSettings):
description="System temperature of the observatory in K. Optional.",
example=25.0,
)
internal_id: StrictStr = Field(
default=None,
description="Internal ID of the FRB. Optional.",
)
dm: float = Field(
default=None,
gt=0.0,
Expand Down Expand Up @@ -180,10 +181,10 @@ class VOEvent(BaseSettings):
description="Declination of the FRB in degrees (-90 ≤ Dec ≤ 90). Required.",
example=14.2049,
)
localization_error: Optional[StrictFloat] = Field(
pos_error_deg_95: Optional[StrictFloat] = Field(
default=None,
gt=0.0,
description="Error of the localization region in degrees. Required.",
description="95% localization error of the observation. Required.",
example=0.001,
)
importance: float = Field(
Expand All @@ -202,16 +203,8 @@ class VOEvent(BaseSettings):
description="Transient Name Server name of the FRB. Optional.",
example="FRB20210826A",
)

@property
def payload(self):
"""Return the VOEvent payload."""
log.info("Returning VOEvent payload")
return self.dict()


# TODO: Functionality
# from frbvoe.models.voe import VOEvent

# voe = VOEvent(...)
# tns = TNS(**voe.payload)
Loading

0 comments on commit d55725b

Please sign in to comment.