From 8c71352b7f1882c87e10a96b7add2384ff0a2a2f Mon Sep 17 00:00:00 2001 From: Ashish Mahabal Date: Wed, 20 Apr 2022 14:16:29 -0700 Subject: [PATCH 1/2] Create get_quad_ids.py Get ids as a list for a specific quad of a CCD for a particular ZTF field. Can be used later for getting features, and inferencing. --- tools/get_quad_ids.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/get_quad_ids.py diff --git a/tools/get_quad_ids.py b/tools/get_quad_ids.py new file mode 100644 index 00000000..0e4e3916 --- /dev/null +++ b/tools/get_quad_ids.py @@ -0,0 +1,49 @@ +from penquins import Kowalski + +def get_field_ids(catalog,field=301,ccd=2,quad=3,minobs=5,n=10): + '''Get ids as a list for a specific quad of a CCD for a particular ZTF field. + + USAGE: data = get_field_ids('ZTF_sources_20210401',field=301,ccd=2,quad=3,minobs=5,n=20) + It is assumed that you are connected to the database already. + ccd range: [1,16] (not checked) + quad range: p1,4] (not checked) + Defualt minobs is 5 + Default number of ids to return is 10 (use 0 for all rows) + Output: list of ids + ''' + + if n == 0: + limit = 10000000000 + else: + limit = n + + q = { + 'query_type': 'find', + 'query': { + 'catalog': catalog, + 'filter': { + "field": {"$eq": field}, + "ccd": {"$eq": ccd}, + "quad": {"$eq": quad}, + "nobs": {"$gt": minobs}, + }, + "projection": { + "_id": 1, + } + }, + "kwargs": { + "limit": limit + } + } + + r = k.query(q) + data = r.get('data') + return [data[i]['_id'] for i in range(len(data))] + +if __name__ == "__main__": + # setup connection to gloria to get the lightcurves + with open('secrets.json', 'r') as f: + secrets = json.load(f) + gloria = Kowalski(**secrets['gloria'], verbose=False) + + data = get_field_ids('ZTF_sources_20210401',field=301,ccd=2,quad=3,minobs=5,n=20) From 524bd8c3f6d0d3e1c1b660d0514d618fd8d4c801 Mon Sep 17 00:00:00 2001 From: Ashish Mahabal Date: Wed, 20 Apr 2022 14:27:11 -0700 Subject: [PATCH 2/2] Update get_quad_ids.py Added a missing import, and corrected a variable name --- tools/get_quad_ids.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/get_quad_ids.py b/tools/get_quad_ids.py index 0e4e3916..a09f1ea7 100644 --- a/tools/get_quad_ids.py +++ b/tools/get_quad_ids.py @@ -1,4 +1,5 @@ from penquins import Kowalski +import json def get_field_ids(catalog,field=301,ccd=2,quad=3,minobs=5,n=10): '''Get ids as a list for a specific quad of a CCD for a particular ZTF field. @@ -36,7 +37,7 @@ def get_field_ids(catalog,field=301,ccd=2,quad=3,minobs=5,n=10): } } - r = k.query(q) + r = gloria.query(q) data = r.get('data') return [data[i]['_id'] for i in range(len(data))]