diff --git a/megaradrp/recipes/calibration/trace.py b/megaradrp/recipes/calibration/trace.py index cdfe4c0..664997d 100644 --- a/megaradrp/recipes/calibration/trace.py +++ b/megaradrp/recipes/calibration/trace.py @@ -133,11 +133,11 @@ def check_qc_tracemap(self, tracemap): continue if trace.start > start_min: cost_ids[idx] += 1 - msg = 'In fiber {}, trace start > {}'.format(trace.fibid, start_min) + msg = f'In fiber {trace.fibid}, trace start > {start_min}' warnings.warn(msg) if trace.stop < end_max: cost_ids[idx] += 1 - msg = 'In fiber {}, trace end < {}'.format(trace.fibid, end_max) + msg = f'In fiber {trace.fibid}, trace end < {end_max}' warnings.warn(msg) total = sum(cost_ids) @@ -149,7 +149,7 @@ def check_qc_tracemap(self, tracemap): else: tracemap.quality_control = qc.QC.GOOD - #@numina.core.validator.validate + # @numina.core.validator.validate def run(self, rinput): """Execute the recipe. @@ -295,8 +295,8 @@ def obtain_boxes_from_image(self, reduced, expected, npeaks, cstart=2000): res = numpy.fft.ifft(yv) final = res.real plt.plot(final) - #trend = detrend(final) - #plt.plot(final - trend) + # trend = detrend(final) + # plt.plot(final - trend) plt.show() idx = find_peaks_indexes(final, window_width=3, threshold=0.3, fpeak=1) @@ -311,7 +311,7 @@ def obtain_boxes_from_image(self, reduced, expected, npeaks, cstart=2000): nidxs = numpy.sort(nidx) plt.plot(final) - #plt.scatter(idx, [0.9 for m in idx]) + # plt.scatter(idx, [0.9 for m in idx]) plt.scatter(nidx, [0.95 for m in nidx], c='r') plt.scatter(expected, [1.0 for m in expected]) plt.show() @@ -379,14 +379,15 @@ def refine_boxes_from_image(self, reduced, expected, cstart=2000, nsearch=20): ioffset = xcorr[ycorr.index(max(ycorr))] # auxiliary plot showing the cross-correlation work - fig, ax = plt.subplots(ncols=1, nrows=1) - ax.plot(xcorr, ycorr, 'o-') - ax.set_xlabel('ioffset') - ax.set_ylabel('peak of corrrelation function') - ax.axvline(ioffset, linestyle=':', color='C1') - ax.set_title('optimal initial offset: {}'.format(ioffset)) - plt.savefig('offset_borders_cross.png') - plt.close() + if self.intermediate_results: + fig, ax = plt.subplots(ncols=1, nrows=1) + ax.plot(xcorr, ycorr, 'o-') + ax.set_xlabel('ioffset') + ax.set_ylabel('peak of corrrelation function') + ax.axvline(ioffset, linestyle=':', color='C1') + ax.set_title('optimal initial offset: {}'.format(ioffset)) + plt.savefig('offset_borders_cross.png') + plt.close() # using the initial offset, refine the peak search around the new # expected location, looking for a maximum in +/- nsearch pixels @@ -398,21 +399,22 @@ def refine_boxes_from_image(self, reduced, expected, cstart=2000, nsearch=20): refined[ibox] = iargmax + box - nsearch + ioffset # auxiliary plot showing the initial and final frontier locations - fig, ax = plt.subplots(ncols=1, nrows=1) - ax.plot(final, label='cross section at x={}'.format(cstart)) - ax.plot(xwave, sp_comb_lines0, label='expected location of frontiers') - for idum, item in enumerate(expected): - if idum == 0: - label = 'refined frontier location' - else: - label = None - ax.plot(refined, final[refined], 'ro', label=label) - ax.legend() - ax.set_title('optimal initial offset: {}'.format(ioffset)) - ax.set_xlabel('pixel number - 1') - ax.set_ylabel('inverted normalized signal') - plt.savefig('frontiers_between_pseudoslits.png') - plt.close() + if self.intermediate_results: + fig, ax = plt.subplots(ncols=1, nrows=1) + ax.plot(final, label='cross section at x={}'.format(cstart)) + ax.plot(xwave, sp_comb_lines0, label='expected location of frontiers') + for idum, item in enumerate(expected): + if idum == 0: + label = 'refined frontier location' + else: + label = None + ax.plot(refined, final[refined], 'ro', label=label) + ax.legend() + ax.set_title('optimal initial offset: {}'.format(ioffset)) + ax.set_xlabel('pixel number - 1') + ax.set_ylabel('inverted normalized signal') + plt.savefig('frontiers_between_pseudoslits.png') + plt.close() return refined, cstart @@ -480,10 +482,10 @@ def search_traces(self, reduced, boxes, box_borders, inactive_fibers=None, cstar if debug_plot: plt.plot(mm[:, 0], mm[:, 1], '.') - plt.savefig('trace-xy-{:03d}.png'.format(dtrace.fibid)) + plt.savefig(f'trace-xy-{dtrace.fibid:03d}.png') plt.close() plt.plot(mm[:, 0], mm[:, 2], '.') - plt.savefig('trace-xz-{:03d}.png'.format(dtrace.fibid)) + plt.savefig(f'trace-xz-{dtrace.fibid:03d}.png') plt.close() if len(mm) < poldeg + 1: self.logger.warning('in fibid %d, only %d points to fit pol of degree %d', @@ -621,8 +623,8 @@ def init_traces(image, center, hs, boxes, box_borders, tol=1.5, threshold=0.37, plt.plot(ipeaks_int+b1, region[ipeaks_int], 'r*') plt.xlabel('pixel number - 1') plt.ylabel('number of counts') - plt.title('pseudoslit box: {}, id: {}'.format(box['name'], boxid)) - plt.savefig('central_cut_{:02d}.png'.format(boxid)) + plt.title(f'pseudoslit box: {box["name"]}, id: {boxid}') + plt.savefig(f'central_cut_{boxid:02d}.png') plt.close() startid = lastid + 1