Skip to content

Cache star coordinates#60

Open
jeremyneveu wants to merge 18 commits intolsst-devfrom
u/jneveu/astroquery
Open

Cache star coordinates#60
jeremyneveu wants to merge 18 commits intolsst-devfrom
u/jneveu/astroquery

Conversation

@jeremyneveu
Copy link
Collaborator

Avoid multiple queries to Simbad

Coordinates are stored as pickle files in .cache/astroquery folder in the extractor subpackage

@coveralls
Copy link

coveralls commented Mar 14, 2025

Pull Request Test Coverage Report for Build 14511196164

Details

  • 28 of 39 (71.79%) changed or added relevant lines in 1 file are covered.
  • 7 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 71.365%

Changes Missing Coverage Covered Lines Changed/Added Lines %
spectractor/extractor/targets.py 28 39 71.79%
Files with Coverage Reduction New Missed Lines %
spectractor/extractor/targets.py 7 55.11%
Totals Coverage Status
Change from base Build 13558643118: -0.05%
Covered Lines: 5762
Relevant Lines: 8074

💛 - Coveralls

@jeremyneveu
Copy link
Collaborator Author

@timj @erykoff are you happy with this proposition to cache star coordinates and skip simbad queries?

@jeremyneveu jeremyneveu requested review from erykoff and timj March 18, 2025 09:16
Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache directory location can't work as written.

I think you need to have a combination of a read-only resource inside the python package that is accessed via importlib.resources.

ie do a look up first in the package, then look in the astropy cache and then do the simbad query itself and write to the astropy cache.

@timj
Copy link
Member

timj commented Mar 19, 2025

If you don't want to special case this one star in the source code itself, my other suggestion was to have the test setUp write the ecsv file to the astropy cache so that when the test runs it reads from the cache.

@jeremyneveu
Copy link
Collaborator Author

jeremyneveu commented Apr 14, 2025

I put a decorator for the test, like

@astropy.config.set_temp_cache(os.path.join(os.path.abspath(os.path.dirname(__file__)), "data", "cache"))

Is it sufficient? Otherwise can you be more explicit concerning your idea "to have the test setUp write the ecsv file to the astropy cache so that when the test runs it reads from the cache." ?

@timj
Copy link
Member

timj commented Apr 14, 2025

I think your decorator idea should be okay so long as nothing writes to that directory. My idea was a more explicit setUp method (or pytest equivalent) that copied the file from the test dir to the cache directory so that the test would pick it up from the cache -- that doesn't require writes to the tests/ directory but if the cache is only being accessed for that test it should be fine.

@jeremyneveu
Copy link
Collaborator Author

OK, I hope I understood well your recommandation. I have just pushed a modification of setup.py

@timj
Copy link
Member

timj commented Apr 16, 2025

I don't see any changes to a test for setting the cache dir so that the ecsv file is read.

@jeremyneveu
Copy link
Collaborator Author

I don't see any changes to a test for setting the cache dir so that the ecsv file is read.

Sorry the git push failed. Now it's online.

@jeremyneveu jeremyneveu requested a review from timj April 30, 2025 07:56
import astropy
astropy_cache_dir = astropy.config.get_cache_dir()
except ImportError:
astropy_cache_dir = os.path.join(f"{os.path.expanduser('~')}", ".astropy", "cache")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. When I said "copy the file to the cache in setup" I meant in the test code just before the test runs. Not having setup.py copy the file -- For tests with unittest there is a setUp method that is called that can do things that the tests need. I'm not sure what the equivalent would be for your tests since you aren't using unittest. I didn't even realize you were using the deprecated setup.py to build the package. There is no guarantee that when test code runs that that cache file written during package installation would still exist.

PS I saw recently that Astropy cache tooling does allow you to name the cache directory so you can call it "spectractor", just like astroquery calls it "astroquery".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants