def select_files(self, files, start_date=None, end_date=None, filter_dates=None, step=1): """Set the images files of the projects. The `files` parameter accept shell like wildcards, and it is possible to filter files by dates. Examples --------- >>> ctx.select_files('/project/files/*.fits') >>> ctx.select_files('/project/files/*.fits', start_date=datetime.datetime(2000, 1, 1)) >>> ctx.select_files('/project/files/*.fits', step=2) Parameters ---------- files : str Path to the file(s). Accept shell like wildcards. start_date : :class:`datetime.datetime`, optional Reject files with date < `start_date`. end_date : :class:`datetime.datetime`, optional Reject files with date > `end_date`. filter_dates : a list of :class:`datetime.datetime`, optional Reject files with date in `filter_dates` step : int, optional """ if isinstance(files, str): files = glob.glob(files) self.files = imgutils.fast_sorted_fits(files, start_date=start_date, end_date=end_date, filter_dates=filter_dates, step=step) print "Number of files selected:", len(self.files)
def _test_load_3c120_config(): import astropy.cosmology as cosmology cosmology.default_cosmology.set(cosmology.FlatLambdaCDM(H0=71 * u.km / u.s / u.Mpc, Om0=0.27)) BASE_DIR = os.path.expanduser("~/data/3c120/mojave") ctx = project.AnalysisContext() # data configuration ctx.config.data.data_dir = os.path.join(BASE_DIR, "run001") ctx.config.data.object_z = 0.033 def get_bg(ctx, img): return img.data[:, :800] def build_mask(ctx): stack = ctx.get_ref_image() segments = wise.SegmentedImages(stack) segments.connected_structure() mask = segments.get_mask(segments.sorted_list()[-1]) mask = imgutils.Image.from_image(stack, mask) return mask def pre_process(ctx, img): img.crop([3, -10], [-22, 3], projection=ctx.get_projection(img)) # img.crop([10, -20], [-40, 10], projection=ctx.get_projection(img)) # img.crop([2, -4], [-5, 2], projection=ctx.get_projection(img)) def get_core(ctx, img): bg = ctx.get_bg(img) ctx.pre_process(img) cmp_y = lambda x, y: cmp(x.get_coord()[1], y.get_coord()[1]) core = wiseutils.align_image_on_core(img, bg, cmp_y) core = ctx.get_projection(img).p2s(plotutils.p2i(core)) return core ctx.config.data.bg_fct = get_bg ctx.config.data.mask_fct = build_mask ctx.config.data.pre_process_fct = pre_process ctx.config.data.core_offset_filename = "mojave_core.dat" ctx.config.data.core_offset_fct = get_core # finder configuration ctx.config.finder.min_scale = 1 ctx.config.finder.max_scale = 4 ctx.config.finder.alpha_threashold = 3 ctx.config.finder.exclude_noise = False ctx.config.finder.ms_dec_klass = wds.WaveletMultiscaleDecomposition files = glob.glob(os.path.join(BASE_DIR, "icn/**.icn.fits")) start_date = end_date = filter_dates = None start_date = datetime.datetime(2002, 1, 1) end_date = datetime.datetime(2006, 1, 1) # filter_dates = [datetime.datetime(2000, 12, 30)] ctx.files = imgutils.fast_sorted_fits(files, start_date=start_date, end_date=end_date, filter_dates=filter_dates) return ctx
def main(): sh.init(libwise.get_version(), USAGE) start_date = get_date(sh.get_opt_value('start-date', 's'), 'start-date') end_date = get_date(sh.get_opt_value('end-date', 'e'), 'end-date') filter_dates = [get_date(k, 'filter-date') for k in sh.get_opt_value('filter-date', 'f', multiple=True)] output_filename = sh.get_opt_value('output', 'o', default='files') args = sh.get_args(min_nargs=1) files = imgutils.fast_sorted_fits(args, start_date=start_date, end_date=end_date, filter_dates=filter_dates) print "Outputing %s files in '%s'" % (len(files), output_filename) with open(output_filename, 'w') as f: f.write("\n".join(files) + "\n")
def main(): sh.init(libwise.get_version(), USAGE) start_date = get_date(sh.get_opt_value('start-date', 's'), 'start-date') end_date = get_date(sh.get_opt_value('end-date', 'e'), 'end-date') filter_dates = [ get_date(k, 'filter-date') for k in sh.get_opt_value('filter-date', 'f', multiple=True) ] output_filename = sh.get_opt_value('output', 'o', default='files') args = sh.get_args(min_nargs=1) files = imgutils.fast_sorted_fits(args, start_date=start_date, end_date=end_date, filter_dates=filter_dates) print "Outputing %s files in '%s'" % (len(files), output_filename) with open(output_filename, 'w') as f: f.write("\n".join(files) + "\n")