DC-analysis / dclab

Python library for the post-measurement analysis of real-time deformability cytometry (RT-DC) data sets
https://dclab.readthedocs.io
Other
10 stars 12 forks source link

Unknown medium name causes error when exporting a dataset #215

Closed B-Hartmann closed 1 year ago

B-Hartmann commented 1 year ago

dclab 0.48.2 Python 3.10.4

I used 1 % MC-PBS in a measurement and also put this information in Shape-In in the respective field for medium by selecting "user defined" in the drop-down menu and entering "1.0 MC-PBS" in the text box.

I now wanted to calculate the Young's modulus for the data and then export it together with some temporary features and used the following code:

ds = dclab.new_dataset("file.rtdc")
ds.config["calculation"]["emodulus lut"] = "LE-2D-FEM-19"
ds.config["calculation"]["emodulus viscosity"] = 21.1457

# some other stuff
ds.export.hdf5(path=path, features=export_features)

I then got an error message saying

ValueError: Only the following media are supported:
['0.49% MC-PBS', '0.49% mc-pbs', '0.5% MC-PBS', '0.5% mc-pbs', '0.50% MC-PBS', '0.50% mc-pbs', '0.59% MC-PBS',
'0.59% mc-pbs', '0.6% MC-PBS', '0.6% mc-pbs', '0.60% MC-PBS', '0.60% mc-pbs', '0.8% MC-PBS', '0.8% mc-pbs',
'0.80% MC-PBS', '0.80% mc-pbs', '0.83% MC-PBS', '0.83% mc-pbs', 'CellCarrier', 'CellCarrier B',
'CellCarrierB', 'cellcarrier', 'cellcarrier b', 'cellcarrierb', 'water'],
got '1.0 mc-pbs'!
File ~\.environments\tracking\lib\site-packages\dclab\rtdc_dataset\export.py:249, in Export.hdf5(self, path, features, filtered, logs, override, compression_kwargs, compression, skip_checks)
    247             lengths.append(len(self.rtdc_ds["trace"][tr]))
    248     else:
--> 249         lengths.append(len(self.rtdc_ds[feat]))
    250 lmin = np.min(lengths)
    251 lmax = np.max(lengths)

File ~\.environments\tracking\lib\site-packages\dclab\rtdc_dataset\core.py:107, in RTDCBase.__getitem__(self, key)
    104     data = self._ancillaries[key][1]
    105 else:
    106     # Compute new value
--> 107     data_dict = ancol[key].compute(self)
    108     for okey in data_dict:
    109         # Store computed value in `self._ancillaries`.
    110         self._ancillaries[okey] = (anhash, data_dict[okey])

File ~\.environments\tracking\lib\site-packages\dclab\rtdc_dataset\feat_anc_core\ancillary_feature.py:220, in AncillaryFeature.compute(self, rtdc_ds)
    205 def compute(self, rtdc_ds):
    206     """Compute the feature with self.method. All ancillary features that
    207     share the same method will also be populated automatically.
    208 
   (...)
    218         computed data features (read-only) as values.
    219     """
--> 220     data_dict = self.method(rtdc_ds)
    221     if not isinstance(data_dict, dict):
    222         data_dict = {self.feature_name: data_dict}

File ~\.environments\tracking\lib\site-packages\dclab\rtdc_dataset\feat_anc_core\af_emodulus.py:34, in compute_emodulus(mm)
     31     raise ValueError(
     32         f"'emodulus medium' must be a string, got '{medium}'!")
     33 if medium not in features.emodulus.viscosity.KNOWN_MEDIA:
---> 34     raise ValueError(
     35         f"Only the following media are supported: "
     36         f"{features.emodulus.viscosity.KNOWN_MEDIA}, got '{medium}'!")
     37 if viscosity is not None:
     38     raise ValueError("You must not set the 'emodulus viscosity' "
     39                      "configuration keyword for known media!")

ValueError: Only the following media are supported: ['0.49% MC-PBS', '0.49% mc-pbs', '0.5% MC-PBS', '0.5% mc-pbs', '0.50% MC-PBS', '0.50% mc-pbs', '0.59% MC-PBS', '0.59% mc-pbs', '0.6% MC-PBS', '0.6% mc-pbs', '0.60% MC-PBS', '0.60% mc-pbs', '0.8% MC-PBS', '0.8% mc-pbs', '0.80% MC-PBS', '0.80% mc-pbs', '0.83% MC-PBS', '0.83% mc-pbs', 'CellCarrier', 'CellCarrier B', 'CellCarrierB', 'cellcarrier', 'cellcarrier b', 'cellcarrierb', 'water'], got '1.0 mc-pbs'!

Does this mean dclab cannot calculate the E modulus with an unknown medium name?

paulmueller commented 1 year ago

That means that dclab does not know this medium and thus cannot compute the viscosity which is required for computing the Young's modulus.

Is the 1% MC-PBS the same as the 0.83% MC-PBS? The 0.83% is the actual number computed from the protocol. If people normally refer to 0.83% MC-PBS as 1.0% MC-PBS, then I can add that as an alias to dclab.

@felix-r might be able to answer my question.

B-Hartmann commented 1 year ago

No, it is really with 1 % methylcellulose. It might be that I made a mistake because I loop over several files and load several files per iteration. I will check again and then come back to you.

paulmueller commented 1 year ago

Sorry, I just reread your original post. This error should not happen when you specify "lut" and "viscosity" in this way. dclab should just take the viscosity you specified. The error puzzles me, because you did not specify "emodulus medium". But maybe the reason for that is what you wrote in your latest post. Let me know what you find out.

B-Hartmann commented 1 year ago

I did make a mistake and tried to compute the E modulus using the custom medium name. I am sorry for the confusion!