Skip to content

Commit dea0b53

Browse files
authored
Merge pull request #160 from SNflows/devel
Refcat2 updates
2 parents 5f90f5f + 17f6e51 commit dea0b53

5 files changed

Lines changed: 41 additions & 7 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
master-v1.2.1
1+
master-v1.2.2

flows/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FLOWS pipeline package
33
"""
44
from .photometry import timed_photometry as photometry
5-
from .catalogs import download_catalog
5+
from .catalogs import download_catalog, delete_catalog
66
from .visibility import visibility
77
from .version import get_version
88
from .load_image import load_image

flows/catalogs.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from astroquery.simbad import Simbad
2525
from bottleneck import anynan
2626
from tendrils.utils import load_config, query_ztf_id
27+
from tendrils import api
2728

2829
from .aadc_db import AADC_DB
2930

@@ -257,7 +258,7 @@ def query_skymapper(coo_centre, radius=24 * u.arcmin):
257258

258259
# --------------------------------------------------------------------------------------------------
259260

260-
def query_local_refcat2(coo_centre, radius=24 * u.arcmin):
261+
def query_local_refcat2(coo_centre, radius=24 * u.arcmin, limiting_magnitude=19):
261262
"""
262263
Uses refcat.c from https://archive.stsci.edu/hlsp/atlas-refcat2 to do a cone-search around the position.
263264
NOTE: In going from mast casjobs to local refcat.c, we have lost the unique object identifier, 'objid'
@@ -289,6 +290,7 @@ def query_local_refcat2(coo_centre, radius=24 * u.arcmin):
289290
refcat_output = subprocess.run(["refcat",
290291
str(coo_centre.ra.deg), str(coo_centre.dec.deg),
291292
"-rad", str(Angle(radius).deg),
293+
"-mlim", str(limiting_magnitude),
292294
"-var", "ra,dec,pmra,pmdec,gaia,bp,rp,dupvar,g,r,i,z,j,h,k",
293295
"-nohdr"],
294296
encoding="utf-8", capture_output=True, check=True)
@@ -331,7 +333,7 @@ def query_local_refcat2(coo_centre, radius=24 * u.arcmin):
331333
logger.debug("Found %d results", len(results))
332334
return results
333335

334-
def query_all(coo_centre, radius=24 * u.arcmin, dist_cutoff=2 * u.arcsec):
336+
def query_all(coo_centre, radius=24 * u.arcmin, dist_cutoff=2 * u.arcsec, limiting_magnitude=19):
335337
"""
336338
Query all catalogs (REFCAT2, APASS, SDSS and SkyMapper) and return merged catalog.
337339
@@ -354,7 +356,7 @@ def query_all(coo_centre, radius=24 * u.arcmin, dist_cutoff=2 * u.arcsec):
354356
"""
355357

356358
# Query the REFCAT2 catalog using CasJobs around the target position:
357-
results = query_local_refcat2(coo_centre, radius=radius)
359+
results = query_local_refcat2(coo_centre, radius=radius, limiting_magnitude=limiting_magnitude)
358360
AT_results = Table(results)
359361
refcat = SkyCoord(ra=AT_results['ra'], dec=AT_results['decl'], unit=u.deg, frame='icrs')
360362

@@ -567,3 +569,18 @@ def download_catalog(target=None, radius=24 * u.arcmin, radius_ztf=3 * u.arcsec,
567569
except: # noqa: E722, pragma: no cover
568570
db.conn.rollback()
569571
raise
572+
573+
574+
def delete_catalog(target):
575+
cat = api.get_catalog(target)
576+
ids = list(cat['references']['starid'])
577+
578+
id_list = ",".join([str(id) for id in ids])
579+
580+
print(id_list)
581+
582+
with AADC_DB() as db:
583+
if target is not None and isinstance(target, (int, float)):
584+
db.cursor.execute("DELETE FROM flows.refcat2 WHERE starid IN (%s);" % id_list)
585+
db.cursor.execute("UPDATE flows.targets SET catalog_downloaded=FALSE,ztf_id=NULL WHERE targetid=%s;" % int(target))
586+
db.conn.commit()

flows/fileio.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ def get_filter(self):
192192
def load_references(self, catalog: Optional[Dict] = None) -> refclean.References:
193193
use_filter = self.get_filter()
194194
references = api.get_catalog(self.target.name)['references'] if catalog is None else catalog['references']
195+
196+
filter = (references["J_mag"] > 10) & (references["H_mag"] > 10) & (references["g_mag"] is not None) \
197+
& (references["H_mag"] is not None) & (references["gaia_variability"] != 1) \
198+
& (references["g_mag"] - references["r_mag"] < 10) & (references["starid"] != 107441912858406185) \
199+
& (references["starid"] != 107441912838383932)
200+
201+
references = references[filter]
195202
references.sort(use_filter)
196203
# Check that there actually are reference stars in that filter:
197204
if allnan(references[use_filter]):

run_catalogs.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import argparse
55
import logging
66
from tendrils import api
7-
from flows import download_catalog
7+
from flows import download_catalog, delete_catalog
88

99

1010
def parse():
@@ -16,7 +16,8 @@ def parse():
1616
parser.add_argument('-q', '--quiet', help='Only report warnings and errors.', action='store_true')
1717
parser.add_argument('-c', '--commit', help='Commit downloaded catalog(s) to flows database.', action='store_true')
1818
parser.add_argument('-p', '--print', help='Print single catalog which already exists in flows database.', action='store_true')
19-
parser.add_argument('-t', '--target', type=str, help='Optionally specify just one target for downloading/committing/printing.', nargs='?', default=None)
19+
parser.add_argument('-t', '--target', type=str, help='Optionally specify just one target for downloading/committing/printing/deleting.', nargs='?', default=None)
20+
parser.add_argument('-D', '--delete', help='Delete single catalog which already exists in flows database.', action='store_true')
2021
return parser.parse_args()
2122

2223
def set_logging_level(args):
@@ -42,6 +43,15 @@ def main():
4243
logger.addHandler(console)
4344
logger.setLevel(logging_level)
4445

46+
if args.delete:
47+
if args.target is not None:
48+
logger.info("Deleting catalog for target=%s...", args.target)
49+
delete_catalog(int(args.target))
50+
logger.info("Done deleting catalog for target=%s...", args.target)
51+
else:
52+
logger.warning("Need to specify target to delete")
53+
exit(0)
54+
4555
targets = api.get_catalog_missing()
4656
if args.target is not None:
4757
if args.print is False:

0 commit comments

Comments
 (0)