Skip to content

Commit

Permalink
Merge pull request #669 from necst-telescope/#668-add_all_read
Browse files Browse the repository at this point in the history
#668 add all read
  • Loading branch information
takayama-27 authored Oct 16, 2024
2 parents 2ffe992 + be628a8 commit eba598c
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 115 deletions.
12 changes: 6 additions & 6 deletions neclib/defaults/Alab_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ _ = "CPZ340816"
rsw_id = 0
channel = { sis_ch1 = 2, sis_ch2 = 4}
max_mv = [-15, 15]
converter = "x / 3"
converter = {sis_ch1 = "x / 3", sis_ch2 = "x / 3"}

[sis_bias_reader]
_ = "CPZ3177"
rsw_id = 0
ave_num = 100
smpl_freq = 1000
single_diff = "DIFF"
all_ch_num = 10
all_ch_num = 4
ch_range = '5V'
channel = {sis_ch1_V = 2, sis_ch1_I = 1, sis_ch2_V = 4, sis_ch2_I = 3}
converter = [
{ ch = "sis_ch1_V", V = "x * 10" },
{ ch = "sis_ch1_I", I = "x * 1000" },
{ ch = "sis_ch2_V", V = "x * 10" },
{ ch = "sis_ch2_I", I = "x * 1000" },
{ ch = "sis_ch1_V", func = "x * 10", units = "mV" },
{ ch = "sis_ch1_I", func = "x * 1000", units = "uA" },
{ ch = "sis_ch2_V", func = "x * 10", units = "mV" },
{ ch = "sis_ch2_I", func = "x * 1000" , units = "uA"},
]

[local_attenuator]
Expand Down
118 changes: 59 additions & 59 deletions neclib/defaults/NANTEN2_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,21 @@ _ = "CPZ340816"
rsw_id = 0
channel = { sis_2L = 2, sis_2R = 1, sis_3L = 3, sis_3R = 4 } # The physical connection of Beam2 is like this. This is correct setting.
max_mv = [-16, 16]
converter = "x / 3"
converter = { sis_2L = "x / 3", sis_2R = "x / 3", sis_3L = "x / 3", sis_3R = "x / 3" }

[sis_bias_setter.board1]
_ = "CPZ340816"
rsw_id = 1
channel = { sis_4L = 1, sis_4R = 2, sis_5L = 3, sis_5R = 4 }
max_mv = [-16, 16]
converter = "x / 3"
converter = { sis_4L = "x / 3", sis_4R = "x / 3", sis_5L = "x / 3", sis_5R = "x / 3" }

[sis_bias_setter.board2]
_ = "CPZ340816"
rsw_id = 2
channel = { sis_1LU = 1, sis_1LL = 2, sis_1RU = 3, sis_1RL = 4 }
max_mv = [-16, 16]
converter = "x / 3"
converter = { sis_1LU = "x / 3", sis_1LL = "x / 3", sis_1RU = "x / 3", sis_1RL = "x / 3" }

[sis_bias_reader]
_ = "CPZ3177"
Expand All @@ -194,30 +194,30 @@ all_ch_num = 24
ch_range = '5V' # TODO: check! in the script
channel = { sis_2L_V = 3, sis_2L_I = 4, sis_2R_V = 1, sis_2R_I = 2, sis_3L_V = 5, sis_3L_I = 6, sis_3R_V = 7, sis_3R_I = 8, sis_4L_V = 9, sis_4L_I = 10, sis_4R_V = 11, sis_4R_I = 12, sis_5L_V = 13, sis_5L_I = 14, sis_5R_V = 15, sis_5R_I = 16, sis_1LU_V = 17, sis_1LU_I = 18, sis_1LL_V = 19, sis_1LL_I = 20, sis_1RU_V = 21, sis_1RU_I = 22, sis_1RL_V = 23, sis_1RL_I = 24 } # The physical connection of Beam2 is like this. This is correct setting.
converter = [
{ ch = "sis_2L_V", V = "x * 10" },
{ ch = "sis_2L_I", I = "x * 1000" },
{ ch = "sis_2R_V", V = "x * 10" },
{ ch = "sis_2R_I", I = "x * 1000" },
{ ch = "sis_3L_V", V = "x * 10" },
{ ch = "sis_3L_I", I = "x * 1000" },
{ ch = "sis_3R_V", V = "x * 10" },
{ ch = "sis_3R_I", I = "x * 1000" },
{ ch = "sis_4L_V", V = "x * 10" },
{ ch = "sis_4L_I", I = "x * 1000" },
{ ch = "sis_4R_V", V = "x * 10" },
{ ch = "sis_4R_I", I = "x * 1000" },
{ ch = "sis_5L_V", V = "x * 10" },
{ ch = "sis_5L_I", I = "x * 1000" },
{ ch = "sis_5R_V", V = "x * 10" },
{ ch = "sis_5R_I", I = "x * 1000" },
{ ch = "sis_1LU_V", V = "x * 10" },
{ ch = "sis_1LU_I", I = "x * 1000" },
{ ch = "sis_1LL_V", V = "x * 10" },
{ ch = "sis_1LL_I", I = "x * 1000" },
{ ch = "sis_1RU_V", V = "x * 10" },
{ ch = "sis_1RU_I", I = "x * 1000" },
{ ch = "sis_1RL_V", V = "x * 10" },
{ ch = "sis_1RL_I", I = "x * 1000" },
{ ch = "sis_2L_V", func = "x * 10", units = "mV" },
{ ch = "sis_2L_I", func = "x * 1000", units = "uA" },
{ ch = "sis_2R_V", func = "x * 10", units = "mV" },
{ ch = "sis_2R_I", func = "x * 1000", units = "uA" },
{ ch = "sis_3L_V", func = "x * 10", units = "mV" },
{ ch = "sis_3L_I", func = "x * 1000", units = "uA" },
{ ch = "sis_3R_V", func = "x * 10", units = "mV" },
{ ch = "sis_3R_I", func = "x * 1000", units = "uA" },
{ ch = "sis_4L_V", func = "x * 10", units = "mV" },
{ ch = "sis_4L_I", func = "x * 1000", units = "uA" },
{ ch = "sis_4R_V", func = "x * 10", units = "mV" },
{ ch = "sis_4R_I", func = "x * 1000", units = "uA" },
{ ch = "sis_5L_V", func = "x * 10", units = "mV" },
{ ch = "sis_5L_I", func = "x * 1000", units = "uA" },
{ ch = "sis_5R_V", func = "x * 10", units = "mV" },
{ ch = "sis_5R_I", func = "x * 1000", units = "uA" },
{ ch = "sis_1LU_V", func = "x * 10", units = "mV" },
{ ch = "sis_1LU_I", func = "x * 1000", units = "uA" },
{ ch = "sis_1LL_V", func = "x * 10", units = "mV" },
{ ch = "sis_1LL_I", func = "x * 1000", units = "uA" },
{ ch = "sis_1RU_V", func = "x * 10", units = "mV" },
{ ch = "sis_1RU_I", func = "x * 1000", units = "uA" },
{ ch = "sis_1RL_V", func = "x * 10", units = "mV" },
{ ch = "sis_1RL_I", func = "x * 1000", units = "uA" },
]

[hemt_bias_reader]
Expand All @@ -230,38 +230,38 @@ all_ch_num = 32
ch_range = '5V' # TODO: check! in the script
channel = { hemt_2L_Vdr = 1, hemt_2L_Vg1 = 2, hemt_2L_Vg2 = 3, hemt_2L_Id = 4, hemt_2R_Vdr = 5, hemt_2R_Vg1 = 6, hemt_2R_Vg2 = 7, hemt_2R_Id = 8, hemt_3L_Vdr = 9, hemt_3L_Vg1 = 10, hemt_3L_Vg2 = 11, hemt_3L_Id = 12, hemt_3R_Vdr = 13, hemt_3R_Vg1 = 14, hemt_3R_Vg2 = 15, hemt_3R_Id = 16, hemt_4L_Vdr = 17, hemt_4L_Vg1 = 18, hemt_4L_Vg2 = 19, hemr_4L_Id = 20, hemt_4R_Vdr = 21, hemt_4R_Vg1 = 22, hemt_4R_Vg2 = 23, hemt_4R_Id = 24, hemt_5L_Vdr = 25, hemt_5L_Vg1 = 26, hemt_5L_Vg2 = 27, hemt_5L_Id = 28, hemt_5R_Vdr = 29, hemt_5R_Vg1 = 30, hemt_5R_Vg2 = 31, hemt_5R_Id = 32 }
converter = [
{ ch = "hemt_2L_Vdr", V = "x" },
{ ch = "hemt_2L_Vg1", V = "x" },
{ ch = "hemt_2L_Vg2", V = "x" },
{ ch = "hemt_2L_Id", I = "10000 * x" },
{ ch = "hemt_2R_Vdr", V = "x" },
{ ch = "hemt_2R_Vg1", V = "x" },
{ ch = "hemt_2R_Vg2", V = "x" },
{ ch = "hemt_2R_Id", I = "10000 * x" },
{ ch = "hemt_3L_Vdr", V = "x" },
{ ch = "hemt_3L_Vg1", V = "x" },
{ ch = "hemt_3L_Vg2", V = "x" },
{ ch = "hemt_3L_Id", I = "10000 * x" },
{ ch = "hemt_3R_Vdr", V = "x" },
{ ch = "hemt_3R_Vg1", V = "x" },
{ ch = "hemt_3R_Vg2", V = "x" },
{ ch = "hemt_3R_Id", I = "10000 * x" },
{ ch = "hemt_4L_Vdr", V = "x" },
{ ch = "hemt_4L_Vg1", V = "x" },
{ ch = "hemt_4L_Vg2", V = "x" },
{ ch = "hemt_4L_Id", I = "10000 * x" },
{ ch = "hemt_4R_Vdr", V = "x" },
{ ch = "hemt_4R_Vg1", V = "x" },
{ ch = "hemt_4R_Vg2", V = "x" },
{ ch = "hemt_4R_Id", I = "10000 * x" },
{ ch = "hemt_5L_Vdr", V = "x" },
{ ch = "hemt_5L_Vg1", V = "x" },
{ ch = "hemt_5L_Vg2", V = "x" },
{ ch = "hemt_5L_Id", I = "10000 * x" },
{ ch = "hemt_5R_Vdr", V = "x" },
{ ch = "hemt_5R_Vg1", V = "x" },
{ ch = "hemt_5R_Vg2", V = "x" },
{ ch = "hemt_5R_Id", I = "10000 * x" },
{ ch = "hemt_2L_Vdr", func = "x", units = "V" },
{ ch = "hemt_2L_Vg1", func = "x", units = "V" },
{ ch = "hemt_2L_Vg2", func = "x", units = "V" },
{ ch = "hemt_2L_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_2R_Vdr", func = "x", units = "V" },
{ ch = "hemt_2R_Vg1", func = "x", units = "V" },
{ ch = "hemt_2R_Vg2", func = "x", units = "V" },
{ ch = "hemt_2R_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_3L_Vdr", func = "x", units = "V" },
{ ch = "hemt_3L_Vg1", func = "x", units = "V" },
{ ch = "hemt_3L_Vg2", func = "x", units = "V" },
{ ch = "hemt_3L_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_3R_Vdr", func = "x", units = "V" },
{ ch = "hemt_3R_Vg1", func = "x", units = "V" },
{ ch = "hemt_3R_Vg2", func = "x", units = "V" },
{ ch = "hemt_3R_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_4L_Vdr", func = "x", units = "V" },
{ ch = "hemt_4L_Vg1", func = "x", units = "V" },
{ ch = "hemt_4L_Vg2", func = "x", units = "V" },
{ ch = "hemt_4L_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_4R_Vdr", func = "x", units = "V" },
{ ch = "hemt_4R_Vg1", func = "x", units = "V" },
{ ch = "hemt_4R_Vg2", func = "x", units = "V" },
{ ch = "hemt_4R_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_5L_Vdr", func = "x", units = "V" },
{ ch = "hemt_5L_Vg1", func = "x", units = "V" },
{ ch = "hemt_5L_Vg2", func = "x", units = "V" },
{ ch = "hemt_5L_Id", func = "10000 * x", units = "mA" },
{ ch = "hemt_5R_Vdr", func = "x", units = "V" },
{ ch = "hemt_5R_Vg1", func = "x", units = "V" },
{ ch = "hemt_5R_Vg2", func = "x", units = "V" },
{ ch = "hemt_5R_Id", func = "10000 * x", units = "mA" },
]

[spectrometer.xffts]
Expand Down
22 changes: 10 additions & 12 deletions neclib/defaults/OMU1p85m_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,25 @@ _ = "CPZ340816"
rsw_id = 0
channel = { USB = 3, LSB = 4 }
max_mv = [-8, 8]
converter = "x / 3"
converter = {USB = "x / 3", LSB = "x/3"}

[sis_bias_reader]
_ = "CPZ3177"
rsw_id = 0
ave_num = 100
smpl_freq = 1000
single_diff = "DIFF"
all_ch_num = 10
all_ch_num = 8
ch_range = '5V'
channel = { hemt_ch1_Vdr = 1, hemt_ch1_Vg1 = 2, hemt_ch1_Vg2 = 3, sis_USB_V = 5, sis_LSB_V = 7, sis_USB_I = 6, sis_LSB_I = 8, sis_USB_P = 9, sis_LSB_P = 10 }
channel = { hemt_ch1_Vdr = 1, hemt_ch1_Vg1 = 2, hemt_ch1_Vg2 = 3, sis_USB_V = 5, sis_LSB_V = 7, sis_USB_I = 6, sis_LSB_I = 8}
converter = [
{ ch = "hemt_ch1_Vdr", V = "x" },
{ ch = "hemt_ch1_Vg1", V = "x" },
{ ch = "hemt_ch1_Vg2", V = "x" },
{ ch = "sis_USB_V", V = "x * 5" },
{ ch = "sis_USB_I", I = "x * 500" },
{ ch = "sis_LSB_V", V = "x * 5" },
{ ch = "sis_LSB_I", I = "x * 500" },
{ ch = "sis_USB_P", P = "x * 6 - 30" },
{ ch = "sis_LSB_P", P = "x * 6 - 30" },
{ ch = "hemt_ch1_Vdr", func = "x", units = "V" },
{ ch = "hemt_ch1_Vg1", func = "x", units = "V" },
{ ch = "hemt_ch1_Vg2", func = "x", units = "V" },
{ ch = "sis_USB_V", func = "x * 5", units = "mV" },
{ ch = "sis_USB_I", func = "x * 500", units = "uA" },
{ ch = "sis_LSB_V", func = "x * 5", units = "mV" },
{ ch = "sis_LSB_I", func = "x * 500", units = "uA" },
]

[hemt_bias_reader]
Expand Down
22 changes: 10 additions & 12 deletions neclib/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,25 @@ _ = "CPZ340816"
rsw_id = 0
channel = { USB = 3, LSB = 4 }
max_mv = [-8, 8]
converter = "x / 3"
converter = {USB = "x / 3", LSB = "x / 3"}

[sis_bias_reader]
_ = "CPZ3177"
rsw_id = 0
ave_num = 100
smpl_freq = 1000
single_diff = "DIFF"
all_ch_num = 10
all_ch_num = 8
ch_range = '5V'
channel = { hemt_ch1_Vdr = 1, hemt_ch1_Vg1 = 2, hemt_ch1_Vg2 = 3, sis_USB_V = 5, sis_LSB_V = 7, sis_USB_I = 6, sis_LSB_I = 8, sis_USB_P = 9, sis_LSB_P = 10 }
channel = { hemt_ch1_Vdr = 1, hemt_ch1_Vg1 = 2, hemt_ch1_Vg2 = 3, sis_USB_V = 5, sis_LSB_V = 7, sis_USB_I = 6, sis_LSB_I = 8}
converter = [
{ ch = "hemt_ch1_Vdr", V = "x" },
{ ch = "hemt_ch1_Vg1", V = "x" },
{ ch = "hemt_ch1_Vg2", V = "x" },
{ ch = "sis_USB_V", V = "x * 5" },
{ ch = "sis_USB_I", I = "x * 500" },
{ ch = "sis_LSB_V", V = "x * 5" },
{ ch = "sis_LSB_I", I = "x * 500" },
{ ch = "sis_USB_P", P = "x * 6 - 30" },
{ ch = "sis_LSB_P", P = "x * 6 - 30" },
{ ch = "hemt_ch1_Vdr", func = "x", units = "V"},
{ ch = "hemt_ch1_Vg1", func = "x", units = "V" },
{ ch = "hemt_ch1_Vg2", func = "x", units = "V"},
{ ch = "sis_USB_V", func = "x * 5", units = "mV" },
{ ch = "sis_USB_I", func = "x * 500", units = "uA" },
{ ch = "sis_LSB_V", func = "x * 5", units = "mV" },
{ ch = "sis_LSB_I", func = "x * 500", units = "uA" },
]

[hemt_bias_reader]
Expand Down
4 changes: 2 additions & 2 deletions neclib/devices/ad_converter/ad_converter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class ADConverter(DeviceBase):
Model: str

@abstractmethod
def get_voltage(self, id: str) -> u.Quantity: ...
def get_all(self, target: str) -> dict: ...

@abstractmethod
def get_current(self, id: str) -> u.Quantity: ...
def get_from_id(self, id: str) -> u.Quantity: ...

@abstractmethod
def finalize(self) -> None: ...
37 changes: 20 additions & 17 deletions neclib/devices/ad_converter/cpz3177.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class CPZ3177(ADConverter):
converter : List[Dict[str, str]]
Functions to convert measured voltage to any parameter you want, in format
``{ch = str(channel id defined in ``channel``),
str(parameter_type) = str(function)}``.
Supported``parameter_types`` are ["V", "I", "P"], and ``x`` in ``function``
str(parameter_type) = str(function), units = str(units of read value)}``.
Supported``parameter_types`` are ["V", "I"], and ``x`` in ``function``
will be substituted by the measured value. This would be useful when measured
voltage is scaled and/or shifted version of physical parameter.
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self) -> None:
)
self.ad.start_sampling("ASYNC")

def get_data(self, ch: int) -> List[float]:
def get_data(self) -> List[float]:
with busy(self, "busy"):
offset = self.ad.get_status()["smpl_count"] - self.ave_num
data = self.ad.read_sampling_buffer(self.ave_num, offset)
Expand All @@ -122,32 +122,35 @@ def get_data(self, ch: int) -> List[float]:
for data in data_li_2:
d = sum(data) / self.ave_num
ave_data_li.append(d)
return ave_data_li[ch - 1]
return ave_data_li

@property
def converter(self) -> Dict[str, Callable[[float], float]]:
conv = []
for i in self.Config.converter:
_ = [sanitize(expr, "x") for k, expr in i.items() if k != "ch"]
_ = [sanitize(expr, "x") for k, expr in i.items() if k == "func"]
conv.append(
{k: v if k == "ch" else eval(f"lambda x: {v}") for k, v in i.items()}
{k: v if k != "func" else eval(f"lambda x: {v}") for k, v in i.items()}
)
return conv

def get_voltage(self, id: str) -> u.Quantity:
ch = self.Config.channel[id]
li_search = list(filter(lambda item: item["ch"] == id, self.converter))[0]
return li_search["V"](self.get_data(ch)) * u.mV

def get_current(self, id: str) -> u.Quantity:
ch = self.Config.channel[id]
li_search = list(filter(lambda item: item["ch"] == id, self.converter))[0]
return li_search["I"](self.get_data(ch)) * u.microampere
def get_all(self, target: str) -> dict:
data = self.get_data()
data_dict = {}
filtered_conv = list(
filter(lambda item: item["ch"].startswith(target), self.converter)
)
for i in filtered_conv:
ch = self.Config.channel[i["ch"]]
value = i["func"](data[ch - 1])
data_dict[i["ch"]] = u.Quantity(value, i["units"])
return data_dict

def get_power(self, id: str) -> u.Quantity:
def get_from_id(self, id: str) -> u.Quantity:
ch = self.Config.channel[id]
li_search = list(filter(lambda item: item["ch"] == id, self.converter))[0]
return li_search["P"](self.get_data(ch)) * u.mW
value = li_search["func"](self.get_data()[ch - 1])
return u.Quantity(value, li_search["units"])

def finalize(self) -> None:
self.ad.stop_sampling()
4 changes: 2 additions & 2 deletions neclib/devices/ad_converter/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ADConverterSimulator(ADConverter):
def __init__(self) -> None:
self._rand = Random().walk(-16, 0.1, -1)

def get_voltage(self, id: str) -> u.Quantity:
def get_all(self, target: str) -> dict:
raise NotImplementedError

def get_current(self, id: str) -> u.Quantity:
def get_from_id(self, id: str) -> u.Quantity:
raise NotImplementedError

def finalize(self) -> None:
Expand Down
15 changes: 10 additions & 5 deletions neclib/devices/da_converter/cpz340816.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class CPZ340816(DAConverter):
check weather the set value is in this range in every "voltage setting”.
The unit of this value is mV.
converter : str
Function to convert setting voltage to any parameter you want.
converter : Dict[str]
Function to convert setting voltage to any parameter you want, , in format
``{ch = str(channel id defined in ``channel``),
str(parameter_type) = str(function)}``.
Supported ``x`` in function will be substituted by the setting value.
This would be useful when setting voltage is scaled and/or
shifted version of physical parameter.
Expand All @@ -52,8 +54,11 @@ def __init__(self):

@property
def converter(self) -> Callable[[Union[int, float]], float]:
sanitize(self.Config.converter, "x")
return eval(f"lambda x: {self.Config.converter}")
conv = {}
for k, v in self.Config.converter.items():
_ = sanitize(v, "x")
conv[k] = eval(f"lambda x: {v}")
return conv

def set_voltage(self, mV: float, id: str) -> None:
ch = self.Config.channel[id]
Expand All @@ -62,7 +67,7 @@ def set_voltage(self, mV: float, id: str) -> None:
if not self.Config.max_mv[0] < mV < self.Config.max_mv[1]:
raise ValueError(f"Unsafe voltage {mV} mV")
else:
self.param_buff[ch] = self.converter(mV)
self.param_buff[ch] = self.converter[id](mV)

def apply_voltage(self) -> None:
with busy(self, "busy"):
Expand Down

0 comments on commit eba598c

Please sign in to comment.