Commit e5cec6d95cf4d0e06749d683301464fe4ea12292

Authored by Alain Klotz
1 parent 7fd005b5
Exists in dev

Update scheduler

Showing 1 changed file with 35 additions and 17 deletions   Show diff stats
src/core/pyros_django/scheduling/A_Scheduler.py
... ... @@ -32,7 +32,7 @@ if pwd not in sys.path:
32 32  
33 33 short_paths = ['src', 'src/core/pyros_django']
34 34 for short_path in short_paths:
35   - path = os.path.join(pwd, short_path)
  35 + path = os.path.abspath(os.path.join(pwd, short_path))
36 36 if path not in sys.path:
37 37 sys.path.insert(0, path)
38 38  
... ... @@ -128,6 +128,7 @@ class A_Scheduler(Agent):
128 128 # === Status of routine processing
129 129 self._routine_running = self.RUNNING_NOTHING
130 130 log.debug("end init()")
  131 + ##### TBD suppress redondant paths in print(f"=>=>=> {sys.path=}")
131 132  
132 133 # Note : called by _routine_process() in Agent
133 134 # @override
... ... @@ -151,7 +152,7 @@ class A_Scheduler(Agent):
151 152 =================================================================
152 153 """
153 154  
154   - def do_ccreate_seq_1(self, nb_seq:int):
  155 + def do_create_seq_1(self, nb_seq:int):
155 156 """Create sequences to debug
156 157 """
157 158 self._create_seq_1(nb_seq)
... ... @@ -213,7 +214,7 @@ class A_Scheduler(Agent):
213 214 No token.
214 215 """
215 216 t0 = time.time()
216   - #self.DPRINT = True
  217 + self.DPRINT = True
217 218 # --- Get the incoming directory of the night
218 219 info = self.get_infos()
219 220 rootdir = info['rootdir']
... ... @@ -225,8 +226,13 @@ class A_Scheduler(Agent):
225 226 seqfiles = glob.glob(wildcard)
226 227 log.info(f"{len(seqfiles)} file sequences to process")
227 228 # --- Initialize the schedule
228   - schedule = np.zeros(86400, dtype=int) -1
  229 + schedule_sequence_id = np.zeros(86400, dtype=int) -1
229 230 schedule_binary = np.ones(86400, dtype=int)
  231 + schedule_visibility = np.zeros(86400, dtype=float)
  232 + schedule_order = np.zeros(86400, dtype=int) -1
  233 + schedule_jd = np.zeros(86400, dtype=float)
  234 + schedule_scientific_programm_id = np.zeros(86400, dtype=int) -1
  235 +
230 236 # ===================================================================
231 237 # --- Loop over the sequences of the night to extract useful infos
232 238 # ===================================================================
... ... @@ -282,6 +288,7 @@ class A_Scheduler(Agent):
282 288 else:
283 289 sequence_info['error'] = f"File {ephfile} not exists"
284 290 sequence_infos.append(sequence_info)
  291 + schedule_jd = eph_info['jd']
285 292  
286 293 # ===================================================================
287 294 # --- Get informations of priority and quota from scientific programs
... ... @@ -337,7 +344,7 @@ class A_Scheduler(Agent):
337 344 scientific_program_info = scientific_program_infos[str(scientific_program_id)]
338 345 priority = scientific_program_info['priority']
339 346 # Order of the following list refers to the enum
340   - seq = [ k, sequence_info['id'], sequence_info['kobs0'], scientific_program_id, priority, int(np.ceil(sequence_info['duration'])), self.SEQ_NOT_PROCESSED ]
  347 + seq = [ k, sequence_info['id'], sequence_info['kobs0'], scientific_program_id, priority, int(np.ceil(sequence_info['duration'])), self.SEQ_NOT_PROCESSED]
341 348 self.dprint(f"{seq=}")
342 349 seqs[k] = seq
343 350 k += 1
... ... @@ -363,9 +370,12 @@ class A_Scheduler(Agent):
363 370 # --- Insert sequences in the schedule. Respecting priority and quota
364 371 # ===================================================================
365 372 self.dprint("\n" + "="*70 + "\n=== Insertion of the sequences in the schedule respecting priority and quota\n" + "="*70 + "\n")
366   - for seq in seq_sorteds:
  373 + kseq_sorted = -1
  374 + for seq_sorted in seq_sorteds:
  375 + kseq_sorted += 1
  376 +
367 377 # --- Unpack the sequence
368   - k, sequence_id, kobs0, scientific_program_id, priority, duration, seq_status = seq
  378 + k, sequence_id, kobs0, scientific_program_id, priority, duration, seq_status = seq_sorted
369 379  
370 380 # --- Get the quota remaining of the scientific program
371 381 quota_remaining = scientific_program_infos[str(scientific_program_id)]['quota_remaining']
... ... @@ -421,12 +431,16 @@ class A_Scheduler(Agent):
421 431 seqs[k][self.SEQ_STATUS] = self.SEQ_SCHEDULED
422 432  
423 433 # --- Update the schedule arrays
424   - schedule[k1:k2] = sequence_id
  434 + schedule_sequence_id[k1:k2] = sequence_id
425 435 schedule_binary[k1:k2] = 0
  436 + schedule_visibility[k1:k2] = sequence_info['visibility'][k1:k2]
  437 + schedule_order[k1:k2] = kseq_sorted
  438 + schedule_scientific_programm_id[k1:k2] = scientific_program_id
426 439  
427 440 # --- Update the scientific program dict
428 441 quota_remaining -= duration
429 442 scientific_program_infos[str(scientific_program_id)]['quota_remaining'] = quota_remaining
  443 +
430 444  
431 445 # ===================================================================
432 446 # --- Insert sequences in the schedule. Respecting priority but over quota
... ... @@ -443,7 +457,7 @@ class A_Scheduler(Agent):
443 457 self.dprint("Order ID_seq K_start ID_sp Priority Duration Status\n")
444 458 self.dprint(f"{seqs=}")
445 459 fpathname = os.path.join(rootdir, subdir, "scheduler_schedule.txt")
446   - np.savetxt(fpathname, np.array([schedule, schedule_binary]).T)
  460 + np.savetxt(fpathname, np.array([schedule_jd, schedule_binary, schedule_sequence_id, schedule_scientific_programm_id, schedule_order, schedule_visibility]).T)
447 461 # --- Update the running state
448 462 self._routine_running = self.RUNNING_NOTHING
449 463 print(f"_compute_schedule_1 finished in {time.time() - t0:.2f} seconds")
... ... @@ -452,6 +466,7 @@ class A_Scheduler(Agent):
452 466 t0 = time.time()
453 467 self.dprint("Debut _create_seq_1")
454 468 seq_template = {'sequence': {'id': 4, 'start_expo_pref': 'IMMEDIATE', 'pyros_user': 2, 'scientific_program': 1, 'name': 'seq_20230628T102140', 'desc': None, 'last_modified_by': 2, 'is_alert': False, 'status': 'TBP', 'with_drift': False, 'priority': None, 'analysis_method': None, 'moon_min': None, 'alt_min': None, 'type': None, 'img_current': None, 'img_total': None, 'not_obs': False, 'obsolete': False, 'processing': False, 'flag': None, 'period': 1, 'start_date': datetime.datetime(2023, 6, 28, 10, 21, 40, tzinfo=zoneinfo.ZoneInfo(key='UTC')), 'end_date': datetime.datetime(2023, 6, 28, 10, 21, 40, 999640, tzinfo=datetime.timezone.utc), 'jd1': Decimal('0E-8'), 'jd2': Decimal('0E-8'), 'tolerance_before': '1s', 'tolerance_after': '1min', 'duration': -1.0, 'overhead': Decimal('0E-8'), 'submitted': False, 'config_attributes': {'tolerance_before': '1s', 'tolerance_after': '1min', 'target': 'RADEC 0H10M -15D', 'conformation': 'WIDE', 'layout': 'Altogether'}, 'ra': None, 'dec': None, 'complete': True, 'night_id': '20230627'}, 'albums': {'Altogether': {'plans': [{'id': 4, 'album': 4, 'duration': 0.0, 'nb_images': 1, 'config_attributes': {'binnings': {'binxy': [1, 1], 'readouttime': 6}, 'exposuretime': 1.0}, 'complete': True}]}}}
  469 + # decode general variables info a dict info
455 470 info = self.get_infos()
456 471 rootdir = info['rootdir']
457 472 subdir = info['subdir']
... ... @@ -460,12 +475,15 @@ class A_Scheduler(Agent):
460 475 duskelev = -7
461 476 eph = guitastro.Ephemeris()
462 477 eph.set_home(self.config.getHome())
463   - #print("Debut _create_seq_1 SUN")
464   - ephem_sun = eph.target2night("sun", info['night'], None, None)
465   - #print("Debut _create_seq_1 MOON")
  478 + print(f"Debut _create_seq_1 SUN {info['night']=}")
  479 + try:
  480 + ephem_sun = eph.target2night("sun", info['night'], None, None)
  481 + except Exception as e:
  482 + print(f"{e.message=} {e.args=}")
  483 + print(f"Debut _create_seq_1 MOON {eph.target2night=}")
466 484 ephem_moon = eph.target2night("moon", info['night'], None, None)
467 485 # --- Horizon (TBD get from config)
468   - #print("Debut _create_seq_1 Horizon")
  486 + print("Debut _create_seq_1 Horizon")
469 487 hor = guitastro.Horizon(eph.home)
470 488 hor.horizon_altaz = [ [0,0], [360,0] ]
471 489 # --- Delete all existing *.p and *.f files in the night directory
... ... @@ -520,15 +538,15 @@ class A_Scheduler(Agent):
520 538 seq['sequence']['config_attributes']['target'] = target
521 539 # --- Build the path and file name of the sequence file
522 540 fn_param["id_seq"] = k
523   - #print(f"{k} : {self._fn.fcontext=}")
  541 + print(f"{k} : {self._fn.fcontext=}")
524 542 self._fn.fname = self._fn.naming_set(fn_param)
525   - #print(f"{k} : {self._fn.fname=}")
  543 + print(f"{k} : {self._fn.fname=}")
526 544 seq_file = self._fn.join(self._fn.fname)
527   - #print(f"{k} : {seq_file=}")
  545 + print(f"{k} : {seq_file=}")
528 546 # --- Build the path and file name of the ephemeris file
529 547 eph_file = f"{seq_file[:-2]}.f"
530 548 # --- Create directory if it doesn't exist
531   - #print(f"{k} : {seq_file=}")
  549 + print(f"{k} : {seq_file=}")
532 550 os.makedirs(os.path.dirname(seq_file), exist_ok=True)
533 551 # --- Compute the ephemeris of the sequence and manage errors
534 552 #print(f"{k} : TRY")
... ...