diff --git a/lemon-completion.sh b/lemon-completion.sh index 89a228c..eab8b51 100644 --- a/lemon-completion.sh +++ b/lemon-completion.sh @@ -98,7 +98,7 @@ _lemon_annuli() _lemon_photometry() { local opts - opts="--overwrite --filter --maximum --margin --gain --annuli + opts="--overwrite --filter --exclude --maximum --margin --gain --annuli --cores --verbose --coordinates --epoch --aperture --annulus --dannulus --min-sky --individual-fwhm --aperture-pix --annulus-pix --dannulus-pix --snr-percentile --mean --objectk --filterk --datek diff --git a/photometry.py b/photometry.py index 58ffa72..53bb901 100644 --- a/photometry.py +++ b/photometry.py @@ -234,6 +234,13 @@ def parallel_photometry(args): "to specify more than one filter with which we want to " "work. " + defaults.desc['filter']) +parser.add_option('--exclude', action = 'append', type = 'passband', + dest = 'excluded_filters', default = None, + help = "ignore those FITS files taken in this photometric " + "filter. This option is the opposite of --filter, and may " + "be as well used multiple times in order to specify more " + "than one photometric filter that must be discarded.") + parser.add_option('--maximum', action = 'store', type = 'int', dest = 'maximum', default = defaults.maximum, help = defaults.desc['maximum']) @@ -498,6 +505,17 @@ def main(arguments = None): if not options.uncimgk: options.uncimgk = None + # There is not much point in using --filter and --exclude at the same time: + # the former discards all the images not taken in one or more filters, and + # the latter discards the images taken in one or more filters. We should + # always need to use one approach or the other, but never both at once. + + if options.filters and options.excluded_filters: + msg = "%sError. The --filter and --exclude options are incompatible." + print msg % style.prefix + print style.error_exit_message + return 1 + # The annuli JSON file (that generated by the annuli command, and specified # with the --annuli option) must exist. The use of this file automatically # discards whathever was specified with the Aperture Photometry (FWHM and @@ -783,6 +801,52 @@ def get_date(img): percentage = discarded / former_total * 100 print msg % (discarded, percentage) + # Now the opposite of --filter: discard those FITS images taken in any of + # the photometric filters contained in options.excluded_filters. The code + # below is very, very similar to that of --filter, but here we discard the + # images that match any of the specified filters, instead of those that do + # *not* match any of them. + + if options.excluded_filters: + + msg = "%sDiscarding images taken in any of the following filters:" + print msg % style.prefix + + for index, pfilter in enumerate(sorted(options.excluded_filters)): + msg = "%s (%d) %s: " % (style.prefix, index + 1, pfilter) + images = files[pfilter] + if not images: + msg += "(no images)" + else: + percentage = len(images) / len(files) * 100 + args = len(images), percentage + msg += "%d files to discard (%.2f %%)" % args + print msg + + sys.stdout.flush() + + discarded = 0 + for pfilter, images in files.items(): + if pfilter in options.excluded_filters: + discarded += len(images) + del files[pfilter] + + if not files: + print + print "%sError. All images were discarded." % style.prefix + print style.error_exit_message + return 1 + + else: + former_total = len(files) + discarded + msg = "%s%d images (%.2f %%) discarded," + percentage = discarded / former_total * 100 + print msg % (style.prefix, discarded, percentage) , + + msg = "%d (%.2f %%) remain." + percentage = len(files) / former_total * 100 + print msg % (len(files), percentage) + # If a JSON file is specified with --annuli, it must list the photometric # parameters for all the filters on which photometry is to be done. if json_annuli: