mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 12:30:01 +00:00
Added to and from json.
This commit is contained in:
parent
50fb662e90
commit
b93967666d
1 changed files with 24 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import numpy as np
|
||||
from nqrduck.helpers.signalprocessing import SignalProcessing as sp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -25,6 +26,29 @@ class Measurement():
|
|||
self.fdx, self.fdy = sp.fft(tdx, tdy, frequency_shift)
|
||||
self.IF_frequency = IF_frequency
|
||||
|
||||
# Data saving and loading
|
||||
|
||||
def to_json(self):
|
||||
"""Converts the measurement to a json-compatible format."""
|
||||
return {
|
||||
"tdx": [[x.real, x.imag] for x in self.tdx], # Convert complex numbers to list
|
||||
"tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list
|
||||
"target_frequency": self.target_frequency,
|
||||
"IF_frequency": self.IF_frequency
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
"""Converts the json format to a measurement."""
|
||||
tdx = np.array([complex(x[0], x[1]) for x in json["tdx"]])
|
||||
tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]])
|
||||
return cls(
|
||||
tdx,
|
||||
tdy,
|
||||
json["target_frequency"],
|
||||
json["IF_frequency"]
|
||||
)
|
||||
|
||||
# Measurement data
|
||||
@property
|
||||
def tdx(self):
|
||||
|
|
Loading…
Reference in a new issue