How to use the pylinac.log_analyzer.Dynalog function in pylinac

To help you get started, we’ve selected a few pylinac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_dynalog(self):
        # test making an anonymized copy
        dlog_file = osp.join(ANONYMOUS_DEST_FOLDER, 'A1234_patientid.dlg')
        dlog = Dynalog(dlog_file)
        dlog.anonymize()

        # test doing inplace anonymization
        files = dlog.anonymize(inplace=True, suffix='inplace')
        for file in files:
            self.assertTrue('inplace' in file)
github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_bad_name(self):
        """Test that a log with a bad name (no underscore) fails gracefully."""
        dlog_file = osp.join(ANONYMOUS_DEST_FOLDER, 'A1234patientid.dlg')
        dlog = Dynalog(dlog_file)
        with self.assertRaises(NameError):
            dlog.anonymize()
github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_loading_bad_names(self):
        a_but_not_b_dir = osp.join(TEST_DIR, 'a_no_b_dir', 'Adlog1.dlg')
        self.assertRaises(DynalogMatchError, Dynalog, a_but_not_b_dir)

        b_but_not_a_dir = osp.join(TEST_DIR, 'b_no_a_dir', 'Bdlog1.dlg')
        self.assertRaises(DynalogMatchError, Dynalog, b_but_not_a_dir)

        bad_name_dlg = osp.join(TEST_DIR, 'bad_names', 'bad_name_dlg.dlg')
        self.assertRaises(ValueError, Dynalog, bad_name_dlg)
github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_loading_can_find_paired_file(self):
        # shouldn't raise since it can find B-file
        a_file = osp.join(TEST_DIR, 'dlogs', 'Adlog1.dlg')
        Dynalog(a_file)

        # ditto for A-file
        b_file = osp.join(TEST_DIR, 'dlogs', 'Bdlog1.dlg')
        Dynalog(b_file)
github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_loading_can_find_paired_file(self):
        # shouldn't raise since it can find B-file
        a_file = osp.join(TEST_DIR, 'dlogs', 'Adlog1.dlg')
        Dynalog(a_file)

        # ditto for A-file
        b_file = osp.join(TEST_DIR, 'dlogs', 'Bdlog1.dlg')
        Dynalog(b_file)
github jrkerns / pylinac / tests_basic / test_logs.py View on Github external
def test_loading_bad_names(self):
        a_but_not_b_dir = osp.join(TEST_DIR, 'a_no_b_dir', 'Adlog1.dlg')
        self.assertRaises(DynalogMatchError, Dynalog, a_but_not_b_dir)

        b_but_not_a_dir = osp.join(TEST_DIR, 'b_no_a_dir', 'Bdlog1.dlg')
        self.assertRaises(DynalogMatchError, Dynalog, b_but_not_a_dir)

        bad_name_dlg = osp.join(TEST_DIR, 'bad_names', 'bad_name_dlg.dlg')
        self.assertRaises(ValueError, Dynalog, bad_name_dlg)
github jrkerns / pylinac / pylinac / log_analyzer.py View on Github external
obj : str, Dynalog, TrajectoryLog
            If a string, must point to a log file.
            If a directory, must contain log files.
            If a Dynalog or Trajectory log instance, then simply appends.
        recursive : bool
            Whether to walk through subfolders of passed directory. Only applicable if obj was a directory.
        """
        if isinstance(obj, str):
            if is_log(obj):
                log = load_log(obj)
                super().append(log)
            elif osp.isdir(obj):
                files = io.retrieve_filenames(obj)
                for file in files:
                    self.append(file)
        elif isinstance(obj, (Dynalog, TrajectoryLog)):
            super().append(obj)
        else:
            raise TypeError("Can only append MachineLog or string pointing to a log or log directory.")
github jrkerns / pylinac / pylinac / log_analyzer.py View on Github external
Returns
    -------
    One of :class:`~pylinac.log_analyzer.Dynalog`, :class:`~pylinac.log_analyzer.TrajectoryLog`,
        :class:`~pylinac.log_analyzer.MachineLogs`.
    """
    if io.is_url(file_or_dir):
        file_or_dir = io.get_url(file_or_dir)
    if osp.isfile(file_or_dir):
        if io.is_zipfile(file_or_dir):
            return MachineLogs.from_zip(file_or_dir)
        if not is_log(file_or_dir):
            raise NotALogError("Not a valid log")
        elif is_tlog(file_or_dir):
            return TrajectoryLog(file_or_dir, exclude_beam_off)
        else:
            return Dynalog(file_or_dir, exclude_beam_off)
    elif osp.isdir(file_or_dir):
        return MachineLogs(file_or_dir, recursive)
    else:
        raise NotALogError(f"'{file_or_dir}' did not point to a valid file, directory, or ZIP archive")
github jrkerns / pylinac / pylinac / log_analyzer.py View on Github external
def num_dlogs(self):
        """The number of Trajectory logs currently loaded."""
        return sum(isinstance(log, Dynalog) for log in self)