sot / astromon

Astrometric accuracy (celestial location) monitor
0 stars 0 forks source link

Opening astromon.h5 file in r+ mode will fail on HEAD / GRETA #25

Closed taldcroft closed 2 years ago

taldcroft commented 2 years ago

The astromon.h5 file is being opened in r+ mode. This fails if the user does not have write permission for the file, which is generally the case on HEAD / GRETA machines.

Example:

In [1]: from astromon import get_cross_matches

In [2]: xc = get_cross_matches()

In [3]: !chmod -w /Users/aldcroft/ska/data/astromon/astromon.h5

In [4]: xc = get_cross_matches()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-98008cb846f8> in <module>
----> 1 xc = get_cross_matches()

~/git/astromon/astromon/db.py in get_cross_matches(name, dbfile, **kwargs)
    572     from astromon.cross_match import filter_matches
    573 
--> 574     matches = get_table('astromon_xcorr', dbfile)
    575     matches = matches[matches['select_name'] == name]
    576     astromon_cat_src = get_table('astromon_cat_src', dbfile)

~/git/astromon/astromon/db.py in get_table(table_name, dbfile)
    176     #     raise RuntimeError(f'Astromon DB file does not exist {dbfile}')
    177 
--> 178     with connect(dbfile) as con:
    179         if type(con) is sqlite3.Connection:
    180             try:

~/miniconda3/envs/ska3/lib/python3.8/contextlib.py in __enter__(self)
    111         del self.args, self.kwds, self.func
    112         try:
--> 113             return next(self.gen)
    114         except StopIteration:
    115             raise RuntimeError("generator didn't yield") from None

~/git/astromon/astromon/db.py in connect(dbfile)
    332                 mode = 'r+' if dbfile.exists() else 'w'
    333                 logger.debug(f'{dbfile} open')
--> 334                 h5 = tables_open_file(dbfile, mode)
    335                 if not h5.is_undo_enabled():
    336                     h5.enable_undo()

~/miniconda3/envs/ska3/lib/python3.8/site-packages/ska_helpers/retry/api.py in tables_open_file(*args, **kwargs)
    149     import tables.exceptions
    150 
--> 151     h5 = ska_helpers.retry.retry_call(
    152         tables.open_file, args=args, kwargs=kwargs,
    153         exceptions=tables.exceptions.HDF5ExtError,

~/miniconda3/envs/ska3/lib/python3.8/site-packages/ska_helpers/retry/api.py in retry_call(f, args, kwargs, exceptions, tries, delay, max_delay, backoff, jitter, logger)
    131         kwargs = {}
    132 
--> 133     return __retry_internal(f, exceptions, tries, delay, max_delay,
    134                             backoff, jitter, logger, args=args, kwargs=kwargs)
    135 

~/miniconda3/envs/ska3/lib/python3.8/site-packages/ska_helpers/retry/api.py in __retry_internal(f, exceptions, tries, delay, max_delay, backoff, jitter, logger, args, kwargs)
     43     while _tries:
     44         try:
---> 45             return f(*args, **kwargs)
     46         except exceptions as e:
     47             exc_type, exc_value, exc_traceback = sys.exc_info()

~/miniconda3/envs/ska3/lib/python3.8/site-packages/tables/file.py in open_file(filename, mode, title, root_uep, filters, **kwargs)
    313 
    314     # Finally, create the File instance, and return it
--> 315     return File(filename, mode, title, root_uep, filters, **kwargs)
    316 
    317 

~/miniconda3/envs/ska3/lib/python3.8/site-packages/tables/file.py in __init__(self, filename, mode, title, root_uep, filters, **kwargs)
    776 
    777         # Now, it is time to initialize the File extension
--> 778         self._g_new(filename, mode, **params)
    779 
    780         # Check filters and set PyTables format version for new files.

tables/hdf5extension.pyx in tables.hdf5extension.File._g_new()

~/miniconda3/envs/ska3/lib/python3.8/site-packages/tables/utils.py in check_file_access(filename, mode)
    184         check_file_access(filename, 'r')
    185         if not os.access(filename, os.W_OK):
--> 186             raise IOError("file ``%s`` exists but it can not be written"
    187                           % (filename,))
    188     else:

OSError: file ``/Users/aldcroft/ska/data/astromon/astromon.h5`` exists but it can not be written