-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write regions and catalogs #36
Conversation
…reizorro into write_regions_catalogs
breizorro/breizorro.py
Outdated
parser.add_argument('-ncpu', '--ncpu', dest='ncpu', default=None, type=int, | ||
help='Number of processors to use for cataloging.') | ||
parser.add_argument('-beam', '--beam-size', dest='beam', default=None, | ||
help='Average beam size in arcesc incase beam info is missing in image header.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this breaks with our current CLI convention of only single-letter options for "-". I would use "-j" for ncpu (it's a popular Unix alias) and "-B" for beam.
breizorro/breizorro.py
Outdated
from breizorro.catalog import multiprocess_contours | ||
except ModuleNotFoundError: | ||
LOGGER.error("Running breizorro source detector requires optional dependencies, please re-install with: pip install breizorro[catalog]") | ||
raise('Missing cataloguing dependencies') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe raise and log the same message?
breizorro/breizorro.py
Outdated
# Suppress FittingWarnings from Astropy | ||
# WARNING: The fit may be unsuccessful; check fit_info['message'] for more information. [astropy.modeling.fitting] | ||
warnings.resetwarnings() | ||
warnings.filterwarnings('ignore', category=UserWarning, append=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a context manager form (with something
) to temporarily change warnings settings.
@Athanaseus I wonder -- the CLI's getting quite complex, is this not a good time to move it to a YAML schema and switch to clickify_parameters instead? |
breizorro/breizorro.py
Outdated
parser.error("Either --restored-image or --mask-image must be specified") | ||
|
||
# Example usage of the parameters | ||
LOGGER.info(f"Restored Image: {restored_image}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the production version, printing all this is probably not necessary.
breizorro/config/breizorro.yaml
Outdated
@@ -0,0 +1,120 @@ | |||
opts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts should not be in the cab definition. Cab def only. Also, suggest placing this at top level, so it can be included as _include: (breizorro)breizorro.yml
.
breizorro/config/breizorro.yaml
Outdated
restored_image: | ||
info: "Restored image file from which to build the mask" | ||
dtype: File | ||
required: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required: false
is the default for all inputs, so can probably omit it.
breizorro/config/breizorro.yaml
Outdated
dtype: bool | ||
required: false | ||
default: false | ||
dilate: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding metavar: R
to this one to maintain consistency with old CLI (anywhere where we defined a metavar).
breizorro/config/breizorro.yaml
Outdated
default: false | ||
merge: | ||
info: "Merge one or more masks or region files" | ||
dtype: list[File] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be List[File]
, also elsewhere. Also, for multiple options, do we want --merge FILE1 FILE2
, --merge FILE1,FILE2
or --merge FILE1 --merge FILE2
? Set policies: repeat
accordingly, to list
, []
or repeat
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the following work?
merge:
info: "Merge one or more masks or region files"
dtype: List[File]
policies:
repeat: ' '
When repeat is set to list
it passes the argument as a string
instead of list
of files.
Also, this results in no file validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I lie, --merge FILE1 FILE2
is not available with click. So you have to decide on --merge 'FILE1 FILE2'
(cumbersome because it needs shell quotes), --merge FILE1,FILE2
, or --merge FILE1 --merge FILE2
.
When repeat is set to
list
it passes the argument as astring
instead oflist
of files.
Also, this results in no file validation.
File validation is not done via clickify anyway. But it's strange that it passes as a string. Could you please test again? Alternatively, try the clickify-cleanup
branch I just pushed to stimela. I've added a test there and it seems to work as expected:
(stimela) oms@baker:~/projects/stimela2/tests/scabha_tests$ ./test_clickify.py 1 2 a b --files1 'x y z' --files2 x --files2 y --files3 a,b --output x
1 2 None 2.0 None
remainder: ('a', 'b')
files1: ['x', 'y', 'z']
files2: ('x', 'y')
files3: ['a', 'b']
output: x
(stimela) oms@baker:~/projects/stimela2/tests/scabha_tests$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, try the clickify-cleanup branch I just pushed to stimela. I've added a test there and it seems to work as expected:
Now I get the following when I set repeat policy to list
: scabha.exceptions.SchemaError: click parameter 'merge': repeat=list policy is only supported for positional=true parameters
I'd go with --merge File1,File2
.
merge:
info: "Merge one or more masks or region files"
dtype: List[File]
metavar: "MASK(s)|REG(s)"
policies:
repeat: '[]'
But for the extract-islands
/remove-islands
parameters which were previously specified as --remove-islands 19 21 14h16m20.3s,-65d42m07s
, can now be configured as:
remove_islands:
info: "Remove islands from input mask (list by number or coordinates)"
dtype: Optional[Tuple[int, str]]
policies:
repeat: ' '
which results in --remove-islands '19 21 14h16m20.3s,-65d42m07s'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I get the following when I set repeat policy to
list
:scabha.exceptions.SchemaError: click parameter 'merge': repeat=list policy is only supported for positional=true parameters
Yeah that's as expected. Click does not support variable-length options -- only positional arguments (i.e. the last positional argument can be variable-length, it will swallow "the rest" of the command line.)
But for the
extract-islands
/remove-islands
parameters which were previously specified as--remove-islands 19 21 14h16m20.3s,-65d42m07s
, can now be configured as:remove_islands: info: "Remove islands from input mask (list by number or coordinates)" dtype: Optional[Tuple[int, str]] policies: repeat: ' '
which results in
--remove-islands '19 21 14h16m20.3s,-65d42m07s'
I'm confused that this works. Tuple[int, str]
should expect two arguments, an int and a str, so if it accepts three, that's a bug in clickify_parameters
. I'll investigate. In any case you probably meant List[Union[int, str]]
, right?
I'm a bit concerned that we have two different ways of specifying multiple arguments (comma-separated and space-separated) in the CLI now, this is potentially confusing. Maybe consider using :
as a separator throughout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I released stimela 2.0.2 which incorporates the CLI fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused that this works. Tuple[int, str] should expect two arguments, an int and a str, so if it accepts three, that's a bug in clickify_parameters.
I was yet to test this dtype, actually I had it as List[str]
.
I'll investigate. In any case you probably meant List[Union[int, str]], right?
Exactly.
I'm a bit concerned that we have two different ways of specifying multiple arguments (comma-separated and space-separated) in the CLI now, this is potentially confusing. Maybe consider using : as a separator throughout?
Sounds good to me.
Example:
breizorro -r mypipelinerun-MFS-image.fits--merge mask.fits,adass.reg --number-islands --remove-islands 19,21,14h16m20.3:-65d42m07
breizorro.breizorro - 2024-12-20 00:55:47,393 INFO - Welcome to breizorro
breizorro.breizorro - 2024-12-20 00:55:47,444 INFO - Version: 0.1.3
breizorro.breizorro - 2024-12-20 00:55:47,444 INFO - Usage: breizorro --help
breizorro.breizorro - 2024-12-20 00:55:47,457 INFO - Generating mask using threshold 6.5
breizorro.breizorro - 2024-12-20 00:55:47,457 INFO - Generating noise map
breizorro.breizorro - 2024-12-20 00:55:47,582 INFO - Median noise value is 0.0007369568920694292
WARNING: FITSFixedWarning: 'datfix' made the change 'Set MJD-OBS to 58318.744319 from DATE-OBS'. [astropy.wcs.wcs]
breizorro.breizorro - 2024-12-20 00:55:47,615 INFO - Treating mask.fits as a FITS mask
breizorro.breizorro - 2024-12-20 00:55:47,622 INFO - Merged into mask
breizorro.breizorro - 2024-12-20 00:55:47,894 INFO - Merging in 24 regions from adass.reg
breizorro.breizorro - 2024-12-20 00:55:48,506 INFO - (Re)numbering islands
breizorro.breizorro - 2024-12-20 00:55:48,524 INFO - Number of islands: 35
breizorro.breizorro - 2024-12-20 00:55:48,524 INFO - Removing islands: ['19', '21', '14h16m20.3:-65d42m07']
breizorro.breizorro - 2024-12-20 00:55:48,550 INFO - coordinates <SkyCoord (ICRS): (ra, dec) in deg
(214.08458333, -65.70194444)> correspond to pixel 328, 241 with value 5
breizorro.breizorro - 2024-12-20 00:55:48,568 INFO - Writing mypipelinerun-MFS-image.mask.fits
breizorro.breizorro - 2024-12-20 00:55:48,588 INFO - Done
breizorro/config/breizorro.yaml
Outdated
info: "Sum-to-peak ratio of flux islands to mask in original image" | ||
dtype: float | ||
required: false | ||
ncpu: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add abbreviation: j
to have the single-letter -j
option also available. Also for other arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we should do this to keep the CLI compatible with older releases.
@Athanaseus what's the status of the changes -- want me to review again? |
Yes, it needs some final review. I added examples in the params info. |
OK looks good, just one final suggestion -- in the yaml file, use dashes (i.e. |
Adds
--outcatalog
and--outregion
to write outt catalog text file and save regions file respectively.Update README and add GitHub pages
NB: The catalogs are also compatible with the
Tigger
viewer