-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add logging framework #131
+205
−201
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
33c9eff
Add logging framework
snbianco d0585d2
Add footprint finder code (#127)
snbianco ba1afaa
comments, add logging to footprint cutouts, asdf cut tests leaving be…
snbianco a27d0e3
fix footprint imports
snbianco 4e27e2c
Merge branch 'main' into logging
snbianco 287c502
switch to INFO level
snbianco c6f004d
style fix
snbianco 1621088
Set logger default level to warning
snbianco 46a3ae2
Revamp __init__.py, use astropy logger
snbianco 5efd55b
rework levels, change to lazy formatting
snbianco 266f11c
Use monotonic(), add precision to %f
snbianco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,10 @@ | |
from astropy.io import fits | ||
from astropy.time import Time | ||
|
||
from . import __version__ | ||
from . import __version__, log | ||
from .exceptions import InputWarning, InvalidQueryError | ||
from .utils.wcs_fitting import fit_wcs_from_points | ||
from .utils.utils import _handle_verbose | ||
|
||
# todo: investigate why for small cutouts the astropy version is not working | ||
# from astropy.wcs.utils import fit_wcs_from_points | ||
|
@@ -121,8 +122,7 @@ def _parse_table_info(self, table_data, verbose=False): | |
if data_ind == len(table_data): | ||
raise wcs.NoWcsKeywordsFoundError("No FFI rows contain valid WCS keywords.") | ||
|
||
if verbose: | ||
print("Using WCS from row {} out of {}".format(data_ind, len(table_data))) | ||
log.info("Using WCS from row {} out of {}".format(data_ind, len(table_data))) | ||
|
||
# Turning the table row into a new header object | ||
wcs_header = fits.header.Header() | ||
|
@@ -462,10 +462,9 @@ def _get_cutout(self, transposed_cube, threads: Union[int, Literal["auto"]] = 1, | |
uncert_cutout = np.pad(uncert_cutout, padding, 'constant', constant_values=np.nan) | ||
aperture = np.pad(aperture, padding[1:], 'constant', constant_values=0) | ||
|
||
if verbose: | ||
print("Image cutout cube shape: {}".format(img_cutout.shape)) | ||
if self.product == "SPOC": | ||
print("Uncertainty cutout cube shape: {}".format(uncert_cutout.shape)) | ||
log.info("Image cutout cube shape: {}".format(img_cutout.shape)) | ||
if self.product == "SPOC": | ||
log.info("Uncertainty cutout cube shape: {}".format(uncert_cutout.shape)) | ||
|
||
return img_cutout, uncert_cutout, aperture | ||
|
||
|
@@ -844,8 +843,9 @@ def cube_cut( | |
if unsuccessful returns None. | ||
""" | ||
|
||
if verbose: | ||
start_time = time() | ||
start_time = time() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a huge deal, but we should be using |
||
# Log messages based on verbosity | ||
_handle_verbose(verbose) | ||
|
||
# Declare the product type being used to make the cutouts | ||
self.product = product.upper() | ||
|
@@ -874,9 +874,8 @@ def cube_cut( | |
else: | ||
self.center_coord = SkyCoord(coordinates, unit='deg') | ||
|
||
if verbose: | ||
print("Cutout center coordinate: {},{}".format(self.center_coord.ra.deg, | ||
self.center_coord.dec.deg)) | ||
log.info("Cutout center coordinate: {},{}".format(self.center_coord.ra.deg, | ||
self.center_coord.dec.deg)) | ||
|
||
# Making size into an array [ny, nx] | ||
if np.isscalar(cutout_size): | ||
|
@@ -894,10 +893,8 @@ def cube_cut( | |
|
||
# Get cutout limits | ||
self._get_cutout_limits(cutout_size) | ||
|
||
if verbose: | ||
print("xmin,xmax: {}".format(self.cutout_lims[1])) | ||
print("ymin,ymax: {}".format(self.cutout_lims[0])) | ||
log.info("xmin,xmax: {}".format(self.cutout_lims[1])) | ||
log.info("ymin,ymax: {}".format(self.cutout_lims[0])) | ||
|
||
# Make the cutout | ||
img_cutout, uncert_cutout, aperture = self._get_cutout(getattr(cube[1], cube_data_prop), threads=threads, | ||
|
@@ -906,17 +903,15 @@ def cube_cut( | |
# Get cutout wcs info | ||
cutout_wcs_full = self._get_full_cutout_wcs(cube[2].header) | ||
max_dist, sigma = self._fit_cutout_wcs(cutout_wcs_full, img_cutout.shape[1:]) | ||
if verbose: | ||
print("Maximum distance between approximate and true location: {}".format(max_dist)) | ||
print("Error in approximate WCS (sigma): {}".format(sigma)) | ||
log.info("Maximum distance between approximate and true location: {}".format(max_dist)) | ||
log.info("Error in approximate WCS (sigma): {}".format(sigma)) | ||
|
||
cutout_wcs_dict = self._get_cutout_wcs_dict() | ||
|
||
# Build the TPF | ||
tpf_object = self._build_tpf(cube, img_cutout, uncert_cutout, cutout_wcs_dict, aperture) | ||
|
||
if verbose: | ||
write_time = time() | ||
write_time = time() | ||
|
||
if not target_pixel_file: | ||
_, flename = os.path.split(cube_file) | ||
|
@@ -931,8 +926,7 @@ def cube_cut( | |
target_pixel_file = os.path.join(output_path, target_pixel_file) | ||
|
||
|
||
if verbose: | ||
print("Target pixel file: {}".format(target_pixel_file)) | ||
log.info("Target pixel file: {}".format(target_pixel_file)) | ||
|
||
# Make sure the output directory exists | ||
if not os.path.exists(output_path): | ||
|
@@ -941,8 +935,7 @@ def cube_cut( | |
# Write the TPF | ||
tpf_object.writeto(target_pixel_file, overwrite=True, checksum=True) | ||
|
||
if verbose: | ||
print("Write time: {:.2} sec".format(time()-write_time)) | ||
print("Total time: {:.2} sec".format(time()-start_time)) | ||
log.info("Write time: {:.2} sec".format(time()-write_time)) | ||
log.info("Total time: {:.2} sec".format(time()-start_time)) | ||
|
||
return target_pixel_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
instead of formatting the string and passing it into the logger, as you have here with the fstring, and below with the
str.format()
calls, it is best practice to let the logger do the formatting. this is for security (in some places we do call astrocut as a web service, so some of these inputs may be untrusted and we don't want them logged onto a server), but there's another reason as well. If the logging level is skipped (e.g. Debug) the logger can avoid doing any str formatting if it's passed in this way, whereas if you format the string before passing it into the logger, you are always doing that (small) bit of work.so in this case, my suggestion would be:
And should be applied to all the log formatting here.
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.
Since
AstropyLogger
doesn't support lazy formatting, I configured a new logger for astrocut with a similar formatter.