def __init__(self, log): MainWindow.__init__(self, log, name='HOPS - Reduction', position=2) fits_name = find_fits_files(self.log.get_param('observation_files'))[0] fits = get_fits_data(fits_name) y_scale = (self.root.winfo_screenheight() - 500) / self.root.winfo_screenheight() self.progress_figure = self.FitsWindow(figsize=(0.5, y_scale, 10, 10, len(fits[0].data[0])/len(fits[0].data))) self.progress_figure.load_fits(fits[0], input_name=os.path.split(fits_name)[1]) self.progress_bias = self.Progressbar(task="Creating master bias") self.progress_dark = self.Progressbar(task="Creating master dark") self.progress_flat = self.Progressbar(task="Creating master flat") self.progress_science = self.Progressbar(task="Reducing data and calculating statistics") self.progress_science_loop = self.CheckButton(text='Show all frames', initial=0) self.setup_window([ [[self.progress_figure, 0, 2]], [[self.progress_bias, 0, 2]], [[self.progress_dark, 0, 2]], [[self.progress_flat, 0, 2]], [[self.progress_science, 0], [self.progress_science_loop, 1]], [[self.Button(text='STOP REDUCTION & RETURN TO MAIN MENU', command=self.trigger_exit), 0, 2]], [] ]) self.set_close_button_function(self.trigger_exit)
def run_reduction(self): if self.log.get_param('reduction_complete'): if self.askyesno('Overwrite files', 'Reduction has been completed, do you want to run again?'): self.log.set_param('reduction_complete', False) self.log.save_local_log() else: self.log.set_param('proceed', True) self.show() if not self.log.get_param('reduction_complete'): if not os.path.isdir(self.log.reduction_directory): os.mkdir(self.log.reduction_directory) else: shutil.rmtree(self.log.reduction_directory) os.mkdir(self.log.reduction_directory) self.bias_files = find_fits_files(self.log.get_param('bias_files')) self.bias_frames = [] self.bias_counter = 0 self.dark_files = find_fits_files(self.log.get_param('dark_files')) self.dark_frames = [] self.dark_counter = 0 self.flat_files = find_fits_files(self.log.get_param('flat_files')) self.flat_frames = [] self.flat_counter = 0 self.science_files = find_fits_files(self.log.get_param('observation_files')) self.all_frames = {} self.science_counter = 0 self.psf = 10 self.after(self.get_bias) else: self.close()
def update_observation_files(self, *event): check = find_fits_files(self.observation_files.get()) self.science_files = len(check) if self.science_files == 0: self.observation_files_test.set( '{0} files found\nyou cannot proceed'.format(len(check))) self.science_header = [] header_list = [' Keywords: Values:', ' '] else: self.observation_files_test.set('{0} files found - OK'.format( len(check))) self.science_header = [] header_list = [' Keywords: Values:', ' '] self.science_header = get_fits_data(check[0])[0].header for ii in self.science_header: if ii != '': header_list.append(' {0}{1}{2}'.format( str(ii[:10]), ' ' * (15 - len(str(ii[:10]))), str(self.science_header[ii]))) self.header_list.update_list(header_list) self.update_exposure_time_key() self.update_observation_date_key() self.update_observation_time_key() self.update_ra_dec() self.choose_target() self.update_observing_info() self.update_save_button()
def __init__(self, log): MainWindow.__init__(self, log, name='HOPS - Data & Target', position=2) # extra windows self.content_window = AddOnWindow(self, name='Files list', sizex=3, sizey=3, position=1) self.header_window = AddOnWindow(self, name='Header keywords list', sizex=3, sizey=3, position=7) self.target_window = AddOnWindow(self, name='Select Target') # set variables, create and place widgets # main window self.directory_test = self.Label( text=self.log.get_param('directory_short')) self.observation_files = self.Entry( value=self.log.get_param('observation_files'), instance=str, command=self.update_observation_files) self.observation_files_test = self.Label(text=' ') self.science_files = 0 self.science_header = [] self.show_files_button = self.Button(text='Show files', command=self.content_window.show) self.bias_files = self.Entry(value=self.log.get_param('bias_files'), instance=str, command=self.update_bias_files) self.bias_files_test = self.Label(text=' ') self.dark_files = self.Entry(value=self.log.get_param('dark_files'), instance=str, command=self.update_dark_files) self.dark_files_test = self.Label(text=' ') self.flat_files = self.Entry(value=self.log.get_param('flat_files'), instance=str, command=self.update_flat_files) self.flat_files_test = self.Label(text=' ') try: initial_bin = self.log.get_param('bin_fits') initial_bin = max(1, initial_bin) initial_bin = min(initial_bin, 4) except: print( 'WARNING the bin_fits parameter should be 1, 2, 3 or 4. Re-setting it to 1.' ) initial_bin = 1 self.bin_fits = self.DropDown(initial=initial_bin, options=[1, 2, 3, 4], instance=int) self.show_header_button = self.Button(text='Show header', command=self.header_window.show) self.exposure_time_key = self.Entry( value=self.log.get_param('exposure_time_key'), instance=str, command=self.update_exposure_time_key) self.exposure_time_key_test = self.Label(text=' ') self.observation_date_key = self.Entry( value=self.log.get_param('observation_date_key'), instance=str, command=self.update_observation_date_key) self.observation_date_key_test = self.Label(text=' ') self.observation_time_key = self.Entry( value=self.log.get_param('observation_time_key'), instance=str, command=self.update_observation_time_key) self.observation_time_key_test = self.Label(text=' ') self.time_stamp = self.DropDown( initial=self.log.get_param('time_stamp'), options=['exposure start', 'mid-exposure', 'exposure end']) self.select_target_button = self.Button( text='CHOOSE TARGET', command=self.update_ra_dec_options) self.target_ra_dec = self.Label( text=self.log.get_param('target_ra_dec')) self.target_name = self.Label(text=self.log.get_param('target_name')) self.target_ra_dec_test = self.Label(text='') self.observer = self.Entry(value=self.log.get_param('observer')) self.observatory = self.Entry(value=self.log.get_param('observatory')) self.telescope = self.Entry(value=self.log.get_param('telescope')) self.camera = self.Entry(value=self.log.get_param('camera')) filters = ['default'] + list(filter_map.keys()) if self.log.get_param('filter') not in filters: self.log.set_param('filter', 'default') self.filter = self.DropDown(initial=self.log.get_param('filter'), options=filters, command=self.check_filter) self.filter_test = self.Label(text=' ') self.save_and_return_button = self.Button( text='SAVE OPTIONS & RETURN TO MAIN MENU', command=self.save_and_return) self.save_and_proceed_button = self.Button( text='SAVE OPTIONS & PROCEED', command=self.save_and_proceed, bg='green', highlightbackground='green') self.setup_window([ [], [[ self.Button(text='CHOOSE DIRECTORY', command=self.update_directory), 1 ], [self.directory_test, 2, 2]], [[self.show_files_button, 2]], [[self.Label(text='Name identifier for observation files'), 1], [self.observation_files, 2], [self.observation_files_test, 3]], [[self.Label(text='Name identifier for bias files'), 1], [self.bias_files, 2], [self.bias_files_test, 3]], [[self.Label(text='Name identifier for dark files'), 1], [self.dark_files, 2], [self.dark_files_test, 3]], [ [self.Label(text='Name identifier for flat files'), 1], [self.flat_files, 2], [self.flat_files_test, 3], ], [[self.Label(text='Bin fits files (reduced only)'), 1], [self.bin_fits, 2]], [[self.show_header_button, 2]], [[self.Label(text='Exposure time header keyword'), 1], [self.exposure_time_key, 2], [self.exposure_time_key_test, 3]], [ [ self.Label( text= 'Observation date header keyword\n(no JD, HJD, BJD)'), 1 ], [self.observation_date_key, 2], [self.observation_date_key_test, 3], ], [[self.Label(text='Observation time header keyword'), 1], [self.observation_time_key, 2], [self.observation_time_key_test, 3]], [[ self.Label( text='Time-stamp\n(which time is saved in your fits files?)' ), 1 ], [self.time_stamp, 2]], [], [[self.select_target_button, 1], [self.target_ra_dec, 2], [self.target_ra_dec_test, 3]], [[self.target_name, 2]], [[self.Label(text='Observer'), 1], [self.observer, 2], [self.Label(text='OK'), 3]], [[self.Label(text='Observatory'), 1], [self.observatory, 2], [self.Label(text='OK'), 3]], [[self.Label(text='Telescope'), 1], [self.telescope, 2], [self.Label(text='OK'), 3]], [[self.Label(text='Camera'), 1], [self.camera, 2], [self.Label(text='OK'), 3]], [[self.Label(text='Filter'), 1], [self.filter, 2], [self.filter_test, 3]], [], [[ self.Button(text='RETURN TO MAIN MENU', command=self.close), 1, 6 ]], [[self.save_and_return_button, 1, 6]], [[self.save_and_proceed_button, 1, 6]], [] ], entries_wd=self.log.entries_width) # files window self.content_list = self.content_window.ListDisplay() self.content_window.setup_window([[[self.content_list, 0]]]) content_list = [' List of files in your directory:', ' '] xx = find_fits_files('*') for ii in xx: content_list.append(' {0}'.format(str(ii).split(os.sep)[-1])) self.content_list.update_list(content_list) # headers window self.header_list = self.header_window.ListDisplay() self.header_window.setup_window([[[self.header_list, 0]]]) self.stars = plc.open_dict( os.path.join(plc.databases.oec, 'stars_catalogue.pickle')) self.stars = { self.stars[ff]['simbad_id']: self.stars[ff]['planets'][0] for ff in self.stars } # target window self.target_ra_dec_choice = self.target_window.IntVar( self.log.get_param('target_ra_dec_choice')) self.target_ra_dec_choice_0 = self.target_window.Radiobutton( text='Use the RA/DEC found in the file\'s header:', variable=self.target_ra_dec_choice, value=0, command=self.update_ra_dec) self.target_ra_dec_choice_1 = self.target_window.Radiobutton( text='Provide the name of the target:', variable=self.target_ra_dec_choice, value=1, command=self.update_ra_dec) self.target_ra_dec_choice_2 = self.target_window.Radiobutton( text='Provide the RA/DEC of the target\n(hh:mm:ss +/-dd:mm:ss):', variable=self.target_ra_dec_choice, value=2, command=self.update_ra_dec) self.auto_target_ra_dec = self.target_window.Label( text=self.log.get_param('auto_target_ra_dec')) self.auto_target_ra_dec_check = self.target_window.Label(text='') self.simbad_target_name = self.target_window.Entry( value=self.log.get_param('simbad_target_name'), command=self.update_ra_dec) self.simbad_target_name_check = self.target_window.Label(text='') self.manual_target_ra_dec = self.target_window.Entry( value=self.log.get_param('manual_target_ra_dec'), command=self.update_ra_dec) self.target_ra_dec_2 = self.target_window.Label( text=self.log.get_param('target_ra_dec')) self.target_name_2 = self.target_window.Label( text=self.log.get_param('target_name')) self.target_window.setup_window([ [], [[ self.target_window.Label( text= 'How would you like to choose your target? Select one of the three options:' ), 0, 5 ]], [], [[self.target_ra_dec_choice_0, 1], [self.auto_target_ra_dec, 2, 2], [self.auto_target_ra_dec_check, 4]], [[self.target_ra_dec_choice_1, 1], [self.simbad_target_name, 2, 2], [self.simbad_target_name_check, 4]], [[self.target_ra_dec_choice_2, 1], [self.manual_target_ra_dec, 2, 2]], [], [[self.target_window.Label(text='Target RA/DEC: '), 0], [self.target_ra_dec_2, 1, 3]], [[self.target_window.Label(text='Target Name: '), 0], [self.target_name_2, 1, 3]], [], [[ self.target_window.Button(text=' Cancel ', command=self.target_window.hide), 2 ], [ self.target_window.Button(text=' Choose ', command=self.choose_target), 3 ]], [] ], entries_wd=self.log.entries_width) self.update_observation_files() self.update_bias_files() self.update_dark_files() self.update_flat_files()
def update_flat_files(self, *event): check = find_fits_files(self.flat_files.get()) self.flat_files_test.set('{0} files found - OK'.format(len(check))) self.update_save_button()
def update_directory(self, *event): new_directory = self.askdirectory() if len(new_directory) > 0: self.log.set_param('directory', new_directory) self.log.set_param('directory_short', os.path.split(new_directory)[1]) self.log.load_main_log() self.log.load_local_log_profile() try: os.chdir(self.log.get_param('directory')) self.log.load_local_log() except: try: os.chdir(self.log.get_param('directory')) self.log.initiate_local_log() except: os.chdir(self.log.__home__) self.log.set_param('directory', 'Choose Directory') self.log.set_param('directory_short', 'Choose Directory') self.log.save_local_log_user() content_list = [' List of files in your directory:', ' '] xx = find_fits_files('*') for ii in xx: content_list.append(' {0}'.format(str(ii).split(os.sep)[-1])) self.content_list.update_list(content_list) self.directory_test.set(self.log.get_param('directory_short')) self.observation_files.set(self.log.get_param('observation_files')) self.bias_files.set(self.log.get_param('bias_files')) self.dark_files.set(self.log.get_param('dark_files')) self.flat_files.set(self.log.get_param('flat_files')) self.bin_fits.set(self.log.get_param('bin_fits')) self.target_ra_dec_choice.set( self.log.get_param('target_ra_dec_choice')) self.target_ra_dec.set(self.log.get_param('target_ra_dec')) self.target_name.set(self.log.get_param('target_name')) self.auto_target_ra_dec.set( self.log.get_param('auto_target_ra_dec')) self.manual_target_ra_dec.set( self.log.get_param('manual_target_ra_dec')) self.simbad_target_name.set( self.log.get_param('simbad_target_name')) self.time_stamp.set(self.log.get_param('time_stamp')) self.exposure_time_key.set(self.log.get_param('exposure_time_key')) self.observation_date_key.set( self.log.get_param('observation_date_key')) self.observation_time_key.set( self.log.get_param('observation_time_key')) self.update_observation_files() self.update_bias_files() self.update_dark_files() self.update_flat_files() self.show()