common.application_layer.services package
Submodules
common.application_layer.services.gbo_calculator_service module
- exception common.application_layer.services.gbo_calculator_service.ResourceNotFound
Bases:
ExceptionException to raise when the GBO Calculator’s database does not contain the requested resource_id
- exception common.application_layer.services.gbo_calculator_service.ResourceNotValid
Bases:
ExceptionException to raise when the GBO Calculator determines a resource to be invalid
- common.application_layer.services.gbo_calculator_service.calculate_from_resource(params: dict[str, str | bool | float | int]) Response
Sends a request to the GBO Sensitivity Calculator to make a time calculation given a resource_id and set of parameters for calculation. Required inputs can change depending on other inputs and hardware.
- Parameters:
params – dictionary of inputs for calculation, where an example superset of inputs looks like
- {
“resourceId”: “244-49”, “rSigRef”: 1, “noAvgRef”: 1, “smoothing”: “velocity_resolution_topo”, “smoothing_resolution”: 1, “conversion”: “Sensitivity to Time”, “units”: “flux”, “sensitivity”: 1, “time”: 1, “frame”: “Rest Frame”, “restFreq”: 1440, “doppler”: “Optical”, “redshift”: 0, “sourceVelocity”: 0.0, “sourceDiameterSlider”: 0, “effectiveBw”: 12, “galactic”: “estimated”, “rightAscension”: 0, “estimatedContinuum”: 0, “declination”: 0, “minElevation”: 5, “diffSignal”: True, “avgPol”: True, “topocentricFreq”: 1440, “dutyCycle”: 10,
} :raises ValueError: if any required keys are missing from params. This is checked multiple times, as requirements change based on other inputs :raises ResourceNotFound: if the specified resourceId in params is not found :return: Response object containing the calulation response, where resp[“e”] contains the results, resp[“messages”] contains warnings, and the other keys contain inputs and other metadata
- common.application_layer.services.gbo_calculator_service.calculate_from_target()
- common.application_layer.services.gbo_calculator_service.calculate_requested_time_from_target(target: ScienceTarget) Quantity
Asks the GBO Sensitivity Calculator for the total observing time needed
- Parameters:
target – the ScienceTarget to calculate for
- Raises:
ResourceNotFound – if the target’s resource_id is not found in the GBO Calculator database
ValueError – if the target does not have contain everything the calculator requires
CalculationError – if the calculator’s response does not contain a usable time
- Returns:
the total observing time as a time Quantity
- common.application_layer.services.gbo_calculator_service.conform_time_params(params: dict[str, str | bool | float | int]) dict[str, str | bool | float | int]
Helper function to translate camelCase to snake_case inputs for the GBO Sensitivity Calculator API
- Parameters:
params – Dictionary of params originally sent to calculate_from_resource function
- Returns:
The same dictionary, but with appropriate camelCase keys replaced with snake_case ones
- common.application_layer.services.gbo_calculator_service.get_doppler(doppler: str) str
- common.application_layer.services.gbo_calculator_service.get_frame(frame: str) str
- common.application_layer.services.gbo_calculator_service.get_gbt_calculator_params(hardware_config: HardwareConfiguration, target: ScienceTarget | ReferenceTarget)
Given a Science|Reference target and its hardware configuration, returns the parameters needed to request time from the GBO Sensitivity Calculator
- Parameters:
hardware_config – the saved HardwareConfiguration for the target
target – a ScienceTarget or ReferenceTarget to calculate for
- Returns:
dict of params required by the Sensitivity Calculator
- common.application_layer.services.gbo_calculator_service.get_hardware_from_resource(resource_id: str) Response
Sends a request to the GBO Sensitivity Calculator to lookup the Hardware saved for a given resource_id.
- Parameters:
resource_id – str representing an existing resource_id
- Raises:
ValueError – if resource_id is not given
ResourceNotFound – if requested resource_id does not exist in the GBO Calculator database
- Returns:
Response object with hardware and any warnings in JSON body like
- {
“hardware”: { “backend”: “VErsatile GB Astronomical Spectrometer”, “mode”: “Spectral Line”, “receiver”: “L (1.15 - 1.73 GHz)”, “beams”: 1, “polarization”: “Full”, “bandwidth”: 11.72, “windows”: 1, “switching”: “In-Band Frequency Switching”
- }
“warnings”: {[
“The requested resource was saved under previous Sensitivity Calculator version “243”. Current version is “244””
]}
}
- common.application_layer.services.gbo_calculator_service.get_hardware_options(params: dict[str, str | float | int]) Response
Sends a request to the GBO Sensitivity Calculator to lookup valid hardware options downstream from backend, mode, & receiver selections.
- Parameters:
params – dictionary of hardware inputs containing at least values for backend, mode, & receiver, e.g.:
- {
“backend”: “VErsatile GB Astronomical Spectrometer”, “mode”: “Spectral Line”, “receiver”: “L (1.15 - 1.73 GHz)”,
} :raises ValueError: if backend, mode, or receiver are not given in params :return: Response object with JSON containing all HW keys not originally specified, each of which stores a list of valid options
- common.application_layer.services.gbo_calculator_service.get_resolution(target: ScienceTarget)
- common.application_layer.services.gbo_calculator_service.get_resource_id(params: dict[str, str]) Response
Sends a request to the GBO Sensitivity Calculator to create and/or fetch a resource_id for the hardware specified in params.
- Parameters:
params – dictionary of hardware specification. Example payload:
- {
“backend”: “CCB”, “mode”: “Continuum”, “frontend”: “Ka (26.0 - 39.8 GHz)”, “beams”: 2, “polarization”: “Single”, “bandwidth”: 3500.0, “windows”: 4, “switching”: “Beam Switching - Nodding between beams”
} :raises ValueError: if any expected keys are missing from params :raises ResourceNotValid if the resource is determined invalid :return: Response object with resource_id in JSON body. Status=201 if newly created, else 200
- common.application_layer.services.gbo_calculator_service.parse_total_observing_time(calculation: dict) Quantity
Reads the total observing time out of a GBO Sensitivity Calculator response.
- Parameters:
calculation – the JSON body of a calculate_from_resource response
- Raises:
CalculationError – if the response does not contain a usable time
- Returns:
the calculator’s “Derived Total Observing Time” (t_tot) as a time Quantity
common.application_layer.services.notification_sender_service module
- common.application_layer.services.notification_sender_service.send_basic_notification(message: str, subject: str, primary_recipient: str, cc_recipient: str | None = None) None
Send a basic email notification via Workspaces’ notification service
- Parameters:
message – Body of the email
subject – Subject of the email
primary_recipient – Primary recipient of the email
cc_recipient – Optional CC recipient for the email
- Raises:
RuntimeError – When the notification service fails to send the email
- common.application_layer.services.notification_sender_service.send_notification(template: str, parameters: dict[str, str] | None = None) None
Send an email notification through Workspaces’ notification service
- Parameters:
template – Name of mustache template for email, must correspond to entry in Workspaces’ template database
parameters – Parameters for given template
- Raises:
RuntimeError – When the notification service fails to send the email
common.application_layer.services.permissions_service module
common.application_layer.services.rct_service module
- exception common.application_layer.services.rct_service.RctInvalidResponse
Bases:
ExceptionRaised when a successful RCT response does not contain valid JSON.
- exception common.application_layer.services.rct_service.RctNotAuthorized
Bases:
ExceptionRaised when RCT refuses the request for the given user.
- exception common.application_layer.services.rct_service.RctNotConfigured
Bases:
ExceptionRaised when no RCT service URL is configured.
- exception common.application_layer.services.rct_service.RctResourceNotFound
Bases:
ExceptionRaised when RCT does not know the requested resource.
Bases:
ExceptionRaised when RCT cannot be reached or returns a server error.
- common.application_layer.services.rct_service.get_resource(resource_id: str, user_id: str, base_url: str = 'http://nmstest-vml.aoc.nrao.edu:9000') Response
Fetch the resource validation report from the RCT for the given user.
Example call: GET {RCT_URL}/v1/resources/4159177?userId=-1
Until user authorization is integrated, requests send RCT_BYPASS_USER_ID instead of user_id.
- Parameters:
resource_id – the resource id to validate
user_id – the id of the user requesting validation; currently not sent to RCT
base_url – base URL of the RCT service; defaults to the configured RCT_URL
- Raises:
RctNotConfigured – if RCT_URL is not set
RctUnavailable – on connection failure, timeout, or a 5xx response
RctResourceNotFound – on a 404 response
RctNotAuthorized – on a 401 or 403 response
requests.HTTPError – on any other non-2xx response
RctInvalidResponse – if the 2xx response body is not valid JSON
- Returns:
Response object from the RCT service (2xx)