Skip to content

model class check if path is empty before attempting to read #233

Open
@bch0w

Description

When Model class attempts to read an empty working directory it throws an IndexError which does not point to the actual issue that their are no model files. See code block example below. Just need to add in a check that the path is not empty before it attempts to read files.

In [11]: ls

In [12]: from seisflows.tools.model import Model

In [13]: m = Model(fmt=".bin", flavor="3D")
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[13], line 1
----> 1 m = Model(fmt=".bin", flavor="3D")

File ~/Repos/seisflows/seisflows/tools/model.py:126, in Model.__init__(self, path, fmt, parameters, regions, flavor)
    122     self.flavor = self._guess_specfem_flavor()
    124 # Gather internal representation of the model for manipulation
    125 self._nproc, self.available_parameters = \
--> 126     self._get_nproc_parameters()
    127 self.model = self.read(parameters=parameters)
    129 # Coordinates are only useful for SPECFEM2D models

File ~/Repos/seisflows/seisflows/tools/model.py:664, in Model._get_nproc_parameters(self)
    658     avail_par = list(set(avail_par).intersection(
    659                                 set(self.acceptable_parameters)
    660                                 ))
    661     # Count the number of files for matching parameters only (do once)
    662     # Globe version requires the region number in the wild card
    663     nproc = len(glob(os.path.join(
--> 664         self.path, self.fnfmt(val=avail_par[0], ext=self.fmt)))
    665     )
    666 elif self.fmt == ".dat":
    667     # e.g., 'proc000000_rho_vp_vs'
    668     _, *avail_par = fids[0].split("_")

IndexError: list index out of range

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions