From e0a0d09bd4a03fca9fb2711edb8fc64150297ee4 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 23 Aug 2023 15:47:44 +0200 Subject: [PATCH] function mbp.normalize() now only normalizes available columns --- src/conda_helpers/mbp.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/conda_helpers/mbp.py b/src/conda_helpers/mbp.py index 3b68c42..2598970 100644 --- a/src/conda_helpers/mbp.py +++ b/src/conda_helpers/mbp.py @@ -1,3 +1,5 @@ +import contextlib + import pandas as pd from sensospot_tools import ( normalize as normalize_xdr_data, @@ -7,10 +9,15 @@ from sensospot_tools import ( split, ) +# column names + EXPOSURE_ID = "Exposure.Id" EXPOSURE_CHANNEL = "Exposure.Channel" EXPOSURE_TIME = "Exposure.Time" EXPOSURE_TIME_NORMALIZED = "Exposure.Time.Normalized" +NET_SIGNAL = "NetSignal" +SPOT_SATURATION = "Spot.Saturation" +TEST_OVERFLOW = "Test.Spot.Overflow" EXPOSURE_COLUMNS = [ EXPOSURE_ID, @@ -19,11 +26,6 @@ EXPOSURE_COLUMNS = [ EXPOSURE_TIME_NORMALIZED, ] -SATURATION_LIMIT = 2 -SPOT_SATURATION = "Spot.Saturation" - -TEST_OVERFLOW = "Test.Spot.Overflow" - SPOT_ID_COLUMNS = ["Analysis.Name", "Well.Name", "Pos.Id"] TIME_DEPENDENT_COLUMNS = [ @@ -37,6 +39,8 @@ TIME_DEPENDENT_COLUMNS = [ "Spot.Sum", ] +SATURATION_LIMIT = 2 + def add_exposure_info(data: pd.DataFrame, analysis="hyb") -> pd.DataFrame: time_cy3 = 100 if "1" in analysis else 200 @@ -61,7 +65,7 @@ def normalize(raw_data: pd.DataFrame, analysis="hyb"): _normalize_channel(data) for _, data in split(overflow_tested, EXPOSURE_CHANNEL) ) - return pd.concat(normalized_data).reset_index() + return pd.concat(normalized_data).reset_index(drop=True) def _normalize_channel(data: pd.DataFrame) -> pd.DataFrame: @@ -72,10 +76,17 @@ def _normalize_channel(data: pd.DataFrame) -> pd.DataFrame: available_columns = [ c for c in hdr_data.columns if c in TIME_DEPENDENT_COLUMNS ] - return normalize_xdr_data( + normalized = normalize_xdr_data( hdr_data, normalized_time, EXPOSURE_TIME, available_columns, "{}.Normalized", ) + with contextlib.suppress(KeyError): + normalized[NET_SIGNAL] = ( + normalized["Spot.Mean.Normalized"] + - normalized["Bkg.Median.Normalized"] + ) + + return normalized