Esempio n. 1
0
 def test_calculate_msd(self):
     track = Track.from_dict(TRACK_DATA['track'])
     track.calculate_msd()
     self.assertTrue(track.is_msd_calculated())
     self.assertTrue(np.isclose(track.get_msd(), TRACK_DATA['msd']).all())
     self.assertTrue(
         np.isclose(track.get_msd_error(), TRACK_DATA['msd_error']).all())
Esempio n. 2
0
    def load_track(self,
                   filename: str,
                   id=None,
                   unit_length=None,
                   unit_time=None,
                   col_names=None):
        if unit_length is None or unit_time is None or col_names is None:
            unit_length, unit_time, col_names = self.show_import_dialog(
                pd.read_csv(filename).columns)
            if unit_length is None or unit_time is None or col_names is None:
                return
        try:
            self.track = Track.from_file(filename,
                                         id=id,
                                         unit_length=unit_length,
                                         unit_time=unit_time,
                                         col_name_x=col_names[0],
                                         col_name_y=col_names[1],
                                         col_name_t=col_names[2],
                                         col_name_id=col_names[3]).normalized(
                                             normalize_t=True,
                                             normalize_xy=False)
        except LoadTrackMissingIdError:
            id = self.show_trackid_dialog()
            if id is None:
                return
            self.load_track(filename=filename,
                            id=id,
                            unit_length=unit_length,
                            unit_time=unit_time,
                            col_names=col_names)
        except LoadTrackIdNotFoundError:
            mb = QMessageBox()
            mb.setText("There is no track with that ID!")
            mb.setWindowTitle("Error")
            mb.setIcon(QMessageBox.Critical)
            mb.exec()
        except KeyError as e:
            mb = QMessageBox()
            mb.setText("Key not found: {}!".format(str(e)))
            mb.setWindowTitle("Error")
            mb.setIcon(QMessageBox.Critical)
            mb.exec()
        if self.track == None:
            return

        self.sigTrackLoaded.emit()

        self.statusbar.showMessage("Loaded track of length {}".format(
            self.track.get_size()))
Esempio n. 3
0
import numpy as np


class ModelBrownian(ModelBase):
    lower = [0.0, 0.0]
    upper = [np.inf, np.inf]
    initial = [0.5e-12, 2.0e-9]

    def __call__(self, t, D, delta):
        return D + delta**2 / (2 * t * (1 - 2 * self.R * self.dt / t))


# %%
# After we've defined the model, we can simply add it to the :class:`trait2d.analysis.ModelDB`.

from trait2d.analysis import ModelDB
ModelDB().add_model(ModelBrownian)

# %%
# We can now run ADC analysis with the model.

from trait2d.analysis import Track
track = Track.from_file("track1.csv", unit_length='micrometres')
track.adc_analysis(fraction_fit_points=0.15)
track.plot_adc_analysis_results()

# %%
# It is a good idea to use `ModelDB().cleanup()` at the end of your notebooks to remove all models again. Otherwise they may carry over into other open notebooks.

ModelDB().cleanup()
Esempio n. 4
0
from trait2d.analysis import ModelDB
from trait2d.analysis.models import ModelBrownian, ModelConfined, ModelHop

ModelDB().add_model(ModelBrownian)
ModelDB().add_model(ModelConfined)
ModelDB().add_model(ModelHop)

# %%
# Single tracks are stored in a ``Track`` object.

from trait2d.analysis import Track

# %%
# We can create a single track from our last simulation:

single_track = Track.from_dict(simulator_brownian.trajectory)

# %%
# We can now do ADC analysis on the track:

results = single_track.adc_analysis(fit_max_time=0.5e-1)

# %%
# Analysis results like the calculated values for :math:`D_{app}`, fit parameters and much more are returned in a dictionary. We can also retreive the dictionary of the last analysis at any time with ``get_adc_analysis_results``.

fit_results = results["fit_results"]
best_model = results["best_model"]
print(fit_results)
print(best_model)

single_track.plot_adc_analysis_results()
Esempio n. 5
0
 def test_msd_analysis(self):
     track = Track.from_dict(TRACK_DATA['track'])
     track.msd_analysis()
     self.assertTrue(track.get_msd_analysis_results() != None)
Esempio n. 6
0
 def test_from_dict(self):
     track = Track.from_dict(TRACK_DATA['track'])
     self.assertEqual(track.get_size(), len(TRACK_DATA['track']['x']))