Skip to content

fixed cache dir bug - #452

Open
Little-Ryugu wants to merge 3 commits into
mainfrom
cache_dir-default-bug
Open

fixed cache dir bug#452
Little-Ryugu wants to merge 3 commits into
mainfrom
cache_dir-default-bug

Conversation

@Little-Ryugu

Copy link
Copy Markdown
Collaborator

Fixes #451 .

Changed cache_dir to default to str(pooch.os_cache("layup")) instead of None in LayupObservatory. Stops layup_furnish_spiceypy from searching for files in the Sorcha created cache.

Review Checklist for Source Code Changes

  • Does pip install still work?
  • Have you written a unit test for any new functions?
  • Do all the units tests run successfully?
  • Does Layup run successfully on a test set of input files/databases?
  • Have you used black on the files you have updated to confirm python programming style guide enforcement?

Changed cache_dir to default to str(pooch.os_cache("layup")) instead of None in LayupObservatory. Stops layup_furnish_spiceypy from searching for files in the Sorcha created cache.
@Little-Ryugu

Copy link
Copy Markdown
Collaborator Author

Don't accept/merge just yet. @mschwamb said there was a different bug before that caused a problem similar to this in orbitfit. I'm going to double-check everything first incase I missed something.

@Little-Ryugu
Little-Ryugu requested a review from mschwamb July 27, 2026 14:34
@Little-Ryugu

Copy link
Copy Markdown
Collaborator Author

@mschwamb, the fix was in pr #225 but missed the case where cache_dir is left as None. The call for Layup_observatory in orbitfit and predict was changed from:

Layup_observatory = LayupObservatory()

To:

Layup_observatory = LayupObservatory(cache_dir=cache_dir) 

This fixed the original bug in the main code, but the unit tests still have the bug as they call Layup_observatory= LayupObservatory()

There was another fix to a similar issue #286, but the fix was related to the observatory position and didn't change the unit tests calling the Sorcha cache.

@mschwamb

Copy link
Copy Markdown
Collaborator

I think you might want to make "layup" a global variable at the top of the file so it's clear that this is hardcoded - easier to spot if it needs to be changed.

@mschwamb mschwamb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see other comment about changes

@mschwamb
mschwamb self-requested a review August 11, 2026 09:22

# default Cache directory name where the layup auxiliary files are stored when layup bootstrap is ran
# eg on Mac ~/Library/Caches/layup
cache_dir_name = "layup"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you make it all caps - so that the style is the same throughout layup see

AU_KM = AU_M / 1000.0

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No problem will do.

@matthewholman matthewholman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't fix #451 on the paths that matter.

Changing the default only helps callers that omit the argument. All three production callers pass it explicitly, and their own defaults are None:

  • predict.py:438, orbitfit.py:1502, orbitfit.py:1555

So layup.predict(data, obscode, times) still sends None through to layup_furnish_spiceypy, which hands it to Sorcha as ar_data_file_path=None — the search #451 reports. tests/layup/test_predict.py:480 passes cache_dir=None explicitly too.

The evidence is one line above a caller:

kernels_loc = str(pooch.os_cache("layup")) if cache_dir is None else str(cache_dir)   # orbitfit.py:1554
observatory = LayupObservatory(cache_dir=cache_dir)                                   # 1555

Also, a default argument is evaluated once at import, so this freezes the cache path at module load — awkward for tests and for #448.

Suggested instead:

def __init__(self, cache_dir=None):
    if cache_dir is None:
        cache_dir = str(pooch.os_cache("layup"))
    self.cache_dir = cache_dir
    layup_furnish_spiceypy(cache_dir)

This covers explicit None, evaluates per call, matches the idiom used elsewhere (including line 434 of this file), and fixes self.cache_dir, which feeds the Horizons state cache and is currently stored as None.

A test asserting predict(..., cache_dir=None) furnishes from the layup cache would catch the regression.

@mschwamb
mschwamb self-requested a review August 12, 2026 09:48

@mschwamb mschwamb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See the detailed review from Matt

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.

Layup checking Sorcha cache for files when cache_dir is None in LayupObservatory.

3 participants