Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal agnostic default calibration files, load actions and sensor def in settings, initialize signal analyzer in gunicorn. #266

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
f26bfba
Enable mock sensor. Set BASE_IMAGE to USRP. Update requirements for U…
dboulware Dec 5, 2023
32d0d79
debug scos_actions.
dboulware Dec 6, 2023
56d7434
debugging.
dboulware Dec 7, 2023
478ff00
scos-actions 7.0.1
dboulware Dec 7, 2023
dc85300
empty_calibration_params
dboulware Dec 7, 2023
27f1bab
don't use mock_sigan
dboulware Dec 7, 2023
b30e694
Update readme and add default sensor_calibration.json file.
dboulware Dec 11, 2023
22f5734
Update BASE_IMAGE and add link to readme.
dboulware Dec 11, 2023
5139b27
Rename default calibration file. Set DEFAULT_CALIBRATION_FILE variabl…
dboulware Jan 3, 2024
834e9dd
default cal file and update readme.
dboulware Jan 8, 2024
7c63bf2
sigan monitor
dboulware Jan 8, 2024
de81df7
move signal_analyzer_monitor to scos_actions.status
dboulware Jan 8, 2024
95b9743
typo fix.
dboulware Jan 8, 2024
598c098
print actions dir.
dboulware Jan 8, 2024
8a9a479
Set ACTIONS_DIR in all settings.
dboulware Jan 8, 2024
114ea89
Register actions in configs/actions.
dboulware Jan 8, 2024
9dd9201
Switch actions and tekrsa branches.
dboulware Jan 9, 2024
51e8986
scos_actions.core refactor.
dboulware Jan 9, 2024
3d59c77
discover action types, gps and sigan and ensure one sigan and actions…
dboulware Jan 11, 2024
3b2d892
delete faulty import.
dboulware Jan 11, 2024
d2c55b6
remove erroneous import.
dboulware Jan 11, 2024
403899b
sigan->signal_analyzer.
dboulware Jan 11, 2024
194a0a1
typo
dboulware Jan 12, 2024
5d88874
fix sigan detection.
dboulware Jan 12, 2024
ae5a1ee
fix setting sigan in actions.
dboulware Jan 12, 2024
629b199
remove scheduler signal_analyzer.
dboulware Jan 12, 2024
f74dc64
debugging
dboulware Jan 12, 2024
fcc8910
fix log message.
dboulware Jan 12, 2024
315b46d
Add SIGAN_MODULE and SIGAN_CLASS settings.
dboulware Jan 12, 2024
c62c282
Instantiate specified sigan and pass to scheduler.
dboulware Jan 12, 2024
4ba3080
remove action_registrar.
dboulware Jan 12, 2024
c9495ae
remove register_action
dboulware Jan 12, 2024
b1cd580
remove checking for sigan and gps from actions/__init__.py
dboulware Jan 12, 2024
f9cf7c2
import from actions in schedule.
dboulware Jan 12, 2024
45911e9
import environs in config.py
dboulware Jan 12, 2024
ec84466
fix logging error.
dboulware Jan 12, 2024
1592ea5
register sigan as status provider. Correct default sigan module.
dboulware Jan 12, 2024
549dd16
typo fix.
dboulware Jan 12, 2024
b57e87d
fix setting scheduler sigan.
dboulware Jan 12, 2024
d71762f
add initializatino package and create Sensor in gunicorn/config.py
dboulware Jan 13, 2024
50d61ad
add logging to settings. Fix actions_loader import.
dboulware Jan 13, 2024
cb61023
move action loading functions into settings.
dboulware Jan 13, 2024
2ea680b
uppercase settings ACTIONS.
dboulware Jan 13, 2024
5bdc21d
move initialization utilities.
dboulware Jan 13, 2024
fb1efc9
remove actions app from settings and don't import django setting in i…
dboulware Jan 13, 2024
fe0c73a
sync settings files.
dboulware Jan 13, 2024
65b5744
move capabilities into settings.
dboulware Jan 13, 2024
4d5d3cc
add missing capabilities in settings files.
dboulware Jan 13, 2024
87bf2e9
remove refs to scos_actions.capabilities
dboulware Jan 13, 2024
25185fd
syntax.
dboulware Jan 13, 2024
d0a5a23
import django settings in gunicorn/config.py
dboulware Jan 13, 2024
3fb91ff
remove migration and runtime settings. Make switch_configs_dir a Path.
dboulware Jan 13, 2024
7ec6df3
Initialize calibrations and pass to signal analyzer.
dboulware Jan 13, 2024
2c643dd
mark Calibrations as default or not.
dboulware Jan 13, 2024
af3f5dd
add status and signal analyzer registration handlers. Don't import ca…
dboulware Jan 13, 2024
6ff7994
register sigan.
dboulware Jan 13, 2024
3956cef
import logging.
dboulware Jan 13, 2024
3c1d1a4
import load_from_json
dboulware Jan 13, 2024
6e22f7a
pass if is_default into loading calibration from json.
dboulware Jan 14, 2024
d629cd5
fix register_sigan handler
dboulware Jan 14, 2024
3973c12
fix mistaken deletion
dboulware Jan 14, 2024
d1e5beb
fix loop to register switches.
dboulware Jan 14, 2024
15c4f77
send signal in config.
dboulware Jan 14, 2024
356e1f0
typo fix.
dboulware Jan 14, 2024
e8b6ecc
debugging.
dboulware Jan 14, 2024
11b5fe7
load preselector config from json.
dboulware Jan 14, 2024
b9a9d44
send signal in config. add type hints.
dboulware Jan 14, 2024
29bcd32
Replace scheduler signal_analyzer with sensor.
dboulware Jan 14, 2024
7a4d16c
correct ref to signal_analyzer in status.
dboulware Jan 14, 2024
17d27af
move status registration into initializatino methods.
dboulware Jan 14, 2024
16e571e
Add register sensor handler. Update registered sensors location when …
dboulware Jan 14, 2024
a1838e6
Fix sensor import in location handler.
dboulware Jan 14, 2024
ce50dc4
send register sensor signal.
dboulware Jan 14, 2024
1a8abb2
add sender to register sensor signal send.
dboulware Jan 14, 2024
1b46c91
If there is an active location in the database, use it over the senso…
dboulware Jan 14, 2024
bac837f
initialize location to None.
dboulware Jan 14, 2024
377a94c
Set description when saving location from sensor definition file.
dboulware Jan 14, 2024
603fc53
cleanup
dboulware Jan 14, 2024
ad179fc
log location handler. Correct comment.
dboulware Jan 14, 2024
fc3e6db
Remove actions app.
dboulware Jan 14, 2024
1b0258e
use description from sensor def file if saving loc to db.
dboulware Jan 15, 2024
19caf84
Move scos_actions imports so django is configured.
dboulware Jan 15, 2024
861c5d7
Place all initialization methods in intialization/__init__.py. Defer …
dboulware Jan 15, 2024
36ab6ce
don't set SENSOR_DEFINITION_HASH in settings.
dboulware Jan 15, 2024
db17975
missing import.
dboulware Jan 15, 2024
d04a825
Initialize actions, and capabilities in settings so they are there du…
dboulware Jan 15, 2024
9b5a8f3
remove invalid imports.
dboulware Jan 15, 2024
d6926fc
set sigan and sensor calibration file environment variables.
dboulware Jan 15, 2024
5f2275d
Set DEFAULT_CALIBRATION_FILE environment variable.
dboulware Jan 15, 2024
64df810
Fix env error
dboulware Jan 15, 2024
d28091a
set env vars as strings.
dboulware Jan 15, 2024
6be34cb
Fix handler tests. Sync sensor/wsgi with gunicorn/config.py
dboulware Jan 16, 2024
cba6b7b
use action_classes in plugins instead of action_types.
dboulware Jan 16, 2024
78ab76f
fix logger init.
dboulware Jan 16, 2024
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
171 changes: 171 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,177 @@ specific to the sensor you are using.
}
```

### Sensor Calibration File
By default, scos-sensor will use `configs/default_calibration.json` as the sensor calibration file. However, if
`configs/sensor_calibration.json` or `configs/sigan_calibration.json` exist they will be used instead of the default
calibration file. Sensor calibration files allow scos-sensor to apply a gain based on a laboratory calibration of
the sensor and may also contain other useful metadata that characterizes the sensor performance. For additional
information on the calibration data, see the [NTIA-Sensor SigMF Calibration Object](https://github.com/NTIA/sigmf-ns-ntia/blob/master/ntia-sensor.sigmf-ext.md#08-the-calibration-object).
The default calibration file is shown below:
```json
{
"calibration_data":{
"datetime": "1970-01-01T00:00:00.000000Z",
"gain": 0,
"noise_figure": null,
"1db_compression_point": null,
"enbw": null,
"temperature": 26.85
},
"last_calibration_datetime": "1970-01-01T00:00:00.000000Z",
"calibration_parameters": [],
"clock_rate_lookup_by_sample_rate": [
],
"sensor_uid": "DEFAULT CALIBRATION",
"calibration_reference": "noise source output"
}
```
The `calibration_parameters` key lists the parameters that will be used to obtain
the calibration data. In the case of the default calibration, there are no
`calibration_parameters` so the calibration data is found directly within the
`calibration_data` element and by default scos-sensor will not apply any additional
gain. Typically, a sensor would be calibrated at particular
sensing parameters. The calibration data for specific parameters should be listed
within the calibration_data object and accessed by the values of the settings listed in the
calibration_parameters element. For example, the calibration below provides an example of a
sensor calibrated at a sample rate of 14000000.0 samples per second at several
frequencies with a signal analyzer reference level setting of -25.
```json
{
"calibration_parameters": [
"sample_rate",
"frequency",
"reference_level"
],
"calibration_datetime": "2020-11-18T23:13:09.156274Z",
"calibration_data": {
"14000000.0":{
"3555000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3565000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3575000000":{

"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3585000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3595000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3605000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3615000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3625000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3635000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3645000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3655000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3665000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3675000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3685000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
},
"3695000000":{
"-25":{
"noise_figure": 46.03993010994134,
"enbw": 15723428.858731967,
"gain": 0.40803345928877379
}
}
}
},
"clock_rate_lookup_by_sample_rate": [
{
"sample_rate": 3500000.0,
"clock_frequency": 3500000.0
},
{
"sample_rate": 28000000.0,
"clock_frequency": 28000000.0
}
],
"sensor_uid": "US55120115"
}

```
When an action is run with the above calibration, scos will expect the action to have
a sample_rate, frequency, and reference_level specified in the action config. The values
specified for these parameters will then be used to retrieve the calibration data.

## Security

This section covers authentication, permissions, and certificates used to access the
Expand Down
16 changes: 16 additions & 0 deletions configs/default_calibration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"calibration_data":{
"datetime": "1970-01-01T00:00:00.000000Z",
"gain": 0,
"noise_figure": 0.0,
"1db_compression_point": null,
"enbw": null,
"temperature": 26.85
},
"last_calibration_datetime": "1970-01-01T00:00:00.000000Z",
"calibration_parameters": [],
"clock_rate_lookup_by_sample_rate": [
],
"sensor_uid": "DEFAULT CALIBRATION",
"calibration_reference": "noise source output"
}
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ services:
- POSTGRES_PASSWORD
- SCOS_SENSOR_GIT_TAG
- SECRET_KEY
- SIGAN_MODULE
- SIGAN_CLASS
- SIGAN_POWER_SWITCH
- SIGAN_POWER_CYCLE_STATES
expose:
Expand Down
13 changes: 2 additions & 11 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1636,16 +1636,7 @@
"title": "Action",
"description": "[Required] The name of the action to be scheduled",
"type": "string",
"enum": [
"logger",
"test_monitor_sigan",
"test_multi_frequency_iq_action",
"test_nasctn_sea_data_product",
"test_single_frequency_iq_action",
"test_single_frequency_m4s_action",
"test_survey_iq_action",
"test_sync_gps"
]
"enum": []
},
"priority": {
"title": "Priority",
Expand Down Expand Up @@ -1941,4 +1932,4 @@
}
}
}
}
}
5 changes: 0 additions & 5 deletions entrypoints/api_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ function cleanup_demodb {

trap cleanup_demodb SIGTERM
trap cleanup_demodb SIGINT
# This is done to avoid loading actions and connecting to the sigan when migrations are applied and when
# the super user is created.
cp sensor/migration_settings.py sensor/settings.py
echo "Starting Migrations"
python3.8 manage.py migrate


echo "Creating superuser (if managed)"
python3.8 /scripts/create_superuser.py
cp sensor/runtime_settings.py sensor/settings.py

echo "Starting Gunicorn"
exec gunicorn sensor.wsgi -c ../gunicorn/config.py &
Expand Down
6 changes: 0 additions & 6 deletions files/README.md

This file was deleted.

68 changes: 65 additions & 3 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import importlib
import logging
import os
import sys
from multiprocessing import cpu_count



bind = ":8000"
workers = 1
worker_class = "gthread"
threads = cpu_count()

loglevel = os.environ.get("GUNICORN_LOG_LEVEL", "info")

logger = logging.getLogger(__name__)

def _modify_path():
"""Ensure Django project is on sys.path."""
Expand All @@ -27,9 +31,67 @@ def post_worker_init(worker):
import django

django.setup()

from scheduler import scheduler

from initialization import (
load_preselector,
load_switches,
)
from initialization import (
get_sensor_calibration,
get_sigan_calibration
)
from django.conf import settings
from status.models import Location
from scos_actions.hardware.sensor import Sensor
from scos_actions.metadata.utils import construct_geojson_point
from scos_actions.signals import register_component_with_status
from scos_actions.signals import register_signal_analyzer
from scos_actions.signals import register_sensor

sigan_module_setting = settings.SIGAN_MODULE
sigan_module = importlib.import_module(sigan_module_setting)
logger.info("Creating " + settings.SIGAN_CLASS + " from " + settings.SIGAN_MODULE)
sigan_constructor = getattr(sigan_module, settings.SIGAN_CLASS)
sensor_cal = get_sensor_calibration(settings.SENSOR_CALIBRATION_FILE, settings.DEFAULT_CALIBRATION_FILE)
sigan_cal = get_sigan_calibration(settings.SIGAN_CALIBRATION_FILE, settings.DEFAULT_CALIBRATION_FILE)
sigan = sigan_constructor(sensor_cal=sensor_cal, sigan_cal=sigan_cal)
register_component_with_status.send(sigan, component=sigan)
register_signal_analyzer.send(sigan, signal_analyzer=sigan)

switches = load_switches(settings.SWITCH_CONFIGS_DIR)
capabilities = settings.CAPABILITIES
preselector = load_preselector(settings.PRESELECTOR_CONFIG, settings.PRESELECTOR_MODULE, settings.PRESELECTOR_CLASS, capabilities["sensor"])
location = None
if "location" in capabilities["sensor"]:
try:
sensor_loc = capabilities["sensor"].pop("location")
try:
#if there is an active database location, use it over the value in the sensor def.
db_location = Location.objects.get(active=True)
location = construct_geojson_point(db_location.longitude, db_location.latitude, db_location.height)
except Location.DoesNotExist:
# This should never occur because status/migrations/0003_auto_20211217_2229.py
# will load the No DB location. Use sensor def location and save to DB.
location = construct_geojson_point(
sensor_loc["x"],
sensor_loc["y"],
sensor_loc["z"] if "z" in sensor_loc else None,
)
#Save the sensor location from the sensor def to the database
db_location = Location()
db_location.longitude = sensor_loc["x"]
db_location.latitude = sensor_loc["y"]
db_location.height = sensor_loc["z"]
db_location.gps = False
db_location.description = sensor_loc["description"]
db_location.save()
except:
logger.exception("Failed to get sensor location from sensor definition.")


sensor = Sensor(signal_analyzer=sigan, preselector = preselector, switches = switches, capabilities = capabilities, location = location)
scheduler.thread.sensor = sensor
register_sensor.send(sensor, sensor=sensor)
scheduler.thread.start()


Expand Down
6 changes: 3 additions & 3 deletions scripts/print_action_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import django

from utils.action_registrar import registered_actions
from actions import actions

PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src")

Expand All @@ -16,7 +16,7 @@
django.setup()


action_names = sorted(registered_actions.keys())
action_names = sorted(actions.keys())


if __name__ == "__main__":
Expand All @@ -28,4 +28,4 @@
),

args = parser.parse_args()
print(registered_actions[args.action].description)
print(actions[args.action].description)
Empty file added src/__init__.py
Empty file.
Loading
Loading