ytsapras / robonet_site

Django RoboNet operational database.
GNU General Public License v2.0
0 stars 0 forks source link

DB Table query feature request #1

Closed rachel3834 closed 7 years ago

rachel3834 commented 9 years ago

I've finished drafting the code to subscribe to ARTEMiS and to the surveys, as laid out by Colin. The one stage that needs to be added is where the harvested information is added to the database, because the Table structure is changing. Below is an outline of the interaction this code needs to have with the DB in order to sync the parameters of an event from a survey with the DB. Some will need new query features added to update_db.py, so I'd like to file a feature request, once the Table structure is complete of course. Thanks!

Check event is known by name to the DB (possible outcomes: True or False)

Check event is known by coordinates to the DB (possible outcomes: - event is known and has this survey's ID

ytsapras commented 8 years ago

In the scripts subdirectory you will find update_db_2.py, based on the structure of the database discussed during the workshop (with slight modifications for simplicity).

from update_db_2 import *

To check if an event is known by name to the DB --> use check_exists

check_exists('OGLE-2015-BLG-0834') True

To check if an event is known by coordinates to the DB --> use coords_exist

coords_exist("17:54:33.49", "-30:31:02.01") (True, u'17:54:33.49', u'-30:31:02.2')

If the coordinates are already in the database, returns successful = True Also returns the coordinates of the object itself or the closest match found (within a radius of 2.5 arcsec).

To extract the event ID that refers to these coordinates use:

Event.objects.filter(ev_ra__contains='17:54:33.59').filter(ev_dec__contains='-30:31:02.2')[0].id 821

Then check the names associated with this ID by typing (returns a list):

EventName.objects.filter(event=821) EventName: OGLE-2015-BLG-0834 EventName.objects.filter(event=194) EventName: OGLE-2015-BLG-0195, EventName: MOA-2015-BLG-0128

To get just the name in string format use:

EventName.objects.filter(event=821)[0].name u'OGLE-2015-BLG-0834'

If the coordinates are not in the DB (unknown), then you can proceed and add them, with all relevant details --> use add_event(ev_ra, ev_dec, bright_neighbour = False, status='EX')

x = add_event(ev_ra='RA coords', ev_dec='Dec coords')

Then add the event name given by the survey that you got the coordinates from: Get the new event ID you just created with

event = Event.objects.filter(ev_ra=x[1]).filter(ev_dec=x[2])[0] Then if it's an event from, say, MOA, get the survey ID corresponding to MOA operator = Operator.objects.get(name='MOA') Then add the new name: y = add_event_name(event=event, operator=operator, name='MOA-2015-BLG-1234')

If MOA have also released a Single Lens model, you can add that by using --> add_single_lens

add_single_lens(event_name='MOA-2015-BLG-1234', Tmax=Tmax, e_Tmax=e_Tmax, tau=tau, e_tau=e_tau, umin=umin, e_umin=e_umin, last_updated=last_updated, modeler='MOA', rho=None, e_rho=None, pi_e_n=None, e_pi_e_n=None, pi_e_e=None, e_pi_e_e=None)

rachel3834 commented 8 years ago

Thanks Yianni. I can modify my code but it may take me a while, so feel free to update it if you prefer.

rachel3834 commented 7 years ago

This is now implemented, so closing this as an issue.