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

add calibration #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add calibration #2

wants to merge 1 commit into from

Conversation

azulaynofar
Copy link

No description provided.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Collaborator

@ackagel ackagel left a comment

Choose a reason for hiding this comment

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

Looks great, great first PR! Just a few notes notes on format.

Comment on lines +66 to +69
a, b = symbols('a b')
eq1 = Eq((((t1 * time_res - b)/a) ** 2 - m1) , 0)
eq2 = Eq((((t2 * time_res - b)/a) ** 2 - m2) , 0)
sol = solve((eq1 , eq2) , (a , b))
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there not a reliable closed form solution for this? The expression

equation

only has 4 solutions, and I think the "correct" one would be fairly consistent if similar calibration parameters are applied from usage to usage.

Open to opinions on that of course

Copy link
Author

Choose a reason for hiding this comment

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

yes I agree. tbh I related on leeat's previous code and didn't solve it myself. would you be ok with selecting the solution that is the closes to the current calibration? something like that:
def calibrate_spectrum(t1 , m1 , t2 , m2 , mass_gain , mass_offset, time_res: float=500e-6):
sign1 = np.array([1 , 1 , -1 , -1])
sign2 = np.array([1 , -1 , 1 , -1])
a = (t1 - t2) * t_res / (sign1 * np.sqrt(m1) + sign2 * np.sqrt(m2))
b = (sign1 * np.sqrt(m2) * t1 + sign2 * np.sqrt(m1) * t2) * t_res / (sign1 * np.sqrt(m2) + sign2 * np.sqrt(m1))
idx = np.argmin((a - mass_gain) ** 2 + (b - mass_offset) ** 2)
return a[idx] , b[idx]

Comment on lines +52 to +53
def get_spectra_df(TimeOffset):
data = collections.Counter(TimeOffset)
Copy link
Collaborator

Choose a reason for hiding this comment

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

TimeOffset -> time_offset, just for syntax consistency. Also, I'm adding some docstrings to some of the other functions. Those might already be merged in (can't remember at the moment tbh), but either way, some docstrings here would be handy. For example:

def get_spectra_df(time_offset):
    """Creates formatted pandas dataframe from spectra data

    Args:
        time_offset (type_of_time_offset (e.g dict, list, etc)):
            time offsets
    Returns:
        pd.DataFrame:
            count spectra
    """
    # rest of function

Copy link
Author

Choose a reason for hiding this comment

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

sure I'll add them now

def extract_bin_files(data_dir: str, out_dir: str,
include_fovs: Union[List[str], None] = None,
panel: Union[Tuple[float, float], pd.DataFrame] = (-0.3, 0.0),
intensities: Union[bool, List[str]] = False, time_res: float=500e-6,
timeout=100):
timeout=100 , calibration: Union[Tuple[float, float], str] = 'auto'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice! thanks for adding the type signature and giving it a default arg!

@alex-l-kong
Copy link
Contributor

@azulaynofar @ngreenwald any plans on continuing development of this PR?

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