Skip to content

Commit

Permalink
added clearcache function
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerapritchard committed Apr 25, 2024
1 parent ff62241 commit af7dbe2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/newlk_search/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import warnings
import glob
import shutil

import astropy.config as astropyconfig

Expand Down Expand Up @@ -81,3 +83,15 @@ def _ensure_cache_dir_exists(cache_dir):
cache_dir = "."
return cache_dir

def clearcache(test=True):
#Check to see if default download dir//mastDownload exists
mastdir = f"{get_cache_dir()}/mastDownload"
if(os.path.isdir(mastdir)):
files = glob.glob(f"{mastdir}/*")
if(test):
print("Running in test mode, rerun with test=False to clear cache")
for f in files:
if(test):
print(f"removing {f}")
else:
shutil.rmtree(f)
8 changes: 3 additions & 5 deletions src/newlk_search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

default_download_dir = config.get_cache_dir()

# from memoization import cached

log = logging.getLogger(__name__)

class MASTSearch(object):
Expand Down Expand Up @@ -1430,9 +1428,9 @@ def download(self, cloud: PREFER_CLOUD = True, cache: PREFER_CLOUD = True, cloud
if("TESScut" in self.table.provenance_name.unique()):
mask = self.table["provenance_name"] == "TESScut"
self._mask(~mask).download()
from astroquery.mast import Tesscut
if cloud:
Tesscut.enable_cloud_dataset()
from astroquery.mast import TesscutClass as Tesscut
#if cloud:
# Tesscut.enable_cloud_dataset()
mf1 = Tesscut.download_cutouts(coordinates=self.SkyCoord,
size=TESScut_size,
sector=self.table['sequence_number'].values[mask],
Expand Down
7 changes: 6 additions & 1 deletion src/newlk_search/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
import sys

from . import config
default_download_dir = config.get_cache_dir()


from functools import wraps

class SearchError(Exception):
Expand All @@ -24,4 +28,5 @@ def wrapper(*args, **kwargs):
finally:
sys.stdout = old_out

return wrapper
return wrapper

0 comments on commit af7dbe2

Please sign in to comment.