Merge pull request #21 from nqrduck/measurement-name

Added name to measurement.
This commit is contained in:
Julia P 2024-05-05 15:40:31 +02:00 committed by GitHub
commit a4ef8fa9d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,7 @@ class Measurement:
Every spectrometer should adhere to this data structure in order to be compatible with the rest of the nqrduck. Every spectrometer should adhere to this data structure in order to be compatible with the rest of the nqrduck.
Args: Args:
name (str): Name of the measurement.
tdx (np.array): Time axis for the x axis of the measurement data. tdx (np.array): Time axis for the x axis of the measurement data.
tdy (np.array): Time axis for the y axis of the measurement data. tdy (np.array): Time axis for the y axis of the measurement data.
target_frequency (float): Target frequency of the measurement. target_frequency (float): Target frequency of the measurement.
@ -33,14 +34,15 @@ class Measurement:
def __init__( def __init__(
self, self,
tdx, name: str,
tdy, tdx: np.array,
target_frequency, tdy: np.array,
target_frequency: float,
frequency_shift: float = 0, frequency_shift: float = 0,
IF_frequency: float = 0, IF_frequency: float = 0,
) -> None: ) -> None:
"""Initializes the measurement.""" """Initializes the measurement."""
# Convert to decimal self.name = name
self.tdx = tdx self.tdx = tdx
self.tdy = tdy self.tdy = tdy
self.target_frequency = target_frequency self.target_frequency = target_frequency
@ -76,7 +78,6 @@ class Measurement:
return apodized_measurement return apodized_measurement
# Data saving and loading # Data saving and loading
def to_json(self): def to_json(self):
@ -86,6 +87,7 @@ class Measurement:
dict : The measurement in json-compatible format. dict : The measurement in json-compatible format.
""" """
return { return {
"name": self.name,
"tdx": self.tdx.tolist(), "tdx": self.tdx.tolist(),
"tdy": [ "tdy": [
[x.real, x.imag] for x in self.tdy [x.real, x.imag] for x in self.tdy
@ -106,6 +108,7 @@ class Measurement:
""" """
tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]]) tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]])
return cls( return cls(
json["name"],
np.array(json["tdx"]), np.array(json["tdx"]),
tdy, tdy,
target_frequency=json["target_frequency"], target_frequency=json["target_frequency"],
@ -113,6 +116,15 @@ class Measurement:
) )
# Measurement data # Measurement data
@property
def name(self):
"""Name of the measurement."""
return self._name
@name.setter
def name(self, value):
self._name = value
@property @property
def tdx(self): def tdx(self):
"""Time axis for the x axis of the measurement data.""" """Time axis for the x axis of the measurement data."""