|
2 | 2 | # SPDX-License-Identifier: BSD-3-Clause |
3 | 3 |
|
4 | 4 | from contextlib import suppress |
5 | | -from pathlib import Path |
6 | 5 |
|
7 | 6 | import numpy as np |
8 | 7 | import pandas as pd |
@@ -645,44 +644,6 @@ def fit(self, verbosity: str | None = None) -> None: |
645 | 644 | expt_names = experiments.names |
646 | 645 | num_expts = len(expt_names) |
647 | 646 |
|
648 | | - # CSV setup: write results if the project has been saved |
649 | | - csv_path = None |
650 | | - csv_header = None |
651 | | - csv_free_names = None |
652 | | - csv_diffrn_fields = None |
653 | | - if self.project.info.path is not None: |
654 | | - from easydiffraction.analysis.sequential import _META_COLUMNS # noqa: PLC0415 |
655 | | - from easydiffraction.analysis.sequential import _append_to_csv # noqa: PLC0415 |
656 | | - from easydiffraction.analysis.sequential import _write_csv_header # noqa: PLC0415 |
657 | | - |
658 | | - csv_path = Path(self.project.info.path) / 'analysis' / 'results.csv' |
659 | | - csv_path.parent.mkdir(parents=True, exist_ok=True) |
660 | | - |
661 | | - all_params = ( |
662 | | - self.project.structures.parameters + self.project.experiments.parameters |
663 | | - ) |
664 | | - csv_free_names = [ |
665 | | - p.unique_name |
666 | | - for p in all_params |
667 | | - if isinstance(p, Parameter) and not p.constrained and p.free |
668 | | - ] |
669 | | - |
670 | | - first_expt = list(experiments.values())[0] |
671 | | - csv_diffrn_fields = [] |
672 | | - if hasattr(first_expt, 'diffrn'): |
673 | | - csv_diffrn_fields = [ |
674 | | - p.name |
675 | | - for p in first_expt.diffrn.parameters |
676 | | - if hasattr(p, 'name') and p.name not in ('type',) |
677 | | - ] |
678 | | - |
679 | | - csv_header = list(_META_COLUMNS) |
680 | | - csv_header.extend(f'diffrn.{f}' for f in csv_diffrn_fields) |
681 | | - for name in csv_free_names: |
682 | | - csv_header.append(name) |
683 | | - csv_header.append(f'{name}.uncertainty') |
684 | | - _write_csv_header(csv_path, csv_header) |
685 | | - |
686 | 647 | # Short mode: print header and create display handle once |
687 | 648 | short_headers = ['experiment', 'χ²', 'iterations', 'status'] |
688 | 649 | short_alignments = ['left', 'right', 'right', 'center'] |
@@ -730,25 +691,6 @@ def fit(self, verbosity: str | None = None) -> None: |
730 | 691 | self._parameter_snapshots[expt_name] = snapshot |
731 | 692 | self.fit_results = results |
732 | 693 |
|
733 | | - # Append row to CSV |
734 | | - if csv_path is not None: |
735 | | - row = { |
736 | | - 'file_path': expt_name, |
737 | | - 'fit_success': results.success, |
738 | | - 'chi_squared': results.chi_square, |
739 | | - 'reduced_chi_squared': results.reduced_chi_square, |
740 | | - 'n_iterations': (self.fitter.minimizer.tracker.best_iteration or 0), |
741 | | - } |
742 | | - if hasattr(experiment, 'diffrn') and csv_diffrn_fields: |
743 | | - for p in experiment.diffrn.parameters: |
744 | | - if hasattr(p, 'name') and p.name not in ('type',): |
745 | | - row[f'diffrn.{p.name}'] = p.value |
746 | | - for uname in csv_free_names: |
747 | | - if uname in snapshot: |
748 | | - row[uname] = snapshot[uname]['value'] |
749 | | - row[f'{uname}.uncertainty'] = snapshot[uname]['uncertainty'] |
750 | | - _append_to_csv(csv_path, csv_header, [row]) |
751 | | - |
752 | 694 | # Short mode: append one summary row and update in-place |
753 | 695 | if verb is VerbosityEnum.SHORT: |
754 | 696 | chi2_str = ( |
|
0 commit comments