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

Coerce mef.get_transform_fxn input to permit None values #331

Merged
merged 1 commit into from Jun 13, 2020
Merged

Coerce mef.get_transform_fxn input to permit None values #331

merged 1 commit into from Jun 13, 2020

Conversation

JS3xton
Copy link
Contributor

@JS3xton JS3xton commented May 11, 2020

Coerce mef_values input to mef.get_transform_fxn() to be a numpy array of floats. This coercion converts None values to np.nan, thereby permitting None as a synonym for np.nan. The coercion also eliminated the need for some type checking, as numpy now throws an error if the inner arrays don't have the same length.

Closes #214.

All unit tests pass before (9cd83ef) and after (7be7ffa) the change in Python 3.8 + Anaconda 2020.02 and Python 2.7 + Anaconda 4.4.0.

The following code failed previously at the last line and is fixed by the change:

import numpy as np
import FlowCal as fc
beads_sample = fc.io.FCSData('./examples/FCFiles/Beads006.fcs')
beads_sample = fc.transform.to_rfi(beads_sample, ['FSC','SSC','FL1','FL2','FL3'])
beads_sample = fc.gate.start_end(beads_sample, 250, 100)
beads_sample = fc.gate.high_low(beads_sample, channels=['FSC','SSC'])
beads_sample = fc.gate.density2d(data=beads_sample, channels=['FSC','SSC'], gate_fraction=0.85, xscale='logicle', yscale='logicle', sigma=5.)

mef_values   = [0, 646, 1704, 4827, 15991, 47609, 135896, 273006]
mef_output   = fc.mef.get_transform_fxn(beads_sample, mef_values, mef_channels='FL1', clustering_channels=['FL1', 'FL3'], plot=False)

mef_values   = [0, 646, 1704, 4827, 15991, 47609, 135896, np.nan]
mef_output   = fc.mef.get_transform_fxn(beads_sample, mef_values, mef_channels='FL1', clustering_channels=['FL1', 'FL3'], plot=False)

mef_values   = [0, 646, 1704, 4827, 15991, 47609, 135896, None]
mef_output   = fc.mef.get_transform_fxn(beads_sample, mef_values, mef_channels='FL1', clustering_channels=['FL1', 'FL3'], plot=False)

NOTE: I first tried using pd.isnull in place of np.isnan, but fit_beads_autofluorescence() would fail later in err_fun(). pd.isnull checks for other null types (like None) in addition to np.nan. I think the failure occurred because mef_values=[0,...,None] later yields an object array instead of a numerical array. As such, I decided to just ensure mef_values was a numerical (float) array from the outset.

Coerce `mef_values` input to mef.get_transform_fxn to be a numpy
array of floats. This coercion converts None values to np.nan,
thereby permitting None values as synonym for np.nan. The coercion
also eliminated the need for some type checking.
@JS3xton JS3xton requested a review from castillohair May 11, 2020 17:15
@castillohair castillohair merged commit c4657ae into taborlab:develop Jun 13, 2020
@JS3xton JS3xton deleted the none-mef-values branch June 14, 2020 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants