Skip to content

Commit

Permalink
a few bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Goldstein committed Apr 26, 2020
1 parent a1161bc commit 0fca8bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions nersc/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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()
Expand 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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/queryref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion zuds/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0fca8bc

Please sign in to comment.