Skip to content

Commit

Permalink
Merge pull request #20 from ratt-ru/issue-19
Browse files Browse the repository at this point in the history
fixes #19
  • Loading branch information
o-smirnov authored Jan 9, 2023
2 parents d802ce8 + a2f15d1 commit 1b16b4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
Expand Down
14 changes: 10 additions & 4 deletions breizorro/breizorro.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def make_noise_map(restored_image, boxsize):
LOGGER.info(f"Median noise value is {median_noise}")
return noise

def resolve_island(isl_spec, mask_image, wcs):
def resolve_island(isl_spec, mask_image, wcs, ignore_missing=False):
if re.match("^\d+$", isl_spec):
return int(isl_spec)
elif ',' not in isl_spec:
Expand All @@ -102,7 +102,10 @@ def resolve_island(isl_spec, mask_image, wcs):
value = mask_image[y, x]
LOGGER.info(f"coordinates {c} correspond to pixel {x}, {y} with value {value}")
if not value:
raise ValueError(f"coordinates {c} do not select a valid island")
if ignore_missing:
LOGGER.warning("no island at specified coordinates, ignoring")
else:
raise ValueError(f"coordinates {c} do not select a valid island")
return value

def add_regions(mask_image, regs, wcs):
Expand Down Expand Up @@ -147,6 +150,8 @@ def main():
help='Number the islands detected (default=do not number islands)')
parser.add_argument('--remove-islands', dest='remove_isl', metavar='N|COORD', type=str, nargs='+',
help='List of islands to remove from input mask. e.g. --remove-islands 1 18 20 20h10m13s,14d15m20s')
parser.add_argument('--ignore-missing-islands', action='store_true',
help='If an island specified by coordinates does not exist, do not throw an error')
parser.add_argument('--extract-islands', dest='extract_isl', metavar='N|COORD', type=str, nargs='+',
help='List of islands to extract from input mask. e.g. --extract-islands 1 18 20 20h10m13s,14d15m20s')
parser.add_argument('--make-binary', action="store_true",
Expand Down Expand Up @@ -271,8 +276,9 @@ def load_fits_or_region(filename):
if args.remove_isl:
LOGGER.info(f"Removing islands: {args.remove_isl}")
for isl_spec in args.remove_isl:
isl = resolve_island(isl_spec, mask_image, wcs)
mask_image[mask_image == isl] = 0
isl = resolve_island(isl_spec, mask_image, wcs, ignore_missing=args.ignore_missing_islands)
if isl != None:
mask_image[mask_image == isl] = 0

if args.extract_isl:
LOGGER.info(f"Extracting islands: {args.extract_isl}")
Expand Down

0 comments on commit 1b16b4d

Please sign in to comment.