Commit ef35b851f3763e59207eaa10580b13c62d57f271
1 parent
3f1744c1
Exists in
dev
add eph sun & moon for eph seq & calculation for duration
Showing
1 changed file
with
35 additions
and
5 deletions
Show diff stats
src/core/pyros_django/seq_submit/functions.py
... | ... | @@ -163,6 +163,17 @@ def check_sequence_file_validity_and_save(yaml_content: dict, request: HttpReque |
163 | 163 | if Period.objects.next_period() != None and Period.objects.next_period().start_date < seq.start_date.date(): |
164 | 164 | period = Period.objects.next_period() |
165 | 165 | seq.period = period |
166 | + # Sum seq duration | |
167 | + duration = 0 | |
168 | + max_duration = 0 | |
169 | + for album in seq.albums.all(): | |
170 | + for plan in album.plans.all(): | |
171 | + duration = plan.nb_images * (plan.config_attributes.get("exposuretime",0) + plan.config_attributes.get("readouttime",0)) | |
172 | + plan.duration = duration | |
173 | + plan.save() | |
174 | + if duration >= max_duration: | |
175 | + max_duration = duration | |
176 | + seq.duration = max_duration | |
166 | 177 | fn = guitastro.FileNames() |
167 | 178 | home = config.getHome() |
168 | 179 | guitastro_home = guitastro.Home(home) |
... | ... | @@ -315,6 +326,9 @@ def process_sequence(yaml_content, seq, config, is_simplified, result, user_sp): |
315 | 326 | |
316 | 327 | if is_simplified: |
317 | 328 | seq.scientific_program = sp_list[yaml_content["sequence"]["scientific_program"]] |
329 | + if yaml_content["sequence"].get("id"): | |
330 | + seq.id = yaml_content["sequence"].get("id") | |
331 | + seq.save() | |
318 | 332 | else: |
319 | 333 | # get scientific program field's attributes |
320 | 334 | yaml_seq_sp = yaml_content["sequence"]["scientific_program"] |
... | ... | @@ -415,7 +429,6 @@ def process_sequence(yaml_content, seq, config, is_simplified, result, user_sp): |
415 | 429 | # else associate field & value in config_attributes sequence's field (JsonField) = variable fields of an sequence |
416 | 430 | seq.config_attributes[field] = value |
417 | 431 | |
418 | - | |
419 | 432 | def create_sequence_pickle(sequence): |
420 | 433 | seq_dict = model_to_dict(sequence) |
421 | 434 | fullseq_dict = { |
... | ... | @@ -442,8 +455,6 @@ def create_sequence_pickle(sequence): |
442 | 455 | config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"], unit_name) |
443 | 456 | pyros_config = ConfigPyros(os.environ["pyros_config_file"]) |
444 | 457 | config.fn.fcontext = "pyros_seq" |
445 | - home = guitastro.Home(config.getHome()) | |
446 | - config.fn.longitude(home.longitude) | |
447 | 458 | period_id = str(period.id) |
448 | 459 | if len(str(period.id)) < 3: |
449 | 460 | while len(period_id) < 3: |
... | ... | @@ -455,6 +466,12 @@ def create_sequence_pickle(sequence): |
455 | 466 | "date": sequence.night_id, |
456 | 467 | "id_seq": sequence.id |
457 | 468 | } |
469 | + test_mode = False | |
470 | + if sequence.id >= 9990000000: | |
471 | + # in test mode | |
472 | + config.fn.rootdir = os.path.abspath(config.fn.rootdir.replace("PRODUCTS/","PRODUCTS/TESTS/", 1)) | |
473 | + test_mode = True | |
474 | + | |
458 | 475 | config.fn.fname = config.fn.naming_set(fn_param) |
459 | 476 | fpath_name = config.fn.join(config.fn.fname) |
460 | 477 | # create dirs if they don't exist |
... | ... | @@ -466,9 +483,22 @@ def create_sequence_pickle(sequence): |
466 | 483 | duskelev = -7 |
467 | 484 | errors = [] |
468 | 485 | try: |
469 | - # TODO remplacer les none par les fichiers pickle de ephem_sun & ephem_moon | |
470 | 486 | #fullseq_dict["ephem"] = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, None, None, preferance=sequence.start_expo_pref, duskelev=duskelev) |
471 | - ephem = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, None, None, preference=sequence.start_expo_pref, duskelev=duskelev) | |
487 | + # change fcontext to eph context | |
488 | + config.fn.fcontext = "pyros_eph" | |
489 | + if test_mode: | |
490 | + config.fn.rootdir = os.path.abspath(config.fn.rootdir.replace("PRODUCTS/","PRODUCTS/TESTS/", 1)) | |
491 | + eph_root_dir = config.fn.rootdir | |
492 | + fn_param["target"] = "sun" | |
493 | + config.fn.fname = config.fn.naming_set(fn_param) | |
494 | + sun_eph_fpath = config.fn.join(config.fn.fname) | |
495 | + fn_param["target"] = "moon" | |
496 | + config.fn.fname = config.fn.naming_set(fn_param) | |
497 | + moon_eph_fpath = config.fn.join(config.fn.fname) | |
498 | + # open eph files | |
499 | + sun_eph = pickle.load(open(sun_eph_fpath,"rb")) | |
500 | + moon_eph = pickle.load(open(moon_eph_fpath,"rb")) | |
501 | + ephem = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, sun_eph, moon_eph, preference=sequence.start_expo_pref, duskelev=duskelev) | |
472 | 502 | except ValueError: |
473 | 503 | errors.append("Target value is not valid") |
474 | 504 | except guitastro.ephemeris.EphemerisException as ephemException: | ... | ... |