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

Tes param corrections #438

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 17 additions & 8 deletions sodetlib/operations/bias_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import matplotlib.pyplot as plt
import scipy.optimize
from sodetlib.operations import iv
from typing import Dict, Any

np.seterr(all='ignore')

Expand Down Expand Up @@ -275,9 +276,9 @@ class BiasStepAnalysis:
I0 (array (float) shape (nchans)):
Computed TES currents for each channel (amps)
Pj (array (float) shape (nchans)):
Bias power computed for each channel
Bias power computed for each channel (W)
Si (array (float) shape (nchans)):
Responsivity computed for each channel
Responsivity computed for each channel (1/V)
step_fit_tmin (float):
Time after bias step to start fitting exponential (sec)
step_fit_popts (array (float) of shape (nchans, 3)):
Expand Down Expand Up @@ -313,7 +314,15 @@ def __init__(self, S=None, cfg=None, bgs=None, run_kwargs=None):
self.run_kwargs = run_kwargs
self.high_current_mode = run_kwargs.get("high_current_mode", True)

def save(self, path=None):

@classmethod
def from_dict(cls, data) -> 'BiasStepAnalysis':
self = cls()
for k, v in data.items():
setattr(self, k, v)
return self

def to_dict(self) -> Dict[str, Any]:
data = {}
saved_fields = [
# Run data and metadata
Expand All @@ -338,7 +347,10 @@ def save(self, path=None):
print(f"WARNING: field {f} does not exist... "
"defaulting to None")
data[f] = getattr(self, f, None)
return data

def save(self, path=None) -> None:
data = self.to_dict()
if path is not None:
np.save(path, data, allow_pickle=True)
self.filepath = path
Expand All @@ -349,11 +361,8 @@ def save(self, path=None):
)

@classmethod
def load(cls, filepath):
self = cls()
data = np.load(filepath, allow_pickle=True).item()
for k, v in data.items():
setattr(self, k, v)
def load(cls, filepath) -> 'BiasStepAnalysis':
self = cls.from_dict(np.load(filepath, allow_pickle=True).item())
self.filepath = filepath
return self

Expand Down
23 changes: 16 additions & 7 deletions sodetlib/operations/iv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from copy import deepcopy
from tqdm.auto import trange
from typing import Optional
from typing import Optional, Dict, Any
from dataclasses import dataclass, asdict

import warnings
Expand Down Expand Up @@ -106,7 +106,7 @@ class IVAnalysis:
current.
"""
def __init__(self, S=None, cfg=None, run_kwargs=None, sid=None,
start_times=None, stop_times=None):
start_times=None, stop_times=None) -> None:

self._S = S
self._cfg = cfg
Expand All @@ -130,6 +130,7 @@ def __init__(self, S=None, cfg=None, run_kwargs=None, sid=None,
self.channels = am.ch_info.channel
self.v_bias = np.full((self.nbiases, ), np.nan)
self.i_bias = np.full((self.nbiases, ), np.nan)
self.v_thevenin = np.full((self.nbiases, ), np.nan)
self.resp = np.full((self.nchans, self.nbiases), np.nan)
self.R = np.full((self.nchans, self.nbiases), np.nan)
self.p_tes = np.full((self.nchans, self.nbiases), np.nan)
Expand All @@ -145,16 +146,19 @@ def __init__(self, S=None, cfg=None, run_kwargs=None, sid=None,
self.bands, self.channels, self.meta['bgmap_file']
)

def save(self, path=None, update_cfg=False):
def to_dict(self):
saved_fields = [
'meta', 'bands', 'channels', 'sid', 'start_times', 'stop_times',
'run_kwargs', 'biases_cmd', 'bias_groups', 'nbiases', 'nchans',
'bgmap', 'polarity', 'resp', 'v_bias', 'i_bias', 'R', 'R_n', 'R_L',
'idxs', 'p_tes', 'v_tes', 'i_tes', 'p_sat', 'si',
'idxs', 'p_tes', 'v_tes', 'i_tes', 'p_sat', 'si', 'v_thevenin'
]
data = {
return {
field: getattr(self, field, None) for field in saved_fields
}

def save(self, path=None, update_cfg=False):
data = self.to_dict()
if path is not None:
np.save(path, data, allow_pickle=True)
else:
Expand All @@ -166,9 +170,9 @@ def save(self, path=None, update_cfg=False):
update_file=True)

@classmethod
def load(cls, path):
def from_dict(cls, data: Dict[str, Any]) -> 'IVAnalysis':
iva = cls()
for key, val in np.load(path, allow_pickle=True).item().items():
for key, val in data.items():
setattr(iva, key, val)

if len(iva.start_times) == 1:
Expand All @@ -180,6 +184,11 @@ def load(cls, path):

return iva

@classmethod
def load(cls, path) -> 'IVAnalysis':
return cls.from_dict(np.load(path, allow_pickle=True).item())


def _load_am(self, arc=None):
if self.am is None:
if arc:
Expand Down
Empty file added sodetlib/py.typed
Empty file.
Loading
Loading