VERITAS-Observatory / gammapy-tools

Repository with tools for gammapy analysis
GNU General Public License v3.0
2 stars 0 forks source link

Catching runlists where no runs are found #15

Closed steob92 closed 7 months ago

steob92 commented 7 months ago

If no runs are found. Need to check length of obs_in_db

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[6], line 1
----> 1 config = prepare_dataset(config)

File /opt/conda/lib/python3.10/site-packages/gammapy_tools/make_background/prepare_data.py:54, in prepare_dataset(config)
     51     os.mkdir(results_dir)
     53 # Copy
---> 54 data_store.copy_obs(obs_in_db, in_dir)
     55 # Update new config
     56 config["run_selection"]["runlist"] = obs_in_db

File /opt/conda/lib/python3.10/site-packages/gammapy/data/data_store.py:436, in DataStore.copy_obs(self, obs_id, outdir, hdu_class, verbose, overwrite)
    434 hdutable.add_index("OBS_ID")
    435 with hdutable.index_mode("discard_on_copy"):
--> 436     subhdutable = hdutable.loc[obs_id]
    437 if hdu_class is not None:
    438     subhdutable.add_index("HDU_CLASS")

File /opt/conda/lib/python3.10/site-packages/astropy/table/index.py:882, in TableLoc.__getitem__(self, item)
    879 rows = self._get_rows(item)
    881 if len(rows) == 0:  # no matches found
--> 882     raise KeyError(f"No matches found for key {item}")
    883 elif len(rows) == 1:  # single row
    884     return self.table[rows[0]]

KeyError: 'No matches found for key []'
steob92 commented 7 months ago

Now provides an error to inform the user that the files don't exist in the data store:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/gammapy_tools/make_background/prepare_data.py:55, in prepare_dataset(config)
     54 try:
---> 55     data_store.copy_obs(obs_in_db, in_dir)
     56 except Exception as e:

File /opt/conda/lib/python3.10/site-packages/gammapy/data/data_store.py:436, in DataStore.copy_obs(self, obs_id, outdir, hdu_class, verbose, overwrite)
    435 with hdutable.index_mode("discard_on_copy"):
--> 436     subhdutable = hdutable.loc[obs_id]
    437 if hdu_class is not None:

File /opt/conda/lib/python3.10/site-packages/astropy/table/index.py:882, in TableLoc.__getitem__(self, item)
    881 if len(rows) == 0:  # no matches found
--> 882     raise KeyError(f"No matches found for key {item}")
    883 elif len(rows) == 1:  # single row

KeyError: 'No matches found for key []'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 config = prepare_dataset(config)

File /opt/conda/lib/python3.10/site-packages/gammapy_tools/make_background/prepare_data.py:58, in prepare_dataset(config)
     56 except Exception as e:
     57     if len(obs_in_db) == 0:
---> 58         raise RuntimeError(
     59             f"Observations cannot be found in {db_dir}, do these files exist?"
     60         ) from e
     61     else:
     62         raise RuntimeError("Error copying files") from e

RuntimeError: Observations cannot be found in /local_data/VERITAS/DL3/v490/dl3_fullenclosure_moderate2tel, do these files exist?