-
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
Changes from 10 commits
33c9eff
d0585d2
ba1afaa
a27d0e3
4e27e2c
287c502
c6f004d
1621088
46a3ae2
5efd55b
266f11c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.debug("Using WCS from row %s out of %s", 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.debug("Image cutout cube shape: %s", img_cutout.shape) | ||
if self.product == "SPOC": | ||
log.debug("Uncertainty cutout cube shape: %s", 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() | ||
# 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,7 @@ 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.debug("Cutout center coordinate: %s, %s", self.center_coord.ra.deg, self.center_coord.dec.deg) | ||
|
||
# Making size into an array [ny, nx] | ||
if np.isscalar(cutout_size): | ||
|
@@ -894,10 +892,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.debug("xmin,xmax: %s", self.cutout_lims[1]) | ||
log.debug("ymin,ymax: %s", 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 +902,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.debug("Maximum distance between approximate and true location: %s", max_dist) | ||
log.debug("Error in approximate WCS (sigma): %f", sigma) | ||
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. When do we format with 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. I'm using %d for integers, %f for floats, and %s for other types. I added a precision to line 906 in the latest commit. |
||
|
||
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 +925,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.debug("Target pixel file: %s", target_pixel_file) | ||
|
||
# Make sure the output directory exists | ||
if not os.path.exists(output_path): | ||
|
@@ -941,8 +934,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.debug("Write time: %.2f sec", (time() - write_time)) | ||
log.debug("Total time: %.2f sec", (time() - start_time)) | ||
|
||
return target_pixel_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.
not a huge deal, but we should be using
time.monotonic()
ortime.perf_counter()
here instead.https://docs.python.org/3/library/time.html#time.monotonic