dirkphilip / LASIF_2.0

An End-to-end Workflow for Adjoint Full Seismic Waveform Inversions, specifically designed for SALVUS. For a tutorial, please download the Jupyter notebook at https://github.com/solvithrastar/LASIF_tutorials
GNU General Public License v3.0
14 stars 12 forks source link

py.test shows some assertion errors #95

Open Hoteryoung opened 1 year ago

Hoteryoung commented 1 year ago

Hi, sorry to bother you guys, but I encountered some assertion errors when executing the py.test command after I install the LASIF_2.0 through pyenv(not anaconda).

I'm a rookie at Seismology. And I'm not sure what's wrong with my installation.

Here is some info about my env. platform MacOS Monterey Python 3.7.13 Python packages: alabaster 0.7.12 appnope 0.1.3 attrs 22.2.0 Babel 2.11.0 backcall 0.2.0 Cartopy 0.20.3 certifi 2022.12.7 charset-normalizer 2.1.1 click 8.1.3 cmasher 1.6.3 colorama 0.4.6 colorspacious 1.1.2 cycler 0.11.0 debugpy 1.6.4 decorator 5.1.1 dill 0.3.6 docutils 0.17.1 e13tools 0.9.6 entrypoints 0.4 exceptiongroup 1.1.0 Flask 2.2.2 Flask-Cache 0.13.1 fonttools 4.38.0 geographiclib 2.0 geojson 2.5.0 greenlet 2.0.1 h5py 3.7.0 idna 3.4 imagesize 1.4.1 importlib-metadata 6.0.0 iniconfig 1.1.1 ipydatawidgets 4.3.2 ipykernel 6.16.2 ipython 7.34.0 ipywidgets 8.0.4 isodate 0.6.1 itsdangerous 2.1.2 jedi 0.18.2 Jinja2 3.1.2 joblib 1.2.0 jupyter_client 7.4.8 jupyter_core 4.12.0 jupyterlab-widgets 3.0.5 kiwisolver 1.4.4 lasif 0.0.1 /Users/yanghaote2/Documents/code/LASIF_2.0 lxml 4.9.2 MarkupSafe 2.1.1 matplotlib 3.5.3 matplotlib-inline 0.1.6 mock 5.0.0 nest-asyncio 1.5.6 networkx 2.6.3 nose 1.3.7 numexpr 2.8.4 numpy 1.21.6 obspy 1.3.1 packaging 22.0 pandas 1.3.5 parso 0.8.3 pathlib 1.0.1 pexpect 4.8.0 pickleshare 0.7.5 Pillow 9.4.0 pip 22.3.1 pluggy 1.0.0 progressbar 2.5 prompt-toolkit 3.0.36 prov 2.0.0 psutil 5.9.4 ptyprocess 0.7.0 pyasdf 0.7.5 Pygments 2.14.0 pyparsing 3.0.9 pyproj 3.2.1 PyQt5 5.15.7 PyQt5-Qt5 5.15.2 PyQt5-sip 12.11.0 pyqtgraph 0.12.4 pyshp 2.3.1 pytest 7.2.0 python-dateutil 2.8.2 pythreejs 2.4.1 pytz 2022.7 pyzmq 24.0.1 rdflib 6.2.0 requests 2.28.1 scipy 1.7.3 seaborn 0.12.2 setuptools 47.1.0 Shapely 1.8.5 six 1.16.0 snowballstemmer 2.2.0 Sphinx 5.3.0 sphinx-rtd-theme 1.1.1 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 SQLAlchemy 1.4.46 toml 0.10.2 tomli 2.0.1 tornado 6.2 tqdm 4.64.1 traitlets 5.8.0 traittypes 0.2.1 typing_extensions 4.4.0 urllib3 1.26.13 wcwidth 0.2.5 Werkzeug 2.2.2 widgetsnbextension 4.0.4 zipp 3.11.0

AssertionError:

$LASIF_2.0 git:(master) py.test                                                                     3.7.13
Exception ignored in: <function Popen.__del__ at 0x10e332dd0>
Traceback (most recent call last):
  File "/Users/yanghaote2/.pyenv/versions/3.7.13/lib/python3.7/subprocess.py", line 883, in __del__
    ResourceWarning, source=self)
ResourceWarning: subprocess 75182 is still running
Exception ignored in: <function Popen.__del__ at 0x10e332dd0>
Traceback (most recent call last):
  File "/Users/yanghaote2/.pyenv/versions/3.7.13/lib/python3.7/subprocess.py", line 883, in __del__
    ResourceWarning, source=self)
ResourceWarning: subprocess 75183 is still running
============================================ test session starts ============================================
platform darwin -- Python 3.7.13, pytest-7.2.0, pluggy-1.0.0
rootdir: /Users/yanghaote2/Documents/code/LASIF_2.0, configfile: pytest.ini
collected 207 items                                                                                         

lasif/rotations.py ....                                                                               [  1%]
lasif/utils.py ...                                                                                    [  3%]
lasif/window_selection.py .                                                                           [  3%]
lasif/components/events.py ..                                                                         [  4%]
lasif/components/iterations.py .                                                                      [  5%]
lasif/function_templates/process_data.py s                                                            [  5%]
lasif/function_templates/window_picking_function.py s                                                 [  6%]
lasif/tests/test_adjoint_sources.py ....                                                              [  8%]
lasif/tests/test_api.py .............................                                                 [ 22%]
lasif/tests/test_cli_interface.py .................s......                                            [ 33%]
lasif/tests/test_code_formatting.py s                                                                 [ 34%]
lasif/tests/test_domain.py .......................................................................... [ 70%]
.......................                                                                               [ 81%]
lasif/tests/test_rotations.py ..                                                                      [ 82%]
lasif/tests/test_utils.py .                                                                           [ 82%]
lasif/tests/test_window_selection.py .                                                                [ 83%]
lasif/tests/components/test_adjoint_sources_component.py .FF.                                         [ 85%]
lasif/tests/components/test_downloads_component.py .                                                  [ 85%]
lasif/tests/components/test_events_component.py ......                                                [ 88%]
lasif/tests/components/test_iterations_component.py ....                                              [ 90%]
lasif/tests/components/test_project_component.py F...                                                 [ 92%]
lasif/tests/components/test_query_component.py ...                                                    [ 93%]
lasif/tests/components/test_validator_component.py ..                                                 [ 94%]
lasif/tests/components/test_visualization_component.py ssssssss                                       [ 98%]
lasif/tests/data/example_project/FUNCTIONS/process_data.py s                                          [ 99%]
lasif/tests/data/example_project/FUNCTIONS/window_picking_function.py s                               [ 99%]
lasif/tools/adjoint/utils.py .                                                                        [100%]

================================================= FAILURES ==================================================
_________________________________________ test_get_misfit_for_event _________________________________________

comm = <lasif.components.communicator.Communicator object at 0x13831f9d0>

    def test_get_misfit_for_event(comm):
        events = lasif.api.list_events(comm, output=True)
        iteration = lasif.api.list_iterations(comm, output=True)[0]
        lasif.api.calculate_adjoint_sources_multiprocessing(comm, iteration, "A")
        misfit = comm.adj_sources.get_misfit_for_event(
            event=events[0], iteration=iteration
        )
>       np.testing.assert_almost_equal(misfit, 1.301670132868937)
E       AssertionError: 
E       Arrays are not almost equal to 7 decimals
E        ACTUAL: 1.3016674437258846
E        DESIRED: 1.301670132868937

/Users/yanghaote2/Documents/code/LASIF_2.0/lasif/tests/components/test_adjoint_sources_component.py:57: AssertionError
------------------------------------------- Captured stdout call --------------------------------------------

===========================================================
Starting adjoint source calculation for event 1 of 2...
===========================================================

Writing adjoint sources...
1 Adjoint sources are in your file.
Finalizing adjoint sources...

===========================================================
Starting adjoint source calculation for event 2 of 2...
===========================================================

Writing adjoint sources...
1 Adjoint sources are in your file.
Finalizing adjoint sources...
------------------------------------------- Captured stderr call --------------------------------------------
100%|██████████| 4/4 [00:00<00:00, 43.20it/s]
100%|██████████| 4/4 [00:00<00:00, 17.19it/s]
______________________________________ test_calculate_adjoint_sources _______________________________________

comm = <lasif.components.communicator.Communicator object at 0x1383f58d0>

    def test_calculate_adjoint_sources(comm):
        events = lasif.api.list_events(comm, output=True)
        file = (
            comm.project.paths["adjoint_sources"]
            / "ITERATION_1"
            / events[0]
            / "auxiliary_adjoint.npy"
        )
        should_be = np.load(file)
        lasif.api.calculate_adjoint_sources_multiprocessing(comm, "1", "A", weight_set="sw_1")
        output = (
            comm.project.paths["adjoint_sources"]
            / "ITERATION_1"
            / events[0]
            / "adjoint_source_auxiliary.h5"
        )
        with pyasdf.ASDFDataSet(output) as ds:
            adj = ds.auxiliary_data.AdjointSources.HT_ALN.Channel__HHZ.data[()]
>       np.testing.assert_array_almost_equal(should_be, adj)
E       AssertionError: 
E       Arrays are not almost equal to 6 decimals
E       
E       (shapes (30002,), (30001,) mismatch)
E        x: array([0., 0., 0., ..., 0., 0., 0.])
E        y: array([0., 0., 0., ..., 0., 0., 0.])

/Users/yanghaote2/Documents/code/LASIF_2.0/lasif/tests/components/test_adjoint_sources_component.py:103: AssertionError
------------------------------------------- Captured stdout call --------------------------------------------

===========================================================
Starting adjoint source calculation for event 1 of 2...
===========================================================

Writing adjoint sources...
1 Adjoint sources are in your file.
Finalizing adjoint sources...

===========================================================
Starting adjoint source calculation for event 2 of 2...
===========================================================

Writing adjoint sources...
1 Adjoint sources are in your file.
Finalizing adjoint sources...
------------------------------------------- Captured stderr call --------------------------------------------
100%|██████████| 4/4 [00:00<00:00, 47.66it/s]
100%|██████████| 4/4 [00:00<00:00, 17.33it/s]
___________________________________ test_config_file_creation_and_parsing ___________________________________

tmpdir = local('/private/var/folders/_4/17zvg8wd3vbf51txxcqystc00000gq/T/pytest-of-yanghaote2/pytest-3/test_config_file_creation_and_0')

    def test_config_file_creation_and_parsing(tmpdir):
        """
        Tests the creation of a default config file and the reading of the file.
        """
        # Create a new project.
        pr = Project(
            project_root_path=pathlib.Path(str(tmpdir)).absolute(),
            init_project="TestProject",
        )
        del pr

        # Init it once again.
        pr = Project(pathlib.Path(str(tmpdir)).absolute())

        # Assert the config file will test the creation of the default file and the
        # reading.
        assert pr.lasif_config["project_name"] == "TestProject"
        assert pr.lasif_config["description"] == ""
        assert pr.lasif_config["download_settings"]["channel_priorities"] == [
            "BH?",
            "LH[Z,N,E]",
            "HH[Z,N,E]",
            "EH[Z,N,E]",
            "MH[Z,N,E]",
        ]
        assert pr.lasif_config["download_settings"]["location_priorities"] == [
            "",
            "00",
            "10",
            "20",
            "01",
            "02",
        ]
        assert pr.lasif_config["download_settings"]["networks"] == "None"

        assert (
            pr.lasif_config["download_settings"]["interstation_distance_in_m"]
            == 1000.0
        )
        assert (
            pr.lasif_config["download_settings"]["seconds_after_event"] == 3600.0
        )
        assert (
            pr.lasif_config["download_settings"]["seconds_before_event"] == 300.0
        )
>       assert not pr.salvus_settings["attenuation"]
E       assert not True

/Users/yanghaote2/Documents/code/LASIF_2.0/lasif/tests/components/test_project_component.py:80: AssertionError
========================================== short test summary info ==========================================
FAILED lasif/tests/components/test_adjoint_sources_component.py::test_get_misfit_for_event - AssertionError: 
FAILED lasif/tests/components/test_adjoint_sources_component.py::test_calculate_adjoint_sources - AssertionError: 
FAILED lasif/tests/components/test_project_component.py::test_config_file_creation_and_parsing - assert not True
================================ 3 failed, 190 passed, 14 skipped in 24.60s =================================
dirkphilip commented 1 year ago

Hi there,

We are aware of this issue. Some minor changes were made to the way adjoint sources are calculated and this broke some of the tests related to misfit and adjoint source calculations. Fixing this is on the to-do list and I will look into it. You don't have to worry about this too much.

What are your plans for using LASIF? Are you planning to do FWI using e.g. Salvus?

Best wishes, Dirk-Philip

Hoteryoung commented 1 year ago

Appreciate your quick reply. I'm glad to hear that this bug is on the to-do list.

Indeed, I,m trying to do some work about FWI. But, currently, I'm a total green hand in this area.

Besides, I want to know whether these assertion errors will affect my learning to use LASIF.

Best wishes, Hoter Young

dirkphilip commented 1 year ago

It shouldn't.

However, LASIF is currently made to work with the wave equation solver Salvus: (see: https://mondaic.com) Was this clear to you?

This software requires a license to be able to do wavefield simulations. Alternatively, you could fork LASIF and adapt it to use it with different solvers.

Hoteryoung commented 1 year ago

I'm not aware of this before. I will look into it.

Thanks again for your kind suggestion.