tomasstolker / species

Toolkit for atmospheric characterization of directly imaged exoplanets
https://species.readthedocs.io
MIT License
22 stars 10 forks source link

Database problem: OSError: Unable to open file (file is already open for read-only) #81

Closed gabrielastro closed 7 months ago

gabrielastro commented 7 months ago

I added an object

from species.data.database import Database
database = Database()
database.add_object('Objekt1', parallax = …  # set properties
    )

but then mistyped when looking for it later: database.get_object('Abject1'), leading to

KeyError: "Unable to open object (object 'Abject1' doesn't exist)"

Afterwards, I try to delete 'Objekt1' through database.delete_data('objects/Objekt1') but get an HDF5 error:

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file is already open for read-only)

How can I recover from here without quitting the session and restarting? And would it be possible to catch these errors and close the file in the background?

tomasstolker commented 7 months ago

Thanks for opening this issue! I think that I have fixed this by using a context manager in the add_object when opening the HDF5 file. This is part of commit 9a4923e0c992a0d83d8ede9632ecf3a64b817b23, so can be pulled from Github.

I wasn't able to reproduce the issue by the way. I was running it from a regular script. Are you using a notebook instead? Doesn't matter, just wondering what the reason might be.

gabrielastro commented 7 months ago

Thanks for your quick action! I was doing this "by hand" (pasting in commands) in ipython3. To try out your changes, I did git pull in my root species directory and then pip install -e . and now I get

~$ pip install -e .
Obtaining file://[…]/species
Collecting astropy~=5.2.0
  Downloading astropy-5.2.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (11.4 MB)
     |████████████████████████████████| 11.4 MB 1.3 MB/s 
Requirement already satisfied: astroquery~=0.4.0 in /home/gabriel/.local/lib/python3.8/site-packages (from species==0.7.4) (0.4.6)
Requirement already satisfied: corner~=2.2.0 in /home/gabriel/.local/lib/python3.8/site-packages (from species==0.7.4) (2.2.1)
Requirement already satisfied: emcee~=3.1.0 in /home/gabriel/.local/lib/python3.8/site-packages (from species==0.7.4) (3.1.3)
Collecting exo-k~=1.2.0
  Downloading exo_k-1.2.2-py3-none-any.whl (174 kB)
     |████████████████████████████████| 174 kB 1.3 MB/s 
Collecting h5py~=3.9.0
  Downloading h5py-3.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB)
     |████████████████████████████████| 4.8 MB 1.3 MB/s 
ERROR: Could not find a version that satisfies the requirement matplotlib~=3.8.0 (from species==0.7.4) (from versions: 0.86, 0.86.1, 0.86.2, 0.91.0, 0.91.1, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.1rc1, 1.4.1, 1.4.2, 1.4.3, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 2.0.0b1, 2.0.0b2, 2.0.0b3, 2.0.0b4, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.1.0rc1, 2.1.0, 2.1.1, 2.1.2, 2.2.0rc1, 2.2.0, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 3.0.0rc2, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0rc1, 3.1.0rc2, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0rc1, 3.2.0rc3, 3.2.0, 3.2.1, 3.2.2, 3.3.0rc1, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.4.0rc1, 3.4.0rc2, 3.4.0rc3, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.5.0b1, 3.5.0rc1, 3.5.0, 3.5.1, 3.5.2, 3.5.3, 3.6.0rc1, 3.6.0rc2, 3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.7.0rc1, 3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.7.4)
ERROR: No matching distribution found for matplotlib~=3.8.0 (from species==0.7.4)

Maybe it was not necessary to do pip install -e . as for the first installation? But it should not have hurt…

In any case, it seems the installation of the update worked because now I get:

ValueError: The argument of  'object_name' is set to 'Abjekt1' but the data is not found in the database.

and I am able to delete the data afterwards without an error. Thanks! I can open a separate issue (probably a silly mistake on my side) about the ERROR: No matching distribution found for matplotlib error, if you wish, and/or you can mark this present issue as closed.

tomasstolker commented 7 months ago

Great! Indeed no need to pip install again after pulling from Github when you used -e.

Not sure why it doesn't find a match for matplotlib. Testing of the installation by the Actions seems to run fine.

Best to install species in a virtual environment so there is no clash with other dependency versions.

gabrielastro commented 7 months ago

Ok, thanks a lot!