Skip to content

Commit

Permalink
Maintain option for both cache/non-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Dec 8, 2022
1 parent 4684314 commit 926c8ce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions winterdrp/data/image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"""
import hashlib
import logging
from pathlib import Path

import numpy as np
from astropy.io.fits import Header
Expand Down Expand Up @@ -89,12 +90,16 @@ def __init__(self, data: np.ndarray, header: Header):
self.cache_files.append(self.cache_path)
self.set_data(data=data)

def get_cache_path(self):
def get_cache_path(self) -> Path:
"""
Get a unique cache path for the image (.npy file).
This is hash, using name and time, so should be unique even
when rerunning on the same image.
:return: unique cache file path
"""
base = "".join([str(Time.now()), self.get_name()])
name = f"{hashlib.sha1(base.encode()).hexdigest()}.npy"
# cache_dir = get_cache_dir()
# if not cache_dir.exists():
# cache_dir.mkdir(parents=True)
return CACHE_DIR.joinpath(name)

def __str__(self):
Expand Down

0 comments on commit 926c8ce

Please sign in to comment.