Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Add --exclude option
Browse files Browse the repository at this point in the history
This is the opposite of --filter: it allows us to specify one or more
photometric filters in which photometry will not be done — those FITS
images taken in any of them are discarded. The --exclude option is
incompatible with --filter, so they cannot be used at the same time.

This merges branch 'add-exclude-option'
  • Loading branch information
Víctor Terrón committed Sep 3, 2014
2 parents 1585212 + a500c5f commit 0e0e81d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lemon-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e0e81d

Please sign in to comment.