Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bch0w opened this issue Nov 15, 2024 · 0 comments
Open

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

bch0w opened this issue Nov 15, 2024 · 0 comments

Comments

@bch0w
Copy link
Member

bch0w commented Nov 15, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant