Commit 1aed430d43c4c2d2b067c780c1329e019840ac47

Authored by jeremy
1 parent 4b503f5c
Exists in master and in 1 other branch dev

Alert handled + kill executing sequence when new alert

simulators/alert/alertSimulator.py
... ... @@ -60,6 +60,7 @@ class AlertSimulator():
60 60 if (int(dic["time"]) == i):
61 61 self.sendAlert(dic["alertSimulator"])
62 62 time.sleep(1)
  63 + self.clean_dir()
63 64 return (0)
64 65  
65 66 if __name__ == "__main__":
... ...
simulators/config/conf1.json deleted
... ... @@ -1,38 +0,0 @@
1   -[
2   - {
3   - "time" : 1,
4   - "userSimulator" : "routine_request_01.xml"
5   - },
6   - {
7   - "time" : 23,
8   - "userSimulator" : "routine_request_02.xml"
9   - },
10   - {
11   - "time" : 24,
12   - "userSimulator" : "routine_request_03.xml"
13   - },
14   - {
15   - "time" : 24,
16   - "userSimulator" : "routine_request_04.xml"
17   - },
18   - {
19   - "time" : 1,
20   - "alertSimulator" : "voevent_alert_04.xml"
21   - },
22   - {
23   - "time" : 30,
24   - "userSimulator" : "routine_request_05.xml"
25   - },
26   - {
27   - "time" : 35,
28   - "plcSimulator" : {"rain" : 5, "cloud" : 3}
29   - },
30   - {
31   - "time" : 40,
32   - "plcSimulator" : {"door1" : "open"}
33   - },
34   - {
35   - "time" : 41,
36   - "plcSimulator" : {"light3" : "on"}
37   - }
38   -]
simulators/config/conf_simple_alert.json 0 โ†’ 100644
... ... @@ -0,0 +1,11 @@
  1 +[
  2 + 30,
  3 + {
  4 + "time": 5,
  5 + "userSimulator" : "routine_request_01.xml"
  6 + },
  7 + {
  8 + "time" : 20,
  9 + "alertSimulator" : "voevent_alert_01.xml"
  10 + }
  11 +]
... ...
simulators/resources/voevent_alert_01.xml 0 โ†’ 100644
... ... @@ -0,0 +1,153 @@
  1 +<?xml version="1.0" ?>
  2 +<voe:VOEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 +xmlns:voe="http://www.ivoa.net/xml/VOEvent/v2.0"
  4 +xsi:schemaLocation="http://www.ivoa.net/xml/VOEvent/v2.0 http://www.ivoa.net/xml/VOEvent/VOEvent-v2.0.xsd"
  5 + version="2.0" role="observation" ivorn="ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_532871-729">
  6 +
  7 + <Who>
  8 + <AuthorIVORN>ivo://nasa.gsfc.tan/gcn</AuthorIVORN>
  9 + <Date>2012-09-07T00:24:36</Date>
  10 + <Description>This VOEvent message was created with GCN VOE version: 1.11 02aug12</Description>
  11 + <Author>
  12 + <shortName>VO-GCN</shortName>
  13 + <contactName>Scott Barthelmy</contactName>
  14 + <contactEmail>scott.barthelmy@nasa.gov</contactEmail>
  15 + <contactPhone>+1-301-286-3106</contactPhone>
  16 + </Author>
  17 + </Who>
  18 +
  19 + <What>
  20 + <Param name="Packet_Type" dataType="string" value="61"/>
  21 + <Param name="Pkt_Ser_Num" dataType="string" value="1"/>
  22 + <Param name="TrigID" dataType="string" value="532871" ucd="meta.id"/>
  23 + <Param name="Segment_Num" dataType="string" value="0" ucd="meta.id.part"/>
  24 + <Param name="Burst_TJD" dataType="string" value="16177" ucd="time" unit="days"/>
  25 + <Param name="Burst_SOD" dataType="string" value="1463.08" ucd="time" unit="sec"/>
  26 + <Param name="Burst_Inten" dataType="string" value="4622" ucd="phot.count;em.gamma.soft" unit="cts"/>
  27 + <Param name="Burst_Peak" dataType="string" value="207" ucd="phot.count;em.gamma.soft" unit="cts"/>
  28 + <Param name="Integ_Time" dataType="string" value="1.024" ucd="time.interval" unit="sec"/>
  29 + <Param name="Phi" dataType="string" value="-70.55" ucd="pos.az.azi" unit="deg"/>
  30 + <Param name="Theta" dataType="string" value="37.64" ucd="pos.az.zd" unit="deg"/>
  31 + <Param name="Trig_Index" dataType="string" value="148"/>
  32 + <Param name="Soln_Status" dataType="string" value="0x3"/>
  33 + <Param name="Misc_flags" dataType="string" value="0x0"/>
  34 + <Param name="Cat_Num" dataType="string" value="0"/>
  35 + <Param name="Rate_Signif" dataType="string" value="15.49" ucd="stat.snr" unit="sigma"/>
  36 + <Param name="Image_Signif" dataType="string" value="11.33" ucd="stat.snr" unit="sigma"/>
  37 + <Param name="Bkg_Inten" dataType="string" value="29359" ucd="phot.count" unit="cts"/>
  38 + <Param name="Bkg_Time" dataType="string" value="00:24:06.37" ucd="time.start"/>
  39 + <Param name="Bkg_Dur" dataType="string" value="8.00" ucd="time.duration" unit="sec"/>
  40 + <Param name="SC_Long" dataType="string" value="88.68" ucd="pos.earth.lon" unit="deg"/>
  41 + <Param name="SC_Lat" dataType="string" value="18.32" ucd="pos.earth.lat" unit="deg"/>
  42 + <Param name="Coords_Type" dataType="string" value="1" unit="dn"/>
  43 + <Param name="Coords_String" dataType="string" value="source_object"/>
  44 + <Group name="Merit_Values">
  45 + <Param name="Merit_Val0" dataType="string" value="1" unit="dn"/>
  46 + <Param name="Merit_Val1" dataType="string" value="0" unit="dn"/>
  47 + <Param name="Merit_Val2" dataType="string" value="0" unit="dn"/>
  48 + <Param name="Merit_Val3" dataType="string" value="0" unit="dn"/>
  49 + <Param name="Merit_Val4" dataType="string" value="2" unit="dn"/>
  50 + <Param name="Merit_Val5" dataType="string" value="1" unit="dn"/>
  51 + <Param name="Merit_Val6" dataType="string" value="0" unit="dn"/>
  52 + <Param name="Merit_Val7" dataType="string" value="0" unit="dn"/>
  53 + <Param name="Merit_Val8" dataType="string" value="4" unit="dn"/>
  54 + <Param name="Merit_Val9" dataType="string" value="0" unit="dn"/>
  55 + </Group>
  56 + <Group name="Solution_Status">
  57 + <Param name="Point_Source" dataType="string" value="true"/>
  58 + <Param name="GRB_Identified" dataType="string" value="true"/>
  59 + <Param name="Target_of_Interest" dataType="string" value="false"/>
  60 + <Param name="Target_Imag_Trig" dataType="string" value="false"/>
  61 + <Param name="Target_Rate_Trig" dataType="string" value="true"/>
  62 + <Param name="Def_NOT_a_GRB" dataType="string" value="false"/>
  63 + <Param name="Hi_Bkg_Level" dataType="string" value="false"/>
  64 + <Param name="Neg_Bkg_Slope" dataType="string" value="false"/>
  65 + <Param name="Lo_Image_Signif" dataType="string" value="false"/>
  66 + <Param name="VERY_Lo_Image_Signif" dataType="string" value="false"/>
  67 + <Param name="Target_in_Flt_Catalog" dataType="string" value="false"/>
  68 + <Param name="Target_in_Gnd_Catalog" dataType="string" value="false"/>
  69 + <Param name="Target_in_Blk_Catalog" dataType="string" value="false"/>
  70 + <Param name="StarTrack_Lost_Lock" dataType="string" value="false"/>
  71 + <Param name="Near_Bright_Star" dataType="string" value="false"/>
  72 + <Param name="Src_Removed_from_OnBoard" dataType="string" value="false"/>
  73 + <Param name="Converted_SubThresh" dataType="string" value="false"/>
  74 + <Param name="Spatial_Prox_Match" dataType="string" value="false"/>
  75 + <Param name="Temporal_Prox_Match" dataType="string" value="false"/>
  76 + <Param name="Test_Submission" dataType="string" value="false"/>
  77 + </Group>
  78 + <Group name="Misc_Flags">
  79 + <Param name="Values_Out_of_Range" dataType="string" value="false"/>
  80 + <Param name="Near_Bright_Star" dataType="string" value="false"/>
  81 + <Param name="Err_Circle_in_Galaxy" dataType="string" value="false"/>
  82 + <Param name="Galaxy_in_Err_Circle" dataType="string" value="false"/>
  83 + <Param name="ImTrig_during_ST_LoL" dataType="string" value="false"/>
  84 + <Param name="TOO_Generated" dataType="string" value="false"/>
  85 + <Param name="Trig_time_is_SecHdrTime" dataType="string" value="false"/>
  86 + <Param name="Delayed_Transmission" dataType="string" value="false"/>
  87 + <Param name="Updated_Notice" dataType="string" value="false"/>
  88 + <Param name="Flt_Generated" dataType="string" value="true"/>
  89 + <Param name="Gnd_Generated" dataType="string" value="false"/>
  90 + <Param name="SERS_Generated" dataType="string" value="false"/>
  91 + <Param name="Other_Generated" dataType="string" value="false"/>
  92 + <Param name="CRC_Error" dataType="string" value="false"/>
  93 + </Group>
  94 + <Group name="Obs_Support_Info">
  95 + <Param name="Sun_RA" dataType="string" value="165.99" ucd="pos.eq.ra" unit="deg"/>
  96 + <Param name="Sun_Dec" dataType="string" value="5.99" ucd="pos.eq.dec" unit="deg"/>
  97 + <Param name="Sun_Distance" dataType="string" value="92.05" ucd="pos.angDistance" unit="deg"/>
  98 + <Param name="Sun_Hr_Angle" dataType="string" value="6.07" unit="hr"/>
  99 + <Param name="Moon_RA" dataType="string" value="55.91" ucd="pos.eq.ra" unit="deg"/>
  100 + <Param name="Moon_Dec" dataType="string" value="19.78" ucd="pos.eq.dec" unit="deg"/>
  101 + <Param name="MOON_Distance" dataType="string" value="34.56" ucd="pos.angDistance" unit="deg"/>
  102 + <Param name="Moon_Illum" dataType="string" value="64.40" ucd="arith.ratio" unit="%"/>
  103 + <Param name="Galactic_Long" dataType="string" value="208.46" ucd="pos.galactic.lon" unit="deg"/>
  104 + <Param name="Galactic_Lat" dataType="string" value="-29.19" ucd="pos.galactic.lat" unit="deg"/>
  105 + <Param name="Ecliptic_Long" dataType="string" value="72.20" ucd="pos.ecliptic.lon" unit="deg"/>
  106 + <Param name="Ecliptic_Lat" dataType="string" value="-31.82" ucd="pos.ecliptic.lat" unit="deg"/>
  107 + <Description>The Sun and Moon values are valid at the time the VOEvent XML message was created.</Description>
  108 + </Group>
  109 + <Description>Type=61: The Swift-BAT instrument position notice.</Description>
  110 + </What>
  111 +
  112 + <WhereWhen>
  113 + <ObsDataLocation>
  114 + <ObservatoryLocation id="GEOLUN"/>
  115 + <ObservationLocation>
  116 + <AstroCoordSystem id="UTC-FK5-GEO"/>
  117 + <AstroCoords coord_system_id="UTC-FK5-GEO">
  118 + <Time unit="s">
  119 + <TimeInstant>
  120 + <ISOTime>2012-09-07T00:24:23.08</ISOTime>
  121 + </TimeInstant>
  122 + </Time>
  123 + <Position2D unit="deg">
  124 + <Name1>RA</Name1>
  125 + <Name2>Dec</Name2>
  126 + <Value2>
  127 + <C1>74.741200</C1>
  128 + <C2>25.313700</C2>
  129 + </Value2>
  130 + <Error2Radius>0.050000</Error2Radius>
  131 + </Position2D>
  132 + </AstroCoords>
  133 + </ObservationLocation>
  134 + </ObsDataLocation>
  135 + <Description>The RA,Dec coordinates are of the type: source_object.</Description>
  136 + </WhereWhen>
  137 +
  138 + <How>
  139 + <Description>Swift Satellite, BAT Instrument</Description>
  140 + <Reference type="url" uri="http://gcn.gsfc.nasa.gov/swift.html"/>
  141 + </How>
  142 +
  143 + <Why importance="0.900000">
  144 + <Inference probability="0.98">
  145 + <Name>GRB 120907</Name>
  146 + <Concept>process.variation.burst;em.gamma</Concept>
  147 + </Inference>
  148 + </Why>
  149 +
  150 + <Description>
  151 + </Description>
  152 +</voe:VOEvent>
  153 +
... ...
src/alert_manager/StrategyBuilder.py
... ... @@ -6,24 +6,30 @@ from common.models import *
6 6 JD1 = 0
7 7 JD2 = 9000000
8 8  
  9 +'''
  10 + Reads a strategy file and creates a new request with it
  11 +
  12 + ENTRY POINT :
  13 + - create_request_from_strategy
  14 +'''
  15 +
  16 +
9 17 class StrategyBuilder():
  18 +
  19 + def validate(self):
  20 + self.rb.validate_request()
  21 + return self.rb.request
  22 +
10 23 '''
11   - Reads a strategy file and creates a new request with it
12   -
13   - ENTRY POINT :
14   - - create_request_from_strategy
15   - '''
  24 + Reads the strategy file, and creates the request, saving everything in DB
16 25  
  26 + :param : strategy_file, the name of the strategy file with .xml but without the path
  27 + :param : pyros_user, the user associated with the existing alert
  28 + :param : scientific_program, the sci prog of the existing alert
  29 + :param : name, the name of the existing request + name of the strategy
  30 + :returns : the created request
  31 + '''
17 32 def create_request_from_strategy(self, strategy_file, pyros_user, scientific_program, name):
18   - '''
19   - Reads the strategy file, and creates the request, saving everything in DB
20   -
21   - :param : strategy_file, the name of the strategy file with .xml but without the path
22   - :param : pyros_user, the user associated with the existing alert
23   - :param : scientific_program, the sci prog of the existing alert
24   - :param : name, the name of the existing request + name of the strategy
25   - :returns : the created request
26   - '''
27 33  
28 34 tree = ET.parse(os.path.join('alert_manager', 'strategies', strategy_file))
29 35 request = tree.getroot()
... ... @@ -53,7 +59,3 @@ class StrategyBuilder():
53 59 def add_plan(self, plan, album_id, name):
54 60 self.rb.add_plan(album_id, plan.get('filter'), plan.get('duration'),
55 61 plan.get('nb_images'), name=name)
56   -
57   - def validate(self):
58   - self.rb.validate_request()
59   - return self.rb.request
... ...
src/alert_manager/tasks.py
... ... @@ -110,7 +110,7 @@ class AlertListener(Task):
110 110 return
111 111  
112 112 alert.strat = StrategyObs.objects.filter(is_default=True)[0]
113   - name = "GRB - " + str(alert.trig_id)
  113 + name = "GRB-" + str(alert.trig_id)
114 114  
115 115 Log.objects.create(agent="Alert manager", message="Creating alert from file : %s ..." % (alert.strat.xml_file,))
116 116 sb = StrategyBuilder()
... ...
src/alert_manager/tests.py
... ... @@ -23,10 +23,6 @@ class TestStrategyChange(TestCase):
23 23 fixtures = ['tests/alert_mgr_test.json']
24 24  
25 25 def setUp(self):
26   - '''
27   - Creates the base for the tests
28   - '''
29   -
30 26 self.alert = Alert.objects.get()
31 27 self.strat1 = Alert.objects.get().strategyobs
32 28 self.strat2 = StrategyObs.objects.exclude(id=self.strat1.id)[0]
... ... @@ -61,7 +57,7 @@ class TestStrategyChange(TestCase):
61 57 new_alert = Alert.objects.exclude(id=self.alert.id)[0]
62 58 self.assertEqual(new_alert.strategyobs.id, self.strat2.id, "The new alert should have the 'strat2' strategy")
63 59  
64   -
  60 +# OBSOLETE
65 61 class AlertListenerTestsCelery(TestCase):
66 62 '''
67 63 IMPORTANT : As soon as you do a DB request in a test, the test DB will no longer be synchronized with the DB used by celery
... ...
src/common/RequestBuilder.py
... ... @@ -19,6 +19,7 @@ class RequestBuilder():
19 19 self.sequences = {}
20 20 self.albums = {}
21 21 self.plans = {}
  22 + self.is_alert = is_alert
22 23  
23 24 def add_sequence(self, priority, jd1, jd2, t_prefered=-1, name="default", duration=0):
24 25 '''
... ... @@ -32,7 +33,7 @@ class RequestBuilder():
32 33 "start_new_request MUST be invoked before creating any sequence")
33 34  
34 35 sequence = Sequence(name=name, status=Sequence.TOBEPLANNED, priority=priority,
35   - jd1=jd1, jd2=jd2, t_prefered=t_prefered, duration=duration)
  36 + jd1=jd1, jd2=jd2, t_prefered=t_prefered, duration=duration, is_alert=self.is_alert)
36 37 self.sequences[self.sequence_id] = sequence
37 38 self.sequence_id += 1
38 39 return self.sequence_id - 1
... ...
simulators/resources/voevent_alert_04.xml renamed to src/external_modules/__init__.py
src/external_modules/exposure.py 0 โ†’ 100644
... ... @@ -0,0 +1,5 @@
  1 +from utils.Logger import *
  2 +
  3 +
  4 +class ExposureCalculator(Logger):
  5 + pass
... ...
src/external_modules/image_simulator.py 0 โ†’ 100644
... ... @@ -0,0 +1,5 @@
  1 +from utils.Logger import *
  2 +
  3 +
  4 +class ImageSimulator(Logger):
  5 + pass
... ...
src/external_modules/visibility_calculator.py 0 โ†’ 100644
... ... @@ -0,0 +1,12 @@
  1 +from utils.Logger import *
  2 +
  3 +'''
  4 + Class made to manage the sequences visibility
  5 +'''
  6 +
  7 +
  8 +class VisibilityCalculator(Logger):
  9 +
  10 + # Return the visible interval
  11 + def getVisibleInterval(self, coordinates) -> tuple:
  12 + return (0, 20000)
... ...
src/majordome/tasks.py
... ... @@ -138,6 +138,7 @@ class Majordome(Task):
138 138 self.timer_status = 5
139 139 self.tasks_timer = 5
140 140 self.timer_plc = 2
  141 + self.alert_timer = 1
141 142 self.timer_schedule = 1
142 143 self.timer_sequence = 1
143 144  
... ... @@ -273,6 +274,7 @@ class Majordome(Task):
273 274 if (schedule.created != self.schedule.created):
274 275 self.next_sequence = None
275 276 self.schedule = schedule
  277 + self.firstSequenceIsAlert()
276 278 if (self.schedule):
277 279 shs_list = self.schedule.shs.filter(Q(status=Sequence.PLANNED) |
278 280 Q(status=Sequence.PENDING)).order_by('tsp')
... ... @@ -282,6 +284,20 @@ class Majordome(Task):
282 284 return (0)
283 285  
284 286 '''
  287 + Function called by handleScheduleTimer, the purpose is to kill the executing sequence if the
  288 + first sequence in the new planning is from an alert
  289 + '''
  290 + @executingSequenceExist
  291 + def firstSequenceIsAlert(self):
  292 + shs_list = self.schedule.shs.filter(Q(status=Sequence.PLANNED) |
  293 + Q(status=Sequence.PENDING)).order_by('tsp')
  294 + if shs_list and shs_list[0].sequence.is_alert:
  295 + if shs_list[0].sequence.created.date() >= (datetime.datetime.now() - datetime.timedelta(seconds=10)).date():
  296 + self.killExecutingSequence()
  297 + return 1
  298 + return 0
  299 +
  300 + '''
285 301 Function called by the main loop to handle the end of a night
286 302 '''
287 303 def handleNightEndTimer(self):
... ...