Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create get_quad_ids.py #74

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tools/get_quad_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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.

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 = gloria.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)