From 0fca8bc20938935b12625d5ff0ff2c36f87a45d7 Mon Sep 17 00:00:00 2001 From: Daniel Goldstein Date: Sun, 26 Apr 2020 13:22:54 -0700 Subject: [PATCH] a few bugfixes --- nersc/retrieve.py | 11 ++++++----- scripts/queryref.py | 4 ++-- zuds/archive.py | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/nersc/retrieve.py b/nersc/retrieve.py index f20d193..725019a 100644 --- a/nersc/retrieve.py +++ b/nersc/retrieve.py @@ -113,7 +113,7 @@ def retrieve_images(images_or_ids, """Image whereclause should be a clause element on ZTFFile.""" images_or_ids = np.atleast_1d(images_or_ids) - ids = [i if isinstance(i, int) else i.id for i in images_or_ids] + ids = [int(i) if not hasattr(i, 'id') else i.id for i in images_or_ids] got = [] @@ -259,7 +259,7 @@ def retrieve_images(images_or_ids, # download the remaining images individually from IPAC if ipac: - remaining = np.setdiff1d(ids, got) + remaining = [int(i) for i in np.setdiff1d(ids, got)] remaining = zuds.DBSession().query(zuds.ZTFFile).filter( zuds.ZTFFile.id.in_(remaining) ).all() @@ -278,15 +278,16 @@ def retrieve_images(images_or_ids, i.download(suffix=suffix, destination=destination, cookie=cookie) except requests.RequestException: continue - + if archive_new: - acopy = zuds.HTTPArchiveCopy.from_product(i, check=False) - destination = acopy.archive_path i.map_to_local_file(destination) # ensure the image header is written to the DB i.load_header() + + acopy = zuds.HTTPArchiveCopy.from_product(i, check=False) + acopy.put() # and archive the file to disk zuds.DBSession().add(acopy) diff --git a/scripts/queryref.py b/scripts/queryref.py index f83617c..f094595 100644 --- a/scripts/queryref.py +++ b/scripts/queryref.py @@ -35,9 +35,9 @@ ).select_from(sub).join( zuds.MaskImage, zuds.MaskImage.parent_image_id == sub.c.id -).filter(sub.c.rank < MAX_IMGS) +).filter(sub.c.rank <= MAX_IMGS) -final = pd.DataFrame(result.all(), columns=['id1', 'id2']) +final = pd.DataFrame(result.all(), columns=['id1', 'id2']).astype(str) with open(outfile_name, 'w') as f: f.write('\n'.join(final['id1'].tolist()) + '\n') diff --git a/zuds/archive.py b/zuds/archive.py index 3099fc3..b3d22a2 100644 --- a/zuds/archive.py +++ b/zuds/archive.py @@ -225,7 +225,8 @@ def archive(copy): if os.getenv('NERSC_HOST') == 'cori': if not path.parent.exists(): _mkdir_recursive(path.parent) - shutil.copy(product.local_path, path) + if not os.path.abspath(product.local_path) == os.path.abspath(path): + shutil.copy(product.local_path, path) os.chmod(path, perm) else: archive_copy_over_http(copy)