diff --git a/src/core/pyros_django/seq_submit/functions.py b/src/core/pyros_django/seq_submit/functions.py index a775399..cc22a22 100644 --- a/src/core/pyros_django/seq_submit/functions.py +++ b/src/core/pyros_django/seq_submit/functions.py @@ -163,6 +163,17 @@ def check_sequence_file_validity_and_save(yaml_content: dict, request: HttpReque if Period.objects.next_period() != None and Period.objects.next_period().start_date < seq.start_date.date(): period = Period.objects.next_period() seq.period = period + # Sum seq duration + duration = 0 + max_duration = 0 + for album in seq.albums.all(): + for plan in album.plans.all(): + duration = plan.nb_images * (plan.config_attributes.get("exposuretime",0) + plan.config_attributes.get("readouttime",0)) + plan.duration = duration + plan.save() + if duration >= max_duration: + max_duration = duration + seq.duration = max_duration fn = guitastro.FileNames() home = config.getHome() guitastro_home = guitastro.Home(home) @@ -315,6 +326,9 @@ def process_sequence(yaml_content, seq, config, is_simplified, result, user_sp): if is_simplified: seq.scientific_program = sp_list[yaml_content["sequence"]["scientific_program"]] + if yaml_content["sequence"].get("id"): + seq.id = yaml_content["sequence"].get("id") + seq.save() else: # get scientific program field's attributes yaml_seq_sp = yaml_content["sequence"]["scientific_program"] @@ -415,7 +429,6 @@ def process_sequence(yaml_content, seq, config, is_simplified, result, user_sp): # else associate field & value in config_attributes sequence's field (JsonField) = variable fields of an sequence seq.config_attributes[field] = value - def create_sequence_pickle(sequence): seq_dict = model_to_dict(sequence) fullseq_dict = { @@ -442,8 +455,6 @@ def create_sequence_pickle(sequence): config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"], unit_name) pyros_config = ConfigPyros(os.environ["pyros_config_file"]) config.fn.fcontext = "pyros_seq" - home = guitastro.Home(config.getHome()) - config.fn.longitude(home.longitude) period_id = str(period.id) if len(str(period.id)) < 3: while len(period_id) < 3: @@ -455,6 +466,12 @@ def create_sequence_pickle(sequence): "date": sequence.night_id, "id_seq": sequence.id } + test_mode = False + if sequence.id >= 9990000000: + # in test mode + config.fn.rootdir = os.path.abspath(config.fn.rootdir.replace("PRODUCTS/","PRODUCTS/TESTS/", 1)) + test_mode = True + config.fn.fname = config.fn.naming_set(fn_param) fpath_name = config.fn.join(config.fn.fname) # create dirs if they don't exist @@ -466,9 +483,22 @@ def create_sequence_pickle(sequence): duskelev = -7 errors = [] try: - # TODO remplacer les none par les fichiers pickle de ephem_sun & ephem_moon #fullseq_dict["ephem"] = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, None, None, preferance=sequence.start_expo_pref, duskelev=duskelev) - ephem = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, None, None, preference=sequence.start_expo_pref, duskelev=duskelev) + # change fcontext to eph context + config.fn.fcontext = "pyros_eph" + if test_mode: + config.fn.rootdir = os.path.abspath(config.fn.rootdir.replace("PRODUCTS/","PRODUCTS/TESTS/", 1)) + eph_root_dir = config.fn.rootdir + fn_param["target"] = "sun" + config.fn.fname = config.fn.naming_set(fn_param) + sun_eph_fpath = config.fn.join(config.fn.fname) + fn_param["target"] = "moon" + config.fn.fname = config.fn.naming_set(fn_param) + moon_eph_fpath = config.fn.join(config.fn.fname) + # open eph files + sun_eph = pickle.load(open(sun_eph_fpath,"rb")) + moon_eph = pickle.load(open(moon_eph_fpath,"rb")) + ephem = eph.target2night(fullseq_dict["sequence"]["config_attributes"]["target"], sequence.night_id, sun_eph, moon_eph, preference=sequence.start_expo_pref, duskelev=duskelev) except ValueError: errors.append("Target value is not valid") except guitastro.ephemeris.EphemerisException as ephemException: -- libgit2 0.21.2