Skip to content

Commit

Permalink
Merge pull request #161 from NTIA/sigmf_location_update
Browse files Browse the repository at this point in the history
Sigmf location update
  • Loading branch information
dboulware committed Jul 11, 2019
2 parents ca0080d + c000643 commit def53c6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/actions/acquire_single_freq_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
from capabilities import capabilities
from hardware import sdr
from sensor import settings, utils
from status.utils import get_location

from .base import Action

Expand Down Expand Up @@ -231,6 +232,8 @@ def build_sigmf_md(self, task_id):

sigmf_md.add_capture(start_index=0, metadata=capture_md)

location = get_location()

for i, detector in enumerate(M4sDetector):
frequency_domain_detection_md = {
"ntia-core:annotation_type": "FrequencyDomainDetection",
Expand All @@ -243,6 +246,12 @@ def build_sigmf_md(self, task_id):
"ntia-algorithm:reference": "not referenced",
}

if location:
frequency_domain_detection_md["core:latitude"] = str(location.latitude)
frequency_domain_detection_md["core:longitude"] = str(
location.longitude
)

sigmf_md.add_annotation(
start_index=(i * self.fft_size),
length=self.fft_size,
Expand Down
8 changes: 8 additions & 0 deletions src/actions/acquire_stepped_freq_tdomain_iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from capabilities import capabilities
from hardware import sdr
from sensor import settings, utils
from status.utils import get_location

from .base import Action

Expand Down Expand Up @@ -154,10 +155,17 @@ def acquire_data(self, fc, task_id):
data = np.append(data, acq)
capture_md = {"core:frequency": fc, "core:datetime": dt}
sigmf_md.add_capture(start_index=0, metadata=capture_md)

annotation_md = {
"ntia-core:annotation_type": "CalibrationAnnotation",
"ntia-calibration:receiver_scaling_factor": self.sdr.radio.scale_factor,
}

location = get_location()
if location:
annotation_md["core:latitude"] = str(location.latitude)
annotation_md["core:longitude"] = str(location.longitude)

sigmf_md.add_annotation(start_index=0, length=nsamps, metadata=annotation_md)

return data, sigmf_md
Expand Down
14 changes: 14 additions & 0 deletions src/status/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging

from .models import Location

logger = logging.getLogger(__name__)


def get_location():
"""Returns Location object JSON if set or None and logs an error."""
try:
return Location.objects.filter(active=True).get()
except Location.DoesNotExist:
logger.error("You must create a Location in /admin.")
return None
14 changes: 7 additions & 7 deletions src/status/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
from scheduler import scheduler
from sensor import utils

from .models import Location
from .serializers import LocationSerializer

from .utils import get_location

logger = logging.getLogger(__name__)


def get_location():
def serialize_location():
"""Returns Location object JSON if set or None and logs an error."""
try:
sensor_def = Location.objects.filter(active=True).get()
sensor_def = get_location()
if sensor_def:
return LocationSerializer(sensor_def).data
except Location.DoesNotExist:
logger.error("You must create a Location in /admin.")
else:
return None


Expand All @@ -38,7 +38,7 @@ def status(request, version, format=None):
return Response(
{
"scheduler": scheduler.thread.status,
"location": get_location(),
"location": serialize_location(),
"system_time": utils.get_datetime_str_now(),
"last_calibration_time": get_last_calibration_time(),
}
Expand Down

0 comments on commit def53c6

Please sign in to comment.