def mod_spec(self): print("MOD SPEC") # Check spec data if not self.check_info(): return # Retrieve spectrograph data from entries spec_info = SpecInfo(self.nameEntry.get(), int(rm_spaces(self.minHEntry.get())), int(rm_spaces(self.maxHEntry.get())), int(rm_spaces(self.imageHEntry.get())), int(rm_spaces(self.rowEntry.get()))) spec_file_name = "spectrographs.csv" spec_file_path = opt.join(CURR_DIR, spec_file_name) with open(spec_file_path, "r") as spec_file: records = spec_file.readlines() # Modify only the corresponding record records[self._specIndex] = (spec_info.to_csv() + "\n") spec_file.close() with open(spec_file_path, "w") as spec_file: spec_file.writelines(records) spec_file.close() # Update spectrographs list self.update_spec_list(spec_info.name) print("Spectrograph modified correctly") self.close() return
def add_spec(self): print("ADD SPEC") # Check spec data if not self.check_info(): return # Retrieve spectrograph data from entries spec_info = SpecInfo(self.nameEntry.get(), int(rm_spaces(self.minHEntry.get())), int(rm_spaces(self.maxHEntry.get())), int(rm_spaces(self.imageHEntry.get())), int(rm_spaces(self.rowEntry.get()))) # Add a new record in the csv file spec_file_name = "spectrographs.csv" spec_file_path = opt.join(CURR_DIR, spec_file_name) with open(spec_file_path, "a") as spec_file: spec_file.write(spec_info.to_csv() + "\n") spec_file.close() # Update spectrographs list self.update_spec_list(spec_info.name) print("Spectrograph added correctly") self.close() return
def check_info(self): check_flag = True print("Checking inserted spectrograph data...") if not rm_spaces(self.nameEntry.get()): print("Error: insert a spectrograph name!") mtk.entry_err_blink(self.nameEntry) check_flag = False if not str_is_positive_int(rm_spaces(self.minHEntry.get())): print("Error: invalid minimum pixel height!") mtk.entry_err_blink(self.minHEntry) check_flag = False if not str_is_positive_int(rm_spaces(self.maxHEntry.get())): print("Error: invalid maximum pixel height!") mtk.entry_err_blink(self.maxHEntry) check_flag = False if not str_is_positive_int(rm_spaces(self.imageHEntry.get())): print("Error: invalid image height!") mtk.entry_err_blink(self.imageHEntry) check_flag = False if not str_is_positive_int(rm_spaces(self.rowEntry.get())): print("Error: invalid maximum file length!") mtk.entry_err_blink(self.rowEntry) check_flag = False return check_flag
def select_ref(self): print("SELECT REF") # Check ref name print("Checking inserted name...") ref_name = rm_spaces(self.refEntry.get()) if not ref_name: print("Error: insert a star name!") mtk.entry_err_blink(self.refEntry) return for i in range(0, self.starListDim): if ref_name != self.starListWindow.starEntries[i].get(): continue # Set reference star print("Setting the reference star...") self.refName = ref_name mtk.clear_Entry(self.refEntry) self.curRefLabel.configure(state=tk.NORMAL) mtk.clear_Entry(self.curRefEntry, tk.NORMAL) self.curRefEntry.insert(0, ref_name) self.curRefEntry.configure(state="readonly") self.starListWindow.refLabel.configure(state=tk.NORMAL) mtk.clear_Entry(self.starListWindow.refEntry, tk.NORMAL) self.starListWindow.refEntry.insert(0, ref_name) self.starListWindow.refEntry.configure(state="readonly") self.starListWindow.refPoseLabel.configure(state=tk.NORMAL) self.starListWindow.refPoseEntry.configure(state=tk.NORMAL) print("Reference star set successfully") return print("Error: invalid reference star name!") mtk.entry_err_blink(self.refEntry) return
def start_session(self): print("START SESSION") err_flag = False master_flag = self.master.masterFlag self.master.starList = [] print("Checking environment...") # Check workspace directory ws_path = self.master.wsPath if not os.path.exists(ws_path): print("Error: workspace directory doesn't exist!") err_flag = True # Check star list length list_dim = self.master.starListDim if list_dim == 0: print("Error: star list is empty!") err_flag = True # Check reference pose ref_pose_str = rm_spaces(self.refPoseEntry.get()) if not str_is_positive_int(ref_pose_str): print("Error: illegal reference pose value!") mtk.entry_err_blink(self.refPoseEntry) self.master.refPose = None err_flag = True else: self.master.refPose = int(ref_pose_str) # Check and retrieve stars information print("Checking star list information...") for i in range(0, list_dim): star_entry = self.starEntries[i].get() poses_entry_str = rm_spaces(self.posesEntries[i].get()) flat_entry_str = rm_spaces(self.flatEntries[i].get()) neon_entry_str = rm_spaces(self.neonEntries[i].get()) dark_entry_str = rm_spaces(self.darkEntries[i].get()) standard_entry = rm_spaces(self.standardEntries[i].get()) std_poses = None std_flag = False if not str_is_positive_int(poses_entry_str): print("Error: illegal poses value for star: " + star_entry + "!") mtk.entry_err_blink(self.posesEntries[i]) star_poses = None err_flag = True else: star_poses = int(poses_entry_str) if not str_is_positive_int(flat_entry_str): print("Error: illegal flat value for star: " + star_entry + "!") mtk.entry_err_blink(self.flatEntries[i]) star_flat = None err_flag = True else: star_flat = int(flat_entry_str) if not str_is_positive_int(neon_entry_str): print("Error: illegal neon value for star: " + star_entry + "!") mtk.entry_err_blink(self.neonEntries[i]) star_neon = None err_flag = True else: star_neon = int(neon_entry_str) if not str_is_positive_int(dark_entry_str): print("Error: illegal dark time value for star: " + star_entry + "!") mtk.entry_err_blink(self.darkEntries[i]) star_dark = None err_flag = True else: star_dark = int(dark_entry_str) if not is_standard(star_entry): if not standard_entry or not is_standard(standard_entry): print("Error: invalid standard for star: " + star_entry + "!") mtk.entry_err_blink(self.standardEntries[i]) standard_entry = None err_flag = True else: for j in range(0, list_dim): if standard_entry != self.starEntries[j].get(): continue std_poses_entry = rm_spaces(self.posesEntries[j].get()) if not str_is_positive_int(std_poses_entry): print("Error: illegal poses value for standard: " + standard_entry + "!") mtk.entry_err_blink(self.posesEntries[j]) err_flag = True else: std_poses = int(std_poses_entry) std_flag = True break else: standard_entry = None std_flag = True if not std_flag: print("Error: standard not found for star: " + star_entry + "!") mtk.entry_err_blink(self.standardEntries[i]) standard_entry = None err_flag = True star_info = StarInfo(star_entry, star_poses, star_flat, star_neon, star_dark, standard_entry, std_poses) self.master.starList.append(star_info) # Retrieve spectrograph data spec_info = get_spec_info(self.master.specVal.get()) if spec_info is None: # Quite impossible error, it's just for the sake of security... print("Error: invalid spectrograph!") err_flag = True if err_flag: return star_list = self.master.starList # CREATE IRAF FILES print("Creating session files...") mf.make_Pulizia0(ws_path) mf.make_CreaDarkati(ws_path, star_list, list_dim) mf.make_ListaGenerale(ws_path, star_list, list_dim) mf.make_ListaBiassati(ws_path, star_list, list_dim) mf.make_FLAT(ws_path, star_list, list_dim) mf.make_Pulizia1(ws_path) mf.make_GeneraMasterFlat(ws_path, star_list, list_dim, spec_info.min_h_pixel, spec_info.max_h_pixel, spec_info.h_image, spec_info.l_row) mf.make_ListaFlattati(ws_path, star_list, list_dim) mf.make_ListaTracciamoStelle(ws_path, star_list, list_dim) mf.make_Pulizia2(ws_path) mf.make_NEON(ws_path, star_list, list_dim) mf.make_GeneraMasterNeon(ws_path, star_list, list_dim) mf.make_ListaApallNe(ws_path, star_list, list_dim) mf.make_ListaReidentify(ws_path, star_list, list_dim, self.master.refName, self.master.refPose) mf.make_ListaChiConChi(ws_path, star_list, list_dim) mf.make_ListaCalibraLambda(ws_path, star_list, list_dim) mf.make_STANDARD(ws_path, star_list, list_dim) mf.make_DaFlussare(ws_path, star_list, list_dim) mf.make_Flussati(ws_path, star_list, list_dim) mf.make_HelioRename(ws_path, star_list, list_dim) mf.make_RvCorrected(ws_path, star_list, list_dim) mf.make_PreparoHelio(ws_path, star_list, list_dim) mf.make_Mediana(ws_path, star_list, list_dim) mf.make_Pulizia3(ws_path, star_list, list_dim) mf.make_Pulizia4(ws_path) mf.make_ListaInizio(ws_path, master_flag) print("Session files have been created successfully") # Enable Synthesis button self.master.synButton.configure(state=tk.NORMAL) # Disable first part self.master.wsButton.configure(state=tk.DISABLED) self.master.wsLabel.configure(state=tk.DISABLED) self.master.wsEntry.configure(state=tk.DISABLED) self.master.starButton.configure(state=tk.DISABLED) self.master.starLabel.configure(state=tk.DISABLED) self.master.starEntry.configure(state=tk.DISABLED) self.master.refButton.configure(state=tk.DISABLED) self.master.refLabel.configure(state=tk.DISABLED) self.master.refEntry.configure(state=tk.DISABLED) self.master.curRefLabel.configure(state=tk.DISABLED) self.master.curRefEntry.configure(state=tk.DISABLED) self.master.specLabel.configure(state=tk.DISABLED) self.master.specOptions.configure(state=tk.DISABLED) self.master.addSpecButton.configure(state=tk.DISABLED) self.master.modSpecButton.configure(state=tk.DISABLED) self.master.delSpecButton.configure(state=tk.DISABLED) # Close star list window print("Closing star list window...") self.master.starListWindow = None self.destroy() return
def add_master(self, master_type): print("ADD MASTER (" + master_type + ")") bias_flag = (master_type == BIAS) err_flag = False if bias_flag: print("Checking inserted bias poses value...") poses_entry = self.biasPosesEntry else: print("Checking inserted dark poses and time values...") poses_entry = self.darkPosesEntry time_entry = self.darkTimeEntry master_time = rm_spaces(time_entry.get()) print("Checking master time...") if not str_is_positive_int(master_time): print("Error: invalid master time value!") err_flag = True else: master_time = int(master_time) if not (self.masterListWindow is None): for i in range(0, self.masterListDim): if self.masterListWindow.typeEntries[i].get() == BIAS: continue i_time = int( self.masterListWindow.timeEntries[i].get()) if master_time == i_time: print( "Error: master dark with such pose time already exists!" ) err_flag = True break master_poses = rm_spaces(poses_entry.get()) print("Checking master poses...") if not str_is_positive_int(master_poses): print("Error: invalid master poses value!") err_flag = True else: master_poses = int(master_poses) if err_flag: mtk.entry_err_blink(poses_entry) if master_type == DARK: mtk.entry_err_blink(time_entry) return mtk.clear_Entry(poses_entry) if bias_flag: self.biasButton.configure(state=tk.DISABLED) self.biasPosesLabel.configure(state=tk.DISABLED) self.biasPosesEntry.configure(state=tk.DISABLED) else: mtk.clear_Entry(time_entry) self.masterListDim += 1 self.masterFlag = True if self.masterListWindow is None: # Open dark list window print("Opening master list window...") self.masterListWindow = MasterListWindow() list_dim = self.masterListDim list_frame = self.masterListWindow.listFrame print("Adding the master to the list...") new_remove_button = mtk.make_Button( list_frame, text="-", row=list_dim, pady=1, command=lambda to_remove=list_dim: self.remove_master(to_remove)) self.masterListWindow.removeButtons.append(new_remove_button) new_type_entry = mtk.make_Entry(list_frame, text=master_type, row=list_dim, column=1, padx=2, width=6, sticky=tk.EW, state="readonly") self.masterListWindow.typeEntries.append(new_type_entry) new_poses_entry = mtk.make_Entry(list_frame, text=master_poses, row=list_dim, column=2, padx=2, width=6, sticky=tk.EW, state="readonly") self.masterListWindow.posesEntries.append(new_poses_entry) new_time_entry = mtk.make_Entry(list_frame, row=list_dim, column=3, padx=2, width=6, sticky=tk.EW) if bias_flag: new_time_entry.configure(state=tk.DISABLED) else: new_time_entry.insert(0, master_time) new_time_entry.configure(state="readonly") self.masterListWindow.timeEntries.append(new_time_entry) # Resize master list window self.masterListWindow = resized_window(self.masterListWindow, list_dim, MASTERL_EN_HG) print("New master added successfully") return
def add_star(self): print("ADD STAR") # Check star name print("Checking inserted name...") star_name = rm_spaces(self.starEntry.get()) mtk.clear_Entry(self.starEntry) if not star_name: print("Error: insert a star name!") mtk.entry_err_blink(self.starEntry) return elif self.starListWindow is None: # Open star list window print("Opening star list window...") self.starListWindow = StarListWindow() self.refButton.configure(state=tk.NORMAL) self.refLabel.configure(state=tk.NORMAL) self.refEntry.configure(state=tk.NORMAL) else: for i in range(0, self.starListDim): i_star = self.starListWindow.starEntries[i].get() if star_name == i_star: print("Error: star is already in the list!") mtk.entry_err_blink(self.starEntry) return mtk.clear_Entry(self.starEntry) self.starListDim += 1 list_dim = self.starListDim list_frame = self.starListWindow.listFrame # Add new record on the star list window print("Adding a new record on the star list window...") new_remove_button = mtk.make_Button( list_frame, text="-", row=list_dim, pady=1, command=lambda to_remove=list_dim: self.remove_star(to_remove)) self.starListWindow.removeButtons.append(new_remove_button) new_star_entry = mtk.make_Entry(list_frame, text=star_name, row=list_dim, column=1, padx=2, width=20, sticky=tk.EW, state="readonly") self.starListWindow.starEntries.append(new_star_entry) new_pose_entry = mtk.make_Entry(list_frame, row=list_dim, column=2, width=6, sticky=tk.EW) self.starListWindow.posesEntries.append(new_pose_entry) new_flat_entry = mtk.make_Entry(list_frame, text=5, row=list_dim, column=3, width=6, sticky=tk.EW) self.starListWindow.flatEntries.append(new_flat_entry) new_neon_entry = mtk.make_Entry(list_frame, text=3, row=list_dim, column=4, width=6, sticky=tk.EW) self.starListWindow.neonEntries.append(new_neon_entry) new_dark_entry = mtk.make_Entry(list_frame, row=list_dim, column=5, width=6, sticky=tk.EW) self.starListWindow.darkEntries.append(new_dark_entry) new_standard_entry = mtk.make_Entry(list_frame, row=list_dim, column=6, width=10, sticky=tk.EW) if is_standard(star_name): new_standard_entry.configure(state=tk.DISABLED) self.starListWindow.standardEntries.append(new_standard_entry) # Resize star list window self.starListWindow = resized_window(self.starListWindow, self.starListDim, STARL_EN_HG) print("New star added successfully") return