Commit 99905f6b authored by Thomas Vincent's avatar Thomas Vincent

Use python logging instead of print (except for multiprocessing part)

parent 1742240d
......@@ -30,17 +30,22 @@ __license__ = "MIT"
__date__ = "01/11/2016"
import logging
from .Hdf5Nodes import H5Base, H5NodeFactory
from .ProjectItem import ProjectItem
_logger = logging.getLogger(__name__)
def h5NodeToProjectItem(h5Node, mode='r', cast=True):
if not isinstance(h5Node, H5Base):
return None
try:
item = ProjectItem(h5Node.h5File, nodePath=h5Node.h5Path, mode=mode)
except Exception as ex:
print('EXCEPTION', ex)
_logger.error(ex)
raise
if cast:
......
......@@ -30,6 +30,7 @@ __license__ = "MIT"
__date__ = "15/09/2016"
import logging
import weakref
from collections import namedtuple, OrderedDict
......@@ -52,6 +53,8 @@ from ..widgets.PointWidget import PointWidget
from ..widgets.Input import StyledLineEdit
_logger = logging.getLogger(__name__)
_defaultNColors = 256
XsocsPlot2DColormap = namedtuple('XsocsPlot2DColormap',
......@@ -1125,7 +1128,8 @@ class XsocsPlot2D(PlotWindow):
if 'color' in kwargs:
del kwargs['color']
print('In XsocsPlot2D.setPlotData : keyword color is ignored.')
_logger.warning(
'In XsocsPlot2D.setPlotData : keyword color is ignored.')
legend = self.__plotData(x,
y,
......
......@@ -30,6 +30,7 @@ __authors__ = ["D. Naudet"]
__date__ = "01/06/2016"
__license__ = "MIT"
import logging
import time
import ctypes
import multiprocessing as mp
......@@ -46,6 +47,10 @@ from ...fit import (GaussianFitter, GaussianResults,
SilxFitter, SilxResults)
from .sharedresults import FitTypes
_logger = logging.getLogger(__name__)
disp_times = False
......@@ -289,11 +294,11 @@ class PeakFitter(Thread):
t_total = time.time() - t_total
if disp_times:
print('Total : {0}.'.format(t_total))
print('Read {0}'.format(res_times.t_read))
print('Mask {0}'.format(res_times.t_mask))
print('Fit {0}'.format(res_times.t_fit))
print('Write {0}'.format(res_times.t_write))
_logger.info('Total : {0}.'.format(t_total))
_logger.info('Read {0}'.format(res_times.t_read))
_logger.info('Mask {0}'.format(res_times.t_mask))
_logger.info('Fit {0}'.format(res_times.t_fit))
_logger.info('Write {0}'.format(res_times.t_write))
with QSpaceH5.QSpaceH5(qspace_f) as qspace_h5:
q_x = qspace_h5.qx
......
......@@ -234,8 +234,8 @@ class KmapMerger(object):
'output': output_files[scan_id]}
for scan_id in selected_scans}
print('Merging scan IDs : {}.'
''.format(', '.join(self.selected_ids)))
_logger.info(
'Merging scan IDs : {}.'.format(', '.join(self.selected_ids)))
try:
manager = Manager()
......@@ -266,7 +266,7 @@ class KmapMerger(object):
def callback(result_):
scan, finished, info = result_
print('{0} finished.'.format(scan))
_logger.info('{0} finished.'.format(scan))
if not finished:
term_evt.set()
......
......@@ -49,7 +49,7 @@ from ...util.histogramnd_lut import histogramnd_get_lut, histogramnd_from_lut
from ...io import XsocsH5, QSpaceH5, ShiftH5
logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)
disp_times = False
......@@ -323,10 +323,7 @@ class QSpaceConverter(object):
if check_consistency:
raise ValueError(msg)
else:
print('==============.')
print('==============.')
print('WARNING.')
print(msg)
_logger.warning(msg)
output_f = self.__output_f
if output_f is None:
......@@ -735,17 +732,17 @@ class QSpaceConverter(object):
n_xy = len(sample_indices)
print('Parameters :')
print('\t- beam energy : {0}'.format(beam_energy))
print('\t- center channel : {0}'.format(center_chan))
print('\t- image roi offset : {0}'.format(image_roi_offset))
print('\t- channel per degree : {0}'.format(chan_per_deg))
print('\t- maxipix correction : {0}'.format(self.maxipix_correction))
print('\t- mask : {0}'.format(
_logger.info('Parameters :')
_logger.info('\t- beam energy : {0}'.format(beam_energy))
_logger.info('\t- center channel : {0}'.format(center_chan))
_logger.info('\t- image roi offset : {0}'.format(image_roi_offset))
_logger.info('\t- channel per degree : {0}'.format(chan_per_deg))
_logger.info('\t- maxipix correction : {0}'.format(self.maxipix_correction))
_logger.info('\t- mask : {0}'.format(
'Yes' if mask is not None else 'No'))
print('\t- normalizer : {0}'.format(normalizer))
print('\t- medfilt dims : {0}'.format(medfilt_dims))
print('\t- qspace size : {0}'.format(qspace_dims))
_logger.info('\t- normalizer : {0}'.format(normalizer))
_logger.info('\t- medfilt dims : {0}'.format(medfilt_dims))
_logger.info('\t- qspace size : {0}'.format(qspace_dims))
# Offset center_chan with image roi offset if any
center_chan = (center_chan[0] - image_roi_offset[0],
......@@ -1025,16 +1022,16 @@ class QSpaceConverter(object):
tb = time.time()
if disp_times:
print('TOTAL {0}'.format(tb - ta))
print('Read {0}'.format(res_times.t_read))
print('Context {0}'.format(res_times.t_context))
print('Preprocess {0}'.format(res_times.t_preprocess))
print('Medfilt {0}'.format(res_times.t_medfilt))
print('Histo {0}'.format(res_times.t_histo))
print('Mask {0}'.format(res_times.t_mask))
print('Sum {0}'.format(res_times.t_sum))
print('Write {0}'.format(res_times.t_write))
print('(lock : {0})'.format(res_times.t_w_lock))
_logger.info('TOTAL {0}'.format(tb - ta))
_logger.info('Read {0}'.format(res_times.t_read))
_logger.info('Context {0}'.format(res_times.t_context))
_logger.info('Preprocess {0}'.format(res_times.t_preprocess))
_logger.info('Medfilt {0}'.format(res_times.t_medfilt))
_logger.info('Histo {0}'.format(res_times.t_histo))
_logger.info('Mask {0}'.format(res_times.t_mask))
_logger.info('Sum {0}'.format(res_times.t_sum))
_logger.info('Write {0}'.format(res_times.t_write))
_logger.info('(lock : {0})'.format(res_times.t_w_lock))
proc_results = [result.get() for result in results]
proc_codes = np.array([proc_result[0]
......@@ -1345,7 +1342,7 @@ def _to_qspace(th_idx,
if (maxipix_correction or normalizer) and img_dtype.kind != 'f':
# Force the type to float64
logger.info('Using float64')
_logger.info('Using float64')
img_dtype = np.float64
img = np.ascontiguousarray(np.zeros(img_size), dtype=img_dtype)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment