def test_view_groupings(self): # create a group, check it is added to DB group = TargetList(name="test_group") group.save() self.assertTrue(TargetList.objects.filter(name="test_group").exists()) # give this user the permission to view it user = User.objects.get(username='******') assign_perm('tom_targets.view_targetlist', user, group) response = self.client.get(reverse('targets:targetgrouping'), follow=True) self.assertContains(response, group.name)
def test_delete_group(self): # create a group, check it is added to DB group = TargetList(name="test_group") group.save() self.assertTrue(TargetList.objects.filter(name="test_group").exists()) # give user permission to delete user = User.objects.get(username='******') assign_perm('tom_targets.delete_targetlist', user, group) response = self.client.post(reverse('targets:delete-group', args=(group.pk,)), follow=True) self.assertRedirects(response, reverse('targets:targetgrouping'), status_code=302) self.assertFalse(TargetList.objects.filter(name='test_group').exists())
def handle(self, *args, **options): ### Create or load TAP list try: tap_list = TargetList.objects.filter(name='TAP')[0] except: tap_list = TargetList(name='TAP') tap_list.save() if options['target_name'] == 'all': list_of_events_alive = Target.objects.filter( targetextra__in=TargetExtra.objects.filter(key='Alive', value=True)) else: target, created = Target.objects.get_or_create( name=options['target_name']) list_of_events_alive = [target] for event in list_of_events_alive[:]: if 'Microlensing' not in event.extra_fields['Classification']: pass else: try: time_now = Time(datetime.datetime.now()).jd t0_pspl = event.extra_fields['t0'] u0_pspl = event.extra_fields['u0'] tE_pspl = event.extra_fields['tE'] covariance = np.array( json.loads(event.extra_fields['Fit_covariance'])) planet_priority = TAP.TAP_planet_priority( time_now, t0_pspl, u0_pspl, tE_pspl) planet_priority_error = TAP.TAP_planet_priority_error( time_now, t0_pspl, u0_pspl, tE_pspl, covariance) #psi_deriv = TAP.psi_derivatives_squared(time_now,t0_pspl,u0_pspl,tE_pspl) #error = (psi_deriv[2] * covariance[2,2] + psi_deriv[1] * covariance[1,1] + psi_deriv[0] * covariance[0,0])**0.5 ### need to create a reducedatum for planet priority data = { 'tap': planet_priority, 'tap_error': planet_priority_error } rd, created = ReducedDatum.objects.get_or_create( timestamp=datetime.datetime.utcnow(), value=data, source_name='MOP', source_location=event.name, data_type='TAP_priority', target=event) if created: rd.save() extras = {'TAP_priority': np.around(planet_priority, 5)} event.save(extras=extras) ### Regular obs event_in_the_Bulge = TAP.event_in_the_Bulge( event.ra, event.dec) if (event_in_the_Bulge ): # & (event.extra_fields['Baseline_magnitude']>17): extras = {'Observing_mode': 'No'} event.save(extras=extras) else: if event.extra_fields['Alive'] == True: extras = {'Observing_mode': 'Regular'} event.save(extras=extras) obs_control.build_and_submit_regular_phot(event) else: extras = {'Observing_mode': 'No'} event.save(extras=extras) # Priority mode mag_now = TAP.TAP_mag_now(event) mag_baseline = event.extra_fields['Baseline_magnitude'] new_observing_mode = TAP.TAP_observing_mode( planet_priority, planet_priority_error, mag_now, mag_baseline) if new_observing_mode: tap_list.targets.add(event) extras = {'Observing_mode': new_observing_mode} event.save(extras=extras) print(planet_priority, planet_priority_error) obs_control.build_and_submit_priority_phot(event) ### Spectroscopy if (event.extra_fields['Spectras'] < 1) & ( event.extra_fields['Observing_mode'] != 'No'): obs_control.build_and_submit_regular_spectro(event) except: print('Can not perform TAP for this target')