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

c_norm & sc_off tracking, optional base_dir to allow load if differen… #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rsonka
Copy link
Contributor

@rsonka rsonka commented Jun 11, 2022

Added saving (during analyze_iv()) of c_norm (phase offset constant) & sc_off (superconducting offset) to IVAnalysis (and documented them). Set _load_am() to automatically initialize those arrays in the class if they didn't. (I'm assuming I don't need to do anything special for axis manager with those?).

Added an optional argument base_dir to _load_am() to allow loading of IVAnalysis save files if sodetlib is run on a different timestream directory structure, so that I could test my code on Princeton's dedicated analysis computer.

I also did a few minor aesthetic improvements by lining up = signs with spaces.

@rsonka rsonka requested review from jlashner and dpdutcher June 11, 2022 16:31
Copy link
Collaborator

@jlashner jlashner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Rita, thanks for this! Looks mostly good, but I have a few small comments inline.

Also I appreciate the formatting changes, however technically it's against pep8 formatting rules and I think we should change it back. I agree that in some cases it does look better, but this kind of thing is difficult to maintain, since you'll have to change the alignment for a bunch of lines whenever a longer variable is added.

Comment on lines 64 to 67
c_norm : np.ndarray
Array of shape (nchans) containing the (contextless) determination of
the proper phase offset correction
sc_off : np.ndarray
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the addition of these fields, however the names aren't so intuitive to me. Do you think we can rename them to something like normal_offset and sc_offset, and maybe add something like "y-intercept of the normal/superconducting branches in the raw data", since I'm not sure if that's clear just from the term "offset".

Also do you think we can specify units here? You say "phase" but I think the units might be amps.

Copy link
Contributor Author

@rsonka rsonka Jun 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thanks for the detailed and useful review!

Also I appreciate the formatting changes, however technically it's against pep8 formatting rules and I think we should change it back.

Okay, will do. I didn't know we were following pep8 formatting rules (I've mostly been following the style guide I was taught in college; I now wonder why they didn't tell me about pep8, seeing as it predated that class.). Perhaps add that to the Github main page so future contributors aren't surprised by it?

this kind of thing is difficult to maintain, since you'll have to change the alignment for a bunch of lines whenever a longer variable is added.

My python instructor might have taught us this way because he was a fan of vim/emacs, which makes that much easier to change.

Do you think we can rename them to something like normal_offset and sc_offset, and maybe add something like "y-intercept of the normal/superconducting branches in the raw data", since I'm not sure if that's clear just from the term "offset".

c_norm stands for "constant of normal branch fit", as opposed to s_norm, "slope of normal branch fit." I agree that your names are improvements individually (and am a bit embarrassed I didn't make better names myself.). However given that sc_offset is only an offset of the superconducting branch, I'm not keen on using "normal_offset" for an offset applied to the entire response (though it is nice in implying where it comes from). "i_tes_offset" might be better in that vein (especially paired with your proposed i_tes vs. resp idea below)?

Also do you think we can specify units here? You say "phase" but I think the units might be amps.

I'm not a SQUID readout expert, but by my understanding: the original Resp is a measure of difference in the recorded phase from when you start taking data, and the phase offset correction (the normal branch offset) is the final step in converting them to amps (In fact, it's common for resp to be very negative before that correction is performed, which is unphysical given how we measure). The fact that we're measuring in phase difference is why we have to do the phase offset correction in the first place. However, it's true that we do it after we do this:

A_per_rad = iva.meta['pA_per_phi0'] / (2*np.pi) * 1e-12
iva.resp = (iva.resp.T * iva.polarity).T * A_per_rad

...and I support doing it in that location. So...I see what you mean in that it's closer to being Amps than it is to being phase. I guess it would be better to call it "[proto-Amps]" or something (similarly for resp in your proposed i_tes vs. resp idea below, which I approve of).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm going to peruse PEP8, so it might be a bit before I actually implement these changes and respond to the rest of your review.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I decided o work on this before finishing pep8. I've performed several updates to the original comment after reviewing things more.

Comment on lines 59 to 63
Array of shape (nchans, nbiases) containing the squid response
at each bias point, with the sc_off and contextless c_norm corrections
applied to (hopefully accurately) convert it to actual [Amps].
That is, it's the original squid response phase data -contextless
c_norm everywhere and -sc_off in [:sc_idx].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking a bit about this and realized that resp and i_tes are currently exactly the same. This may have been what you were suggesting before, but if you want we can have it so resp does not have the offsets subtracted out, while i_tes does. Up to you if you want to make those changes here.

Anyway, I think this docstring is definitely correct, but kind of technical, like it's hard to understand just reading it without knowing what the code is doing. Do you think we can change so it's a bit less technical? Maybe something like

offsets are subtracted from the full IV and the superconducting branch so that the superconducting 
and normal branches both have a y-intercept of 0.

Comment on lines +188 to +192
# check for if the file contains the attributes added after version 1.
# initialize any that are missing so analyze_iv doesn't crash.
for attr_name in ['c_norm','sc_off']:
if not hasattr(self, attr_name):
setattr(self, attr_name, np.full((self.nchans, ), np.nan))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might make a bit more sense to put this in the load function instead of _load_am

@msilvafe
Copy link
Contributor

msilvafe commented Jan 5, 2024

Hi @rsonka, @jlashner and I are trying to do a new year's cleaning up of open PRs in sodetlib. Would you be able to give us an idea of when you could make the requested changes so we can merge this PR? Let us know if we can help.

For PEP8 formatting you can use a linter (such as pylint) in whatever IDE you use (I use one in vim and vscode), it'll check the pep8 format and tell you how to fix it. While reading the PEP8 manual is not a bad idea a linter is probably an easier path to getting the formatting changes here fixed. Thanks again for these contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants