def __init__(self, view, controller): self.controller = controller self.view = view next_obs_kb_id = wx.NewId() prev_obs_kb_id = wx.NewId() accept_src_kb_id = wx.NewId() reject_src_kb_id = wx.NewId() reset_cmap_kb_id = wx.NewId() view.Bind(wx.EVT_MENU, self.on_next_obs_keybind, id=next_obs_kb_id) view.Bind(wx.EVT_MENU, self.on_prev_obs_keybind, id=prev_obs_kb_id) view.Bind(wx.EVT_MENU, self.on_accept_src_keybind, id=accept_src_kb_id) view.Bind(wx.EVT_MENU, self.on_reject_src_keybind, id=reject_src_kb_id) view.Bind(wx.EVT_MENU, self.on_reset_cmap_keybind, id=reset_cmap_kb_id) accept_key = config.read("KEYBINDS.ACCEPT_SRC") reject_key = config.read("KEYBINDS.REJECT_SRC") reset_cmap_key = config.read("KEYBINDS.RESET_CMAP") accelerators = wx.AcceleratorTable( [ (wx.ACCEL_NORMAL, wx.WXK_TAB, next_obs_kb_id), (wx.ACCEL_SHIFT, wx.WXK_TAB, prev_obs_kb_id), (wx.ACCEL_NORMAL, ord(accept_key), accept_src_kb_id), (wx.ACCEL_NORMAL, ord(reject_key), reject_src_kb_id), (wx.ACCEL_NORMAL, ord(reset_cmap_key), reset_cmap_kb_id), ] ) view.SetAcceleratorTable(accelerators)
def __init__(self, slice_rows=None, slice_cols=None, vosclient=None): """ Constructor. Args: resolver: Resolves source readings to the URI's from which they can be retrieved. slice_rows, slice_cols: int The number of rows and columns (pixels) to slice out around the source. Leave as None to use default configuration values. """ # If not provided, read defaults from application config file if slice_rows is None: slice_rows = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS") if slice_cols is None: slice_cols = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS") self.slice_rows = slice_rows self.slice_cols = slice_cols if vosclient is None: self.vosclient = vos.Client(cadc_short_cut=True) else: self.vosclient = vosclient self.cutout_calculator = CutoutCalculator(slice_rows, slice_cols)
def build_source_reading(self, expnum, ccd, X, Y): """ Given the location of a source in the image, create a source reading. """ image_uri = storage.dbimages_uri(expnum=expnum, ccd=None, version='p', ext='.fits', subdir=None) logger.debug('Trying to access {}'.format(image_uri)) if not storage.exists(image_uri, force=False): logger.warning('Image not in dbimages? Trying subdir.') image_uri = storage.dbimages_uri(expnum=expnum, ccd=ccd, version='p') if not storage.exists(image_uri, force=False): logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri) return None slice_rows=config.read("CUTOUTS.SINGLETS.SLICE_ROWS") slice_cols=config.read("CUTOUTS.SINGLETS.SLICE_COLS") if X == -9999 or Y == -9999 : logger.warning("Skipping {} as x/y not resolved.".format(image_uri)) return None if not (-slice_cols/2. < X < 2048+slice_cols/2. and -slice_rows/2. < Y < 4600+slice_rows/2.0): logger.warning("Central location ({},{}) off image cutout.".format(X,Y)) return None mopheader_uri = storage.dbimages_uri(expnum=expnum, ccd=ccd, version='p', ext='.mopheader') if not storage.exists(mopheader_uri, force=False): # ELEVATE! we need to know to go off and reprocess/include this image. logger.critical('Image exists but processing incomplete. Mopheader missing. {}'.format(image_uri)) return None mopheader = get_mopheader(expnum, ccd) # Build astrom.Observation observation = astrom.Observation(expnum=str(expnum), ftype='p', ccdnum=str(ccd), fk="") observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2) observation.header = mopheader return observation
def on_accept(self): """ Initiates acceptance procedure, gathering required data. """ if self.model.is_current_source_named(): provisional_name = self.model.get_current_source_name() else: provisional_name = self._generate_provisional_name() band = self.model.get_current_band() default_comment = "" phot_failure = False source_cutout = self.model.get_current_cutout() pixel_x = source_cutout.pixel_x pixel_y = source_cutout.pixel_y try: cen_x, cen_y, obs_mag, obs_mag_err = self.model.get_current_source_observed_magnitude() except TaskError as error: phot_failure = True obs_mag = "" cen_x = pixel_x cen_y = pixel_y obs_mag_err = -1 band = "" default_comment = str(error) if math.sqrt( (cen_x - pixel_x)**2 + (cen_y - pixel_y)**2 ) > 1.5: # check if the user wants to use the 'hand' coordinates or these new ones. self.view.draw_error_ellipse(cen_x, cen_y, 10, 10, 0, color='r') self.view.show_offset_source_dialog((cen_x, cen_y), (pixel_x,pixel_y)) else: source_cutout.update_pixel_location((cen_x, cen_y)) self.model.get_current_cutout()._adjusted = False if self.model.is_current_source_adjusted(): note1_default = config.read("MPC.NOTE1_HAND_ADJUSTED") else: note1_default = None self.view.show_accept_source_dialog( provisional_name, self.model.get_current_observation_date(), self.model.get_current_ra(), self.model.get_current_dec(), obs_mag, obs_mag_err, band, note1_choices=config.read("MPC.NOTE1OPTIONS"), note2_choices=config.read("MPC.NOTE2OPTIONS"), note1_default=note1_default, note2_default=config.read("MPC.NOTE2DEFAULT"), default_observatory_code=config.read("MPC.DEFAULT_OBSERVATORY_CODE"), default_comment=default_comment, phot_failure=phot_failure )
def should_exit_prompt(parent): dialog = wx.MessageDialog(parent, config.read("UI.ALLPROC.MSG"), caption=config.read("UI.ALLPROC.CAPTION"), style=wx.YES_NO | wx.ICON_INFORMATION) user_choice = dialog.ShowModal() dialog.Destroy() return True if user_choice == wx.ID_YES else False
def __init__(self, controller, track_mode=False): size = (config.read("UI.DIMENSIONS.WIDTH"), config.read("UI.DIMENSIONS.HEIGHT")) super(MainFrame, self).__init__(None, title="Moving Object Pipeline", size=size) self.track_mode = track_mode self.controller = controller self._init_ui_components() # needed for keybinds to work on startup self.main_panel.SetFocus()
def __init__(self, view, controller): self.controller = controller self.view = view next_obs_kb_id = wx.NewId() prev_obs_kb_id = wx.NewId() accept_src_kb_id = wx.NewId() reject_src_kb_id = wx.NewId() reset_cmap_kb_id = wx.NewId() reset_src_kb_id = wx.NewId() autoplay_kb_id = wx.NewId() load_comparison_kb_id = wx.NewId() load_diff_comparison_kb_id = wx.NewId() toggle_reticule_kb_id = wx.NewId() def bind(handler, kb_id): view.Bind(wx.EVT_MENU, handler, id=kb_id) bind(self.on_load_comparison_keybind, load_comparison_kb_id) bind(self.on_load_diff_comparison_keybind, load_diff_comparison_kb_id) bind(self.on_next_obs_keybind, next_obs_kb_id) bind(self.on_prev_obs_keybind, prev_obs_kb_id) bind(self.on_accept_src_keybind, accept_src_kb_id) bind(self.on_reject_src_keybind, reject_src_kb_id) bind(self.on_reset_cmap_keybind, reset_cmap_kb_id) bind(self.on_reset_source_location_keybind, reset_src_kb_id) bind(self.on_toggle_autoplay, autoplay_kb_id) bind(self.on_toggle_reticule, toggle_reticule_kb_id) self.accept_key = config.read("KEYBINDS.ACCEPT_SRC") self.reject_key = config.read("KEYBINDS.REJECT_SRC") self.reset_cmap_key = config.read("KEYBINDS.RESET_CMAP") self.reset_source_key = config.read("KEYBINDS.RESET_SOURCE_LOCATION") self.autoplay_key = config.read("KEYBINDS.AUTOPLAY") self.toggle_reticule_key = config.read("KEYBINDS.TOGGLE_RETICULE") self.load_comparison_key = config.read("KEYBINDS.LOAD_COMPARISON") self.load_diff_comparison_key = config.read( "KEYBINDS.LOAD_DIFF_COMPARISON") logger.debug(str(self.load_diff_comparison_key)) accelerators = wx.AcceleratorTable([ (wx.ACCEL_NORMAL, wx.WXK_TAB, next_obs_kb_id), (wx.ACCEL_SHIFT, wx.WXK_TAB, prev_obs_kb_id), (wx.ACCEL_NORMAL, ord(self.accept_key), accept_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reject_key), reject_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_cmap_key), reset_cmap_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_source_key), reset_src_kb_id), (wx.ACCEL_NORMAL, ord(self.load_comparison_key), load_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.load_diff_comparison_key), load_diff_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.autoplay_key), autoplay_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_reticule_key), toggle_reticule_kb_id), ]) view.SetAcceleratorTable(accelerators)
def on_accept(self): """Initiates acceptance procedure, gathering required data.""" preset_vals = ( self._get_provisional_name(), self.model.is_current_source_discovered(), self.model.get_current_observation_date(), self.model.get_current_ra(), self.model.get_current_dec(), self.model.get_current_source_observed_magnitude(), self.model.get_current_band(), config.read("MPC.NOTE1OPTIONS"), config.read("MPC.NOTE2OPTIONS"), config.read("MPC.NOTE2DEFAULT"), config.read("MPC.DEFAULT_OBSERVATORY_CODE") ) self.get_view().show_accept_source_dialog(preset_vals)
def __init__(self, taskname, working_directory): wx_app = wx.App(False) debug_mode = config.read("DEBUG") if debug_mode: wx.lib.inspection.InspectionTool().Show() try: factory = self.task_name_mapping[taskname]() except KeyError: raise ValueError("Unknown task: %s" % taskname) parser = AstromParser() error_handler = DownloadErrorHandler(self) downloader = ImageSliceDownloader() download_manager = AsynchronousImageDownloadManager( downloader, error_handler) directory_context = DirectoryContext(working_directory) progress_manager = ProgressManager(directory_context) builder = factory.create_workunit_builder(parser, progress_manager) workunit_provider = WorkUnitProvider(tasks.get_suffix(taskname), directory_context, progress_manager, builder) model = UIModel(workunit_provider, progress_manager, download_manager) controller = factory.create_controller(model) self.model = model self.view = controller.get_view() wx_app.MainLoop()
def __init__(self, model, controller): size = (config.read("UI.DIMENSIONS.WIDTH"), config.read("UI.DIMENSIONS.HEIGHT")) super(MainFrame, self).__init__(None, title="Moving Object Pipeline", size=size) self.model = model self.controller = controller self._init_ui_components() self.keybind_manager = KeybindManager(self, self.controller) # needed for keybinds to work on startup self.main_panel.SetFocus()
def retrieve_comparison_image(self): """ Search the DB for a comparison image for this cutout. """ # selecting comparator when on a comparator should load a new one. collectionID = self.comparison_image_list[self.comparison_image_index]['EXPNUM'] ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree radius = self.radius is not None and self.radius or config.read('CUTOUTS.SINGLETS.RADIUS') * units.arcminute try: comparison = collectionID hdu_list = storage.ra_dec_cutout(storage.dbimages_uri(comparison), SkyCoord(ref_ra, ref_dec), radius) ccd = int(hdu_list[-1].header.get('EXTVER', 0)) obs = Observation(str(comparison), 'p', ccdnum=ccd) x = hdu_list[-1].header.get('NAXIS1', 0) // 2.0 y = hdu_list[-1].header.get('NAXIS2', 0) // 2.0 ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree reading = SourceReading(x, y, self.reading.x, self.reading.y, ref_ra, ref_dec, self.reading.x, self.reading.y, obs) self.comparison_image_list[self.comparison_image_index]["REFERENCE"] = SourceCutout(reading, hdu_list) except Exception as ex: print traceback.format_exc() print ex print "Failed to load comparison image;" self.comparison_image_index = None logger.error("{} {}".format(type(ex), str(ex))) logger.error(traceback.format_exc())
def retrieve_comparison_image(self): """ Search the DB for a comparison image for this cutout. """ # selecting comparator when on a comparator should load a new one. collectionID = self.comparison_image_list[ self.comparison_image_index]['EXPNUM'] ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree radius = self.radius is not None and self.radius or config.read( 'CUTOUTS.SINGLETS.RADIUS') * units.arcminute try: comparison = collectionID hdu_list = storage.ra_dec_cutout(storage.dbimages_uri(comparison), SkyCoord(ref_ra, ref_dec), radius) ccd = int(hdu_list[-1].header.get('EXTVER', 0)) obs = Observation(str(comparison), 'p', ccdnum=ccd) x = hdu_list[-1].header.get('NAXIS1', 0) // 2.0 y = hdu_list[-1].header.get('NAXIS2', 0) // 2.0 ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree reading = SourceReading(x, y, self.reading.x, self.reading.y, ref_ra, ref_dec, self.reading.x, self.reading.y, obs) self.comparison_image_list[ self.comparison_image_index]["REFERENCE"] = SourceCutout( reading, hdu_list) except Exception as ex: print(traceback.format_exc()) print(ex) print("Failed to load comparison image;") self.comparison_image_index = None logger.error("{} {}".format(type(ex), str(ex))) logger.error(traceback.format_exc())
def __init__(self, view, controller): self.controller = controller self.view = view next_obs_kb_id = wx.NewId() prev_obs_kb_id = wx.NewId() accept_src_kb_id = wx.NewId() reject_src_kb_id = wx.NewId() reset_cmap_kb_id = wx.NewId() reset_src_kb_id = wx.NewId() autoplay_kb_id = wx.NewId() load_comparison_kb_id = wx.NewId() load_diff_comparison_kb_id = wx.NewId() toggle_reticule_kb_id = wx.NewId() def bind(handler, kb_id): view.Bind(wx.EVT_MENU, handler, id=kb_id) bind(self.on_load_comparison_keybind, load_comparison_kb_id) bind(self.on_load_diff_comparison_keybind, load_diff_comparison_kb_id) bind(self.on_next_obs_keybind, next_obs_kb_id) bind(self.on_prev_obs_keybind, prev_obs_kb_id) bind(self.on_accept_src_keybind, accept_src_kb_id) bind(self.on_reject_src_keybind, reject_src_kb_id) bind(self.on_reset_cmap_keybind, reset_cmap_kb_id) bind(self.on_reset_source_location_keybind, reset_src_kb_id) bind(self.on_toggle_autoplay, autoplay_kb_id) bind(self.on_toggle_reticule, toggle_reticule_kb_id) self.accept_key = config.read("KEYBINDS.ACCEPT_SRC") self.reject_key = config.read("KEYBINDS.REJECT_SRC") self.reset_cmap_key = config.read("KEYBINDS.RESET_CMAP") self.reset_source_key = config.read("KEYBINDS.RESET_SOURCE_LOCATION") self.autoplay_key = config.read("KEYBINDS.AUTOPLAY") self.toggle_reticule_key = config.read("KEYBINDS.TOGGLE_RETICULE") self.load_comparison_key = config.read("KEYBINDS.LOAD_COMPARISON") self.load_diff_comparison_key = config.read("KEYBINDS.LOAD_DIFF_COMPARISON") logger.debug(str(self.load_diff_comparison_key)) accelerators = wx.AcceleratorTable( [ (wx.ACCEL_NORMAL, wx.WXK_TAB, next_obs_kb_id), (wx.ACCEL_SHIFT, wx.WXK_TAB, prev_obs_kb_id), (wx.ACCEL_NORMAL, ord(self.accept_key), accept_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reject_key), reject_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_cmap_key), reset_cmap_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_source_key), reset_src_kb_id), (wx.ACCEL_NORMAL, ord(self.load_comparison_key), load_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.load_diff_comparison_key), load_diff_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.autoplay_key), autoplay_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_reticule_key), toggle_reticule_kb_id), ] ) view.SetAcceleratorTable(accelerators)
def __init__(self, working_directory, output_directory, dry_run=False, debug=False): self.dry_run = dry_run logger.info("Input directory set to: %s" % working_directory) logger.info("Output directory set to: %s" % output_directory) working_context = context.get_context(working_directory) output_context = context.get_context(output_directory) if dry_run and working_context.is_remote(): sys.stdout.write("A dry run can only be done on local files.\n") sys.exit(0) if output_context.is_remote(): sys.stdout.write("The output directory must be local.\n") sys.exit(0) image_manager = self._create_image_manager() progress_manager = working_context.get_progress_manager() builder = self._create_workunit_builder(working_context, output_context, progress_manager) workunit_provider = WorkUnitProvider(self.input_suffix, working_context, progress_manager, builder, randomize=self.should_randomize_workunits) prefetching_workunit_provider = PreFetchingWorkUnitProvider(workunit_provider, config.read("PREFETCH.NUMBER"), image_manager) if working_context.is_remote(): synchronization_manager = SynchronizationManager(working_context) else: synchronization_manager = None model = TransAckValidationModel(prefetching_workunit_provider, image_manager, synchronization_manager) logger.debug("Created model.") view = self._create_view(model, debug=debug) logger.debug("Created view.") model.start_work() self.model = model self.view = view self.controller = view.controller self.controller.display_current_image() if not synchronization_manager: self.view.disable_sync_menu() self.view.show()
def download_cutout(self, reading, focus=None, needs_apcor=False): """ Downloads a cutout of the FITS image for a given source reading. Args: reading: ossos.astrom.SourceReading The reading which will be the focus of the downloaded image. focus: tuple(int, int) The x, y coordinates that should be the focus of the downloaded image. These coordinates should be in terms of the source_reading parameter's coordinate system. Default value is None, in which case the source reading's x, y position is used as the focus. needs_apcor: bool If True, the apcor file with data needed for photometry calculations is downloaded in addition to the image. Defaults to False. Returns: cutout: ossos.downloads.data.SourceCutout """ logger.debug( "Doing download_cutout with inputs: reading:{} focus:{} needs_apcor:{}" .format(reading, focus, needs_apcor)) assert isinstance(reading, SourceReading) min_radius = config.read('CUTOUTS.SINGLETS.RADIUS') if not isinstance(min_radius, Quantity): min_radius = min_radius * units.arcsec radius = max(reading.uncertainty_ellipse.a, reading.uncertainty_ellipse.b) * 2.5 + min_radius logger.debug("got radius for cutout: {}".format(radius)) image_uri = reading.get_image_uri() logger.debug("Getting cutout at {} for {}".format( reading.reference_sky_coord, image_uri)) hdulist = storage._cutout_expnum(reading.obs, reading.reference_sky_coord, radius) # hdulist = storage.ra_dec_cutout(image_uri, reading.reference_sky_coord, radius) logger.debug("Getting the aperture correction.") source = SourceCutout(reading, hdulist, radius=radius) # Accessing the attribute here to trigger the download. try: apcor = source.apcor zmag = source.zmag source.reading.get_observation_header() except Exception as ex: if needs_apcor: import sys, traceback sys.stderr.write( "Failed to retrieve apcor but apcor required. " "Raising error, see logs for more details") sys.stderr.write(traceback.print_exc()) pass logger.debug("Sending back the source reading.") return source
def set_ds9(self, level="PREF"): """ Set the default values on the ds9 display. """ self.set_zoom() ds9_settings = config.read("DS9."+level) for key in ds9_settings.keys(): value = ds9_settings[key] cmd = key.replace("_", " ") self.ds9.set("{} {}".format(cmd, value))
def set_ds9(self, level="PREF"): """ Set the default values on the ds9 display. """ self.set_zoom() ds9_settings = config.read("DS9." + level) for key in list(ds9_settings.keys()): value = ds9_settings[key] cmd = key.replace("_", " ") self.ds9.set("{} {}".format(cmd, value))
def download_cutout(self, reading, focus=None, needs_apcor=False): """ Downloads a cutout of the FITS image for a given source reading. Args: reading: ossos.astrom.SourceReading The reading which will be the focus of the downloaded image. focus: tuple(int, int) The x, y coordinates that should be the focus of the downloaded image. These coordinates should be in terms of the source_reading parameter's coordinate system. Default value is None, in which case the source reading's x, y position is used as the focus. needs_apcor: bool If True, the apcor file with data needed for photometry calculations is downloaded in addition to the image. Defaults to False. Returns: cutout: ossos.downloads.data.SourceCutout """ logger.debug("Doing download_cutout with inputs: reading:{} focus:{} needs_apcor:{}".format(reading, focus, needs_apcor)) assert isinstance(reading, SourceReading) min_radius = config.read('CUTOUTS.SINGLETS.RADIUS') if not isinstance(min_radius, Quantity): min_radius = min_radius * units.arcsec radius = max(reading.uncertainty_ellipse.a, reading.uncertainty_ellipse.b) * 2.5 + min_radius logger.debug("got radius for cutout: {}".format(radius)) image_uri = reading.get_image_uri() logger.debug("Getting cutout at {} for {}".format(reading.reference_sky_coord, image_uri)) hdulist = storage._cutout_expnum(reading.obs, reading.reference_sky_coord, radius) # hdulist = storage.ra_dec_cutout(image_uri, reading.reference_sky_coord, radius) logger.debug("Getting the aperture correction.") source = SourceCutout(reading, hdulist, radius=radius) # Accessing the attribute here to trigger the download. try: apcor = source.apcor zmag = source.zmag source.reading.get_observation_header() except Exception as ex: if needs_apcor: import sys, traceback sys.stderr.write("Failed to retrieve apcor but apcor required. Raising error, see logs for more details") sys.stderr.write(traceback.print_exc()) pass logger.debug("Sending back the source reading.") return source
def __init__(self, slice_rows=500, slice_cols=500, radius=250, vosclient=None): """ Constructor. Args: slice_rows, slice_cols: int The number of rows and columns (pixels) to slice out around the source. Leave as None to use default configuration values. """ super(ImageCutoutDownloader, self).__init__() if slice_rows is None: slice_rows = config.read('CUTOUTS.SINGLETS.SLICE_ROWS') self.slice_rows = slice_rows if slice_cols is None: slice_cols = config.read('CUTOUTS.SINGLETS.SLICE_COLS') self.slice_cols = slice_cols if radius is None: radius = config.read('CUTOUTS.SINGLETS.RADIUS') self.radius = radius
def __init__(self, parent): # Create the actual mpl figure we will draw on self.figure = plt.figure() # Don't draw extra whitespace around image self.colorbar_height_portion = 0.05 self.axes = plt.Axes(self.figure, [0.0, self.colorbar_height_portion, 1., 1.]) self.axes.set_aspect("equal", adjustable="datalim") # Make the axes fit the image tightly self.imgwidth = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS") self.imgheight = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS") self.axes.set_xlim([0, self.imgwidth]) self.axes.set_ylim([0, self.imgheight]) # Don't draw tick marks and labels self.axes.set_axis_off() self.figure.add_axes(self.axes) # Create the canvas on which the figure is rendered self.canvas = FigureCanvas(parent, wx.ID_ANY, self.figure) self.interaction_context = InteractionContext(self) self.current_image = None self.axes_image = None self.colorbar = None self.circle = None self._has_had_interaction = False self._viewed_images = {}
def test_accept_sets_note1_to_hand_adjusted_if_current_source_adjusted(self): self.model.is_current_source_adjusted.return_value = True self.controller.on_accept() self.view.show_accept_source_dialog.assert_called_once_with( ANY, ANY, ANY, ANY, ANY, ANY, ANY, note1_choices=ANY, note2_choices=ANY, note1_default=config.read("MPC.NOTE1_HAND_ADJUSTED"), note2_default=ANY, default_observatory_code=ANY, default_comment=ANY, phot_failure=ANY)
def comparison_image_list(self): """ returns a list of possible comparison images for the current cutout. Will query CADC to create the list when first called. @rtype: Table """ if self._comparison_image_list is not None: return self._comparison_image_list ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree radius = self.radius is not None and self.radius or config.read('CUTOUTS.SINGLETS.RADIUS') * units.arcminute print "Querying CADC for list of possible comparison images at RA: {}, DEC: {}, raidus: {}".format(ref_ra, ref_dec, radius) query_result = storage.cone_search(ref_ra, ref_dec, radius, radius) # returns an astropy.table.table.Table print "Got {} possible images".format(len(query_result)) print "Building table for presentation and selection, including getting fwhm which is a bit slow." comparison_image_list = [] if len(query_result['collectionID']) > 0: # are there any comparison images even available on that sky? index = -1 for row in query_result: expnum = row['collectionID'] if expnum in self._bad_comparison_images: continue date = Time(row['mjdate'], format='mjd').mpc exptime = row['exptime'] filter_name = row['filter'] if filter_name.lower() in self.hdulist[-1].header['FILTER'].lower(): filter_name = "* {:8s}".format(filter_name) try: fwhm = "{:5.2f}".format(float(storage.get_fwhm_tag(expnum, 22))) except: fwhm = -1.00 index += 1 comparison_image_list.append([index, expnum, date, exptime, filter_name, fwhm, None]) self._comparison_image_list = Table(data=numpy.array(comparison_image_list), names=["ID", "EXPNUM", "DATE-OBS", "EXPTIME", "FILTER", "FWHM", "REFERENCE"]) return self._comparison_image_list
exptime = float(header.get('EXPTIME')) mpc_date = Time(mjd_obs, format='mjd', scale='utc', precision=5) mpc_date += TimeDelta(exptime * units.second) / 2.0 date = mpc_date.mpc obs = mpc.Observation( null_observation=False, minor_planet_number=None, provisional_name=name, discovery=True, note1=None, note2=config.read('MPC.NOTE2DEFAULT')[0], date=date, ra=cutout.ra, dec=cutout.dec, mag=obs_mag, mag_err=obs_mag_err, frame=reading.obs.rawname, band=header['FILTER'], xpos=cutout.observed_x, ypos=cutout.observed_y, comment='AUTO', astrometric_level=cutout.astrom_header.get('ASTLEVEL', None) ) source_obs.append(obs)
def read(slice_config): return config.read("CUTOUTS.%s" % slice_config)
def test_lazy_instantiation(self): assert_that(config._configs, has_length(0)) config.read("testsection1.key1", configfile=self.conffile()) assert_that(config._configs, has_length(1)) config.read("testsection1.key2", configfile=self.conffile()) assert_that(config._configs, has_length(1))
def __init__(self, model): self.model = model self.interval = config.read("DISPLAY.AUTOPLAY_INTERVAL") self._task_thread = None self._running = False
def on_accept(self): """ Initiates acceptance procedure, gathering required data. """ if self.model.is_current_source_named(): provisional_name = self.model.get_current_source_name() else: provisional_name = self._generate_provisional_name() band = self.model.get_current_band() default_comment = "" phot_failure = False source_cutout = self.model.get_current_cutout() display = ds9.ds9(target='validate') result = display.get('imexam key coordinate') values = result.split() logger.debug("IMEXAM returned {}".format(values)) cen_coords = (float(values[1]), float(values[2])) key = values[0] source_cutout.update_pixel_location(cen_coords) #source_cutout.pixel_x = float(values[1]) #source_cutout.pixel_y = float(values[2]) logger.debug("X, Y => {} , {}".format(source_cutout.pixel_x, source_cutout.pixel_y)) pixel_x = source_cutout.pixel_x pixel_y = source_cutout.pixel_y self.view.mark_apertures(self.model.get_current_cutout()) try: cen_x, cen_y, obs_mag, obs_mag_err = self.model.get_current_source_observed_magnitude( ) except Exception as error: logger.critical(str(error)) phot_failure = True obs_mag = "" cen_x = pixel_x cen_y = pixel_y obs_mag_err = -1 band = "" default_comment = str(error) if math.sqrt((cen_x - pixel_x)**2 + (cen_y - pixel_y)**2) > 1.5: # check if the user wants to use the 'hand' coordinates or these new ones. self.view.draw_error_ellipse(cen_x, cen_y, 10, 10, 0, color='r') self.view.show_offset_source_dialog((pixel_x, pixel_y), (cen_x, cen_y)) else: source_cutout.update_pixel_location((cen_x, cen_y)) self.model.get_current_cutout()._adjusted = False if self.model.is_current_source_adjusted(): note1_default = config.read("MPC.NOTE1_HAND_ADJUSTED") elif key in mpc.MPCNOTES['Note1'].keys(): note1_default = key else: note1_default = "" self.view.show_accept_source_dialog( provisional_name, self.model.get_current_observation_date(), self.model.get_current_ra(), self.model.get_current_dec(), obs_mag, obs_mag_err, band, note1_choices=config.read("MPC.NOTE1OPTIONS"), note2_choices=config.read("MPC.NOTE2OPTIONS"), note1_default=note1_default, note2_default=config.read("MPC.NOTE2DEFAULT"), default_observatory_code=config.read( "MPC.DEFAULT_OBSERVATORY_CODE"), default_comment=default_comment, phot_failure=phot_failure, pixel_x=source_cutout.pixel_x, pixel_y=source_cutout.pixel_y)
def __init__(self, working_directory, output_directory, dry_run=False, debug=False, name_filter=None, user_id=None): self.dry_run = dry_run self.user_id = user_id logger.info("Input directory set to: %s" % working_directory) logger.info("Output directory set to: %s" % output_directory) working_context = context.get_context(working_directory, userid=self.user_id) output_context = context.get_context(output_directory, userid=self.user_id) if dry_run and working_context.is_remote(): sys.stdout.write("A dry run can only be done on local files.\n") sys.exit(0) if output_context.is_remote(): sys.stdout.write("The output directory must be local.\n") sys.exit(0) image_manager = self._create_image_manager() progress_manager = working_context.get_progress_manager() builder = self._create_workunit_builder(working_context, output_context, progress_manager) workunit_provider = WorkUnitProvider( self.input_suffix, working_context, progress_manager, builder, randomize=self.should_randomize_workunits, name_filter=name_filter) prefetching_workunit_provider = PreFetchingWorkUnitProvider( workunit_provider, config.read("PREFETCH.NUMBER"), image_manager) if working_context.is_remote(): synchronization_manager = SynchronizationManager(working_context, sync_enabled=True) else: synchronization_manager = None model = TransAckValidationModel(prefetching_workunit_provider, image_manager, synchronization_manager) logger.debug("Created model.") view = self._create_view(model, debug=debug) logger.debug("Created view.") model.start_work() self.model = model self.view = view self.controller = view.controller self.controller.display_current_image() if not synchronization_manager: self.view.disable_sync_menu() self.view.show()
def test_module_read_function(self): configfile = self.conffile() assert_that(config.read("testsection1.key2", configfile), equal_to(1.2))
def __init__(self, view, controller): """ :param view: :param controller: the controller to bind this key to :type controller: AbstractController :return: """ logger.debug("Building KeybindManager.") self.controller = controller self.view = view next_obs_kb_id = wx.NewId() prev_obs_kb_id = wx.NewId() accept_src_kb_id = wx.NewId() auto_accept_src_kd_id = wx.NewId() reject_src_kb_id = wx.NewId() reset_cmap_kb_id = wx.NewId() reset_src_kb_id = wx.NewId() autoplay_kb_id = wx.NewId() load_comparison_kb_id = wx.NewId() load_diff_comparison_kb_id = wx.NewId() toggle_reticule_kb_id = wx.NewId() toggle_align_kb_id = wx.NewId() def bind(handler, kb_id): view.Bind(wx.EVT_MENU, handler, id=kb_id) bind(self.on_load_comparison_keybind, load_comparison_kb_id) bind(self.on_load_diff_comparison_keybind, load_diff_comparison_kb_id) bind(self.on_next_obs_keybind, next_obs_kb_id) bind(self.on_prev_obs_keybind, prev_obs_kb_id) bind(self.on_accept_src_keybind, accept_src_kb_id) bind(self.on_auto_accept_src_keybind, auto_accept_src_kd_id) bind(self.on_reject_src_keybind, reject_src_kb_id) bind(self.on_reset_cmap_keybind, reset_cmap_kb_id) bind(self.on_reset_source_location_keybind, reset_src_kb_id) bind(self.on_toggle_autoplay, autoplay_kb_id) bind(self.on_toggle_reticule, toggle_reticule_kb_id) bind(self.on_toggle_align, toggle_align_kb_id) self.toggle_align_key = config.read("KEYBINDS.TOGGLE_ALIGN") self.accept_key = config.read("KEYBINDS.ACCEPT_SRC") self.auto_accept_key = config.read("KEYBINDS.AUTO_ACCEPT_SRC") self.reject_key = config.read("KEYBINDS.REJECT_SRC") self.reset_cmap_key = config.read("KEYBINDS.RESET_CMAP") self.reset_source_key = config.read("KEYBINDS.RESET_SOURCE_LOCATION") self.autoplay_key = config.read("KEYBINDS.AUTOPLAY") self.toggle_reticule_key = config.read("KEYBINDS.TOGGLE_RETICULE") self.load_comparison_key = config.read("KEYBINDS.LOAD_COMPARISON") self.load_diff_comparison_key = config.read( "KEYBINDS.LOAD_DIFF_COMPARISON") accelerators = [ (wx.ACCEL_NORMAL, wx.WXK_TAB, next_obs_kb_id), (wx.ACCEL_SHIFT, wx.WXK_TAB, prev_obs_kb_id), (wx.ACCEL_NORMAL, ord(self.accept_key), accept_src_kb_id), (wx.ACCEL_NORMAL, ord(self.auto_accept_key), auto_accept_src_kd_id), (wx.ACCEL_NORMAL, ord(self.reject_key), reject_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_cmap_key), reset_cmap_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_source_key), reset_src_kb_id), (wx.ACCEL_NORMAL, ord(self.load_comparison_key), load_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.load_diff_comparison_key), load_diff_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.autoplay_key), autoplay_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_reticule_key), toggle_reticule_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_align_key), toggle_align_kb_id), ] for line in config.read("MPC.NOTE1OPTIONS"): if not len(line) > 0: continue this_key = line.split()[0][0].lower() this_func = self._build_accept_func(this_key) this_key_id = wx.NewId() bind(this_func, this_key_id) accelerators.append((wx.ACCEL_CTRL, ord(this_key), this_key_id)) accelerators = wx.AcceleratorTable(accelerators) view.SetAcceleratorTable(accelerators)
def __init__(self, view, controller): """ :param view: :param controller: the controller to bind this key to :type controller: AbstractController :return: """ logger.debug("Building KeybindManager.") self.controller = controller self.view = view next_obs_kb_id = wx.NewId() prev_obs_kb_id = wx.NewId() accept_src_kb_id = wx.NewId() auto_accept_src_kd_id = wx.NewId() reject_src_kb_id = wx.NewId() reset_cmap_kb_id = wx.NewId() reset_src_kb_id = wx.NewId() autoplay_kb_id = wx.NewId() load_comparison_kb_id = wx.NewId() load_diff_comparison_kb_id = wx.NewId() toggle_reticule_kb_id = wx.NewId() toggle_align_kb_id = wx.NewId() def bind(handler, kb_id): view.Bind(wx.EVT_MENU, handler, id=kb_id) bind(self.on_load_comparison_keybind, load_comparison_kb_id) bind(self.on_load_diff_comparison_keybind, load_diff_comparison_kb_id) bind(self.on_next_obs_keybind, next_obs_kb_id) bind(self.on_prev_obs_keybind, prev_obs_kb_id) bind(self.on_accept_src_keybind, accept_src_kb_id) bind(self.on_auto_accept_src_keybind, auto_accept_src_kd_id) bind(self.on_reject_src_keybind, reject_src_kb_id) bind(self.on_reset_cmap_keybind, reset_cmap_kb_id) bind(self.on_reset_source_location_keybind, reset_src_kb_id) bind(self.on_toggle_autoplay, autoplay_kb_id) bind(self.on_toggle_reticule, toggle_reticule_kb_id) bind(self.on_toggle_align, toggle_align_kb_id) self.toggle_align_key = config.read("KEYBINDS.TOGGLE_ALIGN") self.accept_key = config.read("KEYBINDS.ACCEPT_SRC") self.auto_accept_key = config.read("KEYBINDS.AUTO_ACCEPT_SRC") self.reject_key = config.read("KEYBINDS.REJECT_SRC") self.reset_cmap_key = config.read("KEYBINDS.RESET_CMAP") self.reset_source_key = config.read("KEYBINDS.RESET_SOURCE_LOCATION") self.autoplay_key = config.read("KEYBINDS.AUTOPLAY") self.toggle_reticule_key = config.read("KEYBINDS.TOGGLE_RETICULE") self.load_comparison_key = config.read("KEYBINDS.LOAD_COMPARISON") self.load_diff_comparison_key = config.read("KEYBINDS.LOAD_DIFF_COMPARISON") accelerators = [ (wx.ACCEL_NORMAL, wx.WXK_TAB, next_obs_kb_id), (wx.ACCEL_SHIFT, wx.WXK_TAB, prev_obs_kb_id), (wx.ACCEL_NORMAL, ord(self.accept_key), accept_src_kb_id), (wx.ACCEL_NORMAL, ord(self.auto_accept_key), auto_accept_src_kd_id), (wx.ACCEL_NORMAL, ord(self.reject_key), reject_src_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_cmap_key), reset_cmap_kb_id), (wx.ACCEL_NORMAL, ord(self.reset_source_key), reset_src_kb_id), (wx.ACCEL_NORMAL, ord(self.load_comparison_key), load_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.load_diff_comparison_key), load_diff_comparison_kb_id), (wx.ACCEL_NORMAL, ord(self.autoplay_key), autoplay_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_reticule_key), toggle_reticule_kb_id), (wx.ACCEL_NORMAL, ord(self.toggle_align_key), toggle_align_kb_id), ] for line in config.read("MPC.NOTE1OPTIONS"): if not len(line) > 0: continue this_key = line.split()[0][0].lower() this_func = self._build_accept_func(this_key) this_key_id = wx.NewId() bind(this_func, this_key_id) accelerators.append((wx.ACCEL_CTRL, ord(this_key), this_key_id)) accelerators = wx.AcceleratorTable(accelerators) view.SetAcceleratorTable(accelerators)
def on_accept(self): """ Initiates acceptance procedure, gathering required data. """ if self.model.is_current_source_named(): provisional_name = self.model.get_current_source_name() else: provisional_name = self._generate_provisional_name() band = self.model.get_current_band() default_comment = "" phot_failure = False source_cutout = self.model.get_current_cutout() display = ds9.ds9(target='validate') result = display.get('imexam key coordinate') values = result.split() logger.debug("IMEXAM returned {}".format(values)) cen_coords = (float(values[1]),float(values[2])) key = values[0] source_cutout.update_pixel_location(cen_coords) #source_cutout.pixel_x = float(values[1]) #source_cutout.pixel_y = float(values[2]) logger.debug("X, Y => {} , {}".format(source_cutout.pixel_x, source_cutout.pixel_y)) pixel_x = source_cutout.pixel_x pixel_y = source_cutout.pixel_y try: cen_x, cen_y, obs_mag, obs_mag_err = self.model.get_current_source_observed_magnitude() except TaskError as error: phot_failure = True obs_mag = "" cen_x = pixel_x cen_y = pixel_y obs_mag_err = -1 band = "" default_comment = str(error) if math.sqrt( (cen_x - pixel_x)**2 + (cen_y - pixel_y)**2 ) > 1.5: # check if the user wants to use the 'hand' coordinates or these new ones. self.view.draw_error_ellipse(cen_x, cen_y, 10, 10, 0, color='r') self.view.show_offset_source_dialog((pixel_x, pixel_y), (cen_x, cen_y)) else: source_cutout.update_pixel_location((cen_x, cen_y)) self.model.get_current_cutout()._adjusted = False if self.model.is_current_source_adjusted(): note1_default = config.read("MPC.NOTE1_HAND_ADJUSTED") elif key in mpc.MPCNOTES['Note1'].keys(): note1_default = key else: note1_default = "" self.view.show_accept_source_dialog( provisional_name, self.model.get_current_observation_date(), self.model.get_current_ra(), self.model.get_current_dec(), obs_mag, obs_mag_err, band, note1_choices=config.read("MPC.NOTE1OPTIONS"), note2_choices=config.read("MPC.NOTE2OPTIONS"), note1_default=note1_default, note2_default=config.read("MPC.NOTE2DEFAULT"), default_observatory_code=config.read("MPC.DEFAULT_OBSERVATORY_CODE"), default_comment=default_comment, phot_failure=phot_failure, pixel_x=source_cutout.pixel_x, pixel_y=source_cutout.pixel_y )
def comparison_image_list(self): """ returns a list of possible comparison images for the current cutout. Will query CADC to create the list when first called. @rtype: Table """ if self._comparison_image_list is not None: return self._comparison_image_list ref_ra = self.reading.ra * units.degree ref_dec = self.reading.dec * units.degree radius = self.radius is not None and self.radius or config.read( 'CUTOUTS.SINGLETS.RADIUS') * units.arcminute print(( "Querying CADC for list of possible comparison images at RA: {}, DEC: {}, raidus: {}" .format(ref_ra, ref_dec, radius))) query_result = storage.cone_search( ref_ra, ref_dec, radius, radius) # returns an astropy.table.table.Table print(("Got {} possible images".format(len(query_result)))) ans = input("Do you want to lookup IQ? (y/n)") print("Building table for presentation and selection") if ans == "y": print("Including getting fwhm which is a bit slow.") comparison_image_list = [] if len( query_result['collectionID'] ) > 0: # are there any comparison images even available on that sky? index = -1 for row in query_result: expnum = row['collectionID'] if expnum in self._bad_comparison_images: continue date = Time(row['mjdate'], format='mjd').mpc if Time(row['mjdate'], format='mjd') < Time( '2013-01-01 00:00:00', format='iso'): continue exptime = row['exptime'] if float(exptime) < 250: continue filter_name = row['filter'] if 'U' in filter_name: continue if filter_name.lower( ) in self.hdulist[-1].header['FILTER'].lower(): filter_name = "* {:8s}".format(filter_name) fwhm = -1.0 if ans == 'y': try: fwhm = "{:5.2f}".format( float(storage.get_fwhm_tag(expnum, 22))) except: pass index += 1 comparison_image_list.append( [index, expnum, date, exptime, filter_name, fwhm, None]) self._comparison_image_list = Table( data=numpy.array(comparison_image_list), names=[ "ID", "EXPNUM", "DATE-OBS", "EXPTIME", "FILTER", "FWHM", "REFERENCE" ]) return self._comparison_image_list
#(x, y, extno) = source_cutout.world2pix(ra, dec, usepv=False) #cutout.update_pixel_location((cen_x, cen_y)) mjd_obs = float(header.get('MJD-OBS')) exptime = float(header.get('EXPTIME')) mpc_date = Time(mjd_obs, format='mjd', scale='utc', precision=5) mpc_date += TimeDelta(exptime * units.second) / 2.0 date = mpc_date.mpc obs = mpc.Observation(null_observation=False, minor_planet_number=None, provisional_name=name, discovery=True, note1=None, note2=config.read('MPC.NOTE2DEFAULT')[0], date=date, ra=cutout.ra, dec=cutout.dec, mag=obs_mag, mag_err=obs_mag_err, frame=reading.obs.rawname, band=header['FILTER'], xpos=cutout.observed_x, ypos=cutout.observed_y, comment='AUTO', astrometric_level=cutout.astrom_header.get( 'ASTLEVEL', None)) source_obs.append(obs) with open(name + ".mpc", 'a') as fout: