CEA-MetroCarac / fitspy

Generic tool dedicated to fit spectra in python
GNU General Public License v3.0
5 stars 0 forks source link

documentation missing how to run the tests and examples #9

Closed maurov closed 10 months ago

maurov commented 12 months ago

@patquem

I am evaluating fitspy (https://github.com/openjournals/joss-reviews/issues/5868) but I cannot run the tests and examples. The documentation should be updated with clear instructions and possibly a "quickstart tutorial". Please, could it be possible to push the documentation to a static web site? For example, GitHub Pages or Read the docs

Tested on Ubuntu WSL (Windows Subsystem for Linux), python 3.9 in a fresh conda environment.

Fitspy installation

pip install fitspy -> OK

Tests

cd
git clone https://github.com/CEA-MetroCarac/fitspy.git
cd fitspy/tests
pip install pytest

All tests fail because the examples are not found. Error trace below:

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/tests$ pytest
=============================================== test session starts ================================================
platform linux -- Python 3.9.0, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/mauro/devel/fitspy
collected 0 items / 4 errors

====================================================== ERRORS ======================================================
____________________________________ ERROR collecting tests/test_gui_2d_maps.py ____________________________________
ImportError while importing test module '/home/mauro/devel/fitspy/tests/test_gui_2d_maps.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../local/mambaforge/envs/fitspy/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_gui_2d_maps.py:4: in <module>
    from examples.ex3_gui_2d_maps import gui_2d_maps
E   ModuleNotFoundError: No module named 'examples'
________________________ ERROR collecting tests/test_gui_apply_model_to_all_new_spectra.py _________________________
ImportError while importing test module '/home/mauro/devel/fitspy/tests/test_gui_apply_model_to_all_new_spectra.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../local/mambaforge/envs/fitspy/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_gui_apply_model_to_all_new_spectra.py:4: in <module>
    from examples.ex2_gui_apply_model_to_all_new_spectra import \
E   ModuleNotFoundError: No module named 'examples'
______________________________ ERROR collecting tests/test_gui_auto_decomposition.py _______________________________
ImportError while importing test module '/home/mauro/devel/fitspy/tests/test_gui_auto_decomposition.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../local/mambaforge/envs/fitspy/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_gui_auto_decomposition.py:4: in <module>
    from examples.ex0_gui_auto_decomposition import gui_auto_decomposition
E   ModuleNotFoundError: No module named 'examples'
_____________________________ ERROR collecting tests/test_inline_auto_decomposition.py _____________________________
ImportError while importing test module '/home/mauro/devel/fitspy/tests/test_inline_auto_decomposition.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../local/mambaforge/envs/fitspy/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_inline_auto_decomposition.py:5: in <module>
    from examples.ex4_inline_auto_decomposition import inline_auto_decomposition
E   ModuleNotFoundError: No module named 'examples'
============================================= short test summary info ==============================================
ERROR test_gui_2d_maps.py
ERROR test_gui_apply_model_to_all_new_spectra.py
ERROR test_gui_auto_decomposition.py
ERROR test_inline_auto_decomposition.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================ 4 errors in 0.13s =================================================

Examples

Example 0 -> fails with error:

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/examples$ python ex0_gui_auto_decomposition.py
/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/examples/data/spectra_1 is not an existing directory
Traceback (most recent call last):
  File "/home/mauro/devel/fitspy/examples/ex0_gui_auto_decomposition.py", line 34, in <module>
    gui_auto_decomposition()
  File "/home/mauro/devel/fitspy/examples/ex0_gui_auto_decomposition.py", line 22, in gui_auto_decomposition
    appli.auto_eval_all()
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/fitspy/app/callbacks.py", line 739, in auto_eval_all
    current_fname = self.current_spectrum.fname
AttributeError: 'NoneType' object has no attribute 'fname'

Example 1 -> only empty GUI appears:

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/examples$ python ex1_gui_reload_model.py

image

Example 2 -> fails, data not found

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/examples$ python ex2_gui_apply_model_to_all_new_spectra.py
/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/examples/data/spectra_2 is not an existing directory

image

Example 3 -> fails, data not found

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/examples$ python ex3_gui_2d_maps.py
Traceback (most recent call last):
  File "/home/mauro/devel/fitspy/examples/ex3_gui_2d_maps.py", line 36, in <module>
    gui_2d_maps()
  File "/home/mauro/devel/fitspy/examples/ex3_gui_2d_maps.py", line 19, in gui_2d_maps
    appli.add_items(fnames=[str_map, unstr_map])
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/fitspy/app/callbacks.py", line 816, in add_items
    spectrum.load_profile(fname)
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/fitspy/spectra.py", line 209, in load_profile
    dfr = pd.read_csv(self.fname, sep=r'\s+|\t|,|;| ', engine='python',
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 948, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 611, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1448, in __init__
    self._engine = self._make_engine(f, self.engine)
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1705, in _make_engine
    self.handles = get_handle(
  File "/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/pandas/io/common.py", line 863, in get_handle
    handle = open(
FileNotFoundError: [Errno 2] No such file or directory: '/home/mauro/local/mambaforge/envs/fitspy/lib/python3.9/site-packages/examples/data/2D_maps/ordered_map.txt'

Example 4 -> fails

(fitspy) mauro@LAPCNRSMR:~/devel/fitspy/examples$ python ex4_inline_auto_decomposition.py
Traceback (most recent call last):
  File "/home/mauro/devel/fitspy/examples/ex4_inline_auto_decomposition.py", line 64, in <module>
    inline_auto_decomposition(show_plots=True)
  File "/home/mauro/devel/fitspy/examples/ex4_inline_auto_decomposition.py", line 32, in inline_auto_decomposition
    print(f"\n\nfilename: {fname}")
UnboundLocalError: local variable 'fname' referenced before assignment

Thanks for your help

patquem commented 11 months ago

Hi @maurov, Thank you for your feedback. Indeed, proceeding as you did, I reproduced the problems. I haven't encountered these problems before with my IDE (PyCharm) which automatically adds the contents roots and source roots to the PYTHONPATH. After some modifications to allow executions in a standard terminal, the issues have been fixed for me. Let me know if you still have problems running the tests. (I also added some text in the README.md about tests and examples execution.)

maurov commented 11 months ago

@patquem thanks for fixing this. The tests all pass now for me.

Example 0 -> OK Example 1 -> fails

(fitspy) mauro@LAPROVEZZI:~/devel/fitspy/examples$ python ex1_gui_reload_model.py
Traceback (most recent call last):
  File "/home/mauro/devel/fitspy/examples/ex1_gui_reload_model.py", line 20, in <module>
    gui_reload_model()
  File "/home/mauro/devel/fitspy/examples/ex1_gui_reload_model.py", line 16, in gui_reload_model
    fitspy_launcher(fname_json=fname)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/fitspy/app/gui.py", line 431, in fitspy_                                          launcher
    appli.reload(fname_json=fname_json)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/fitspy/app/callbacks.py", line 274, in r                                          eload
    self.spectra = Spectra.load(fname_json)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/fitspy/spectra.py", line 885, in load
    spectrum.preprocess()
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/fitspy/spectra.py", line 192, in preproc                                          ess
    self.load_profile(self.fname)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/fitspy/spectra.py", line 209, in load_pr                                          ofile
    dfr = pd.read_csv(self.fname, sep=r'\s+|\t|,|;| ', engine='python',
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 948,                                           in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 611,                                           in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1448                                          , in __init__
    self._engine = self._make_engine(f, self.engine)
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1705                                          , in _make_engine
    self.handles = get_handle(
  File "/home/mauro/local/conda/envs/fitspy/lib/python3.9/site-packages/pandas/io/common.py", line 863, in get_h                                          andle
    handle = open(
FileNotFoundError: [Errno 2] No such file or directory: '..\\examples\\data\\spectra_2\\InP-1_42-P21.txt'

Example 3 -> OK Example 4 -> OK

Some further questions

1) I cannot horizontally extend the settings panel ((see screenshot)

image

2) When I use the top right cross to close the GUI window, the command line shell is stuck and CTRL+C does not work to close the process. I have to kill the whole command line shell or the python process itself. This is very annoying. Could you add a "Quit" button (possibly binded to CTRL+Q) to quit the GUI in a clean way?

3) Is it possible to show the fit residual (in a panel with scaled y scale)? This is very important.

4) The "Parameters" panel is very slow to show/refresh (any idea why?), it does not include the background model information and does not nicely render (see screenshot)

image

patquem commented 11 months ago

Hi @maurov,

Thanks again for your feedback and sorry for the problems you encountered.

patquem commented 11 months ago

image

maurov commented 10 months ago

@patquem thanks for implementing most of my suggestions regarding this issue while running the examples.