From 0b88b23500c79dbea26add9ebd0b488f06757e5c Mon Sep 17 00:00:00 2001 From: Varghese Reji Date: Mon, 6 Oct 2025 19:43:03 +0530 Subject: [PATCH 1/3] Adding pyproject.toml to build wheel properly --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9c3fb0e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools<60", "wheel", "numpy"] +build-backend = "setuptools.build_meta" \ No newline at end of file From dd7996f5892dc55f3f319ac1f39e51f2d87f6ef0 Mon Sep 17 00:00:00 2001 From: Varghese Reji Date: Mon, 6 Oct 2025 21:44:33 +0530 Subject: [PATCH 2/3] Showing the aperture fitting plot together. Added legend to the plot. The legend will shown only once. --- SpectrumExtractor/spectrum_extractor.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SpectrumExtractor/spectrum_extractor.py b/SpectrumExtractor/spectrum_extractor.py index 0f0fd7f..c6f65f0 100644 --- a/SpectrumExtractor/spectrum_extractor.py +++ b/SpectrumExtractor/spectrum_extractor.py @@ -535,6 +535,7 @@ def CalculateShiftInXD(SpectrumImage, RefImage=None, XDshiftmodel='p0',Coeffmode Splits_RefImage = np.split(RefImage[:,DWindowToUse[0]:DWindowToUse[0]+NoOfXDstripes*StripWidth],NoOfXDstripes,axis=1) Indices = list(range(len(Splits_SpectrumImage))) # Fit starting at the center where flux will likely be maximum, after finishing to right, return and do towards the left. + plt.figure() for i in Indices[NoOfXDstripes//2:]+Indices[NoOfXDstripes//2-1::-1]: XDSliceSpec = Splits_SpectrumImage[i] XDSliceRef = Splits_RefImage[i] @@ -573,10 +574,10 @@ def CalculateShiftInXD(SpectrumImage, RefImage=None, XDshiftmodel='p0',Coeffmode logging.debug('XD offset fit {0}:{1}'.format(i,fitted_driftp)) XDShiftCoeffDict[centerx] = fitted_driftp if ShowPlot: - plt.figure() - plt.plot(newRefFlux[:,0],newRefFlux[:,1]*fitted_driftp[0],color='k',alpha=0.3) - plt.plot(shifted_pixels,SumApFluxSpectrum,color='g',alpha=0.3) - plt.show(block=False) + # plt.figure() + plt.plot(newRefFlux[:,0],newRefFlux[:,1]*fitted_driftp[0],color='k',alpha=0.3, label="Reference aperture position") + plt.plot(shifted_pixels,SumApFluxSpectrum,color='g',alpha=0.3, label="Observed aperture position") + # plt.show(block=False) if int(Coeffmodel[1:]) == 0: Avg_XD_shift = biweight_location(np.array(list(XDShiftCoeffDict.values())),axis=0)[1:] #remove the flux scale coeff @@ -589,6 +590,9 @@ def CalculateShiftInXD(SpectrumImage, RefImage=None, XDshiftmodel='p0',Coeffmode c = np.polynomial.Polynomial.fit(Dpixelpos, coeff_list, int(Coeffmodel[1:])) Avg_XD_shift.append(tuple(c.convert().coef)) if ShowPlot: + handles, labels = plt.gca().get_legend_handles_labels() + by_label = dict(zip(labels, handles)) + plt.legend(by_label.values(), by_label.keys()) plt.title('{0}: {1}'.format(tuple(Avg_XD_shift),tuple(DomainRange))) plt.xlabel('XD pixels') plt.ylabel('Apodized counts') From 5e018a4a079572c77ed84ec318e6ba2f1809db98 Mon Sep 17 00:00:00 2001 From: Varghese Reji Date: Fri, 10 Oct 2025 11:35:08 +0530 Subject: [PATCH 3/3] If ShowPlot is True, a new directory will be created. The trace plots will be saved to this as png files. The pixel shift will display all together, but saved separately. --- SpectrumExtractor/spectrum_extractor.py | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/SpectrumExtractor/spectrum_extractor.py b/SpectrumExtractor/spectrum_extractor.py index c6f65f0..39a03d4 100644 --- a/SpectrumExtractor/spectrum_extractor.py +++ b/SpectrumExtractor/spectrum_extractor.py @@ -511,7 +511,7 @@ def Get_SlitShearFunction(ApertureCenters): return ApertureSlitShearFuncDic def CalculateShiftInXD(SpectrumImage, RefImage=None, XDshiftmodel='p0',Coeffmodel='p0', DWindowToUse=None, StripWidth=50, - Apodize=True, bkg_medianfilt=False,dispersion_Xaxis=True,ShowPlot=False): + Apodize=True, bkg_medianfilt=False,dispersion_Xaxis=True,ShowPlot=False, PlotPrifix=None): """ Calculates the avg shift in XD to match SpectrumImage to RefImage Returns Avg_XD_shift coeffiencts in the domain the XD pixels are scaled to -1 to 1 if Coeffmodel is pi, where i >0 then an i degree polynomial fit is made to the coefficents of the XDshift model acorss the dispersion pixels""" @@ -574,10 +574,18 @@ def CalculateShiftInXD(SpectrumImage, RefImage=None, XDshiftmodel='p0',Coeffmode logging.debug('XD offset fit {0}:{1}'.format(i,fitted_driftp)) XDShiftCoeffDict[centerx] = fitted_driftp if ShowPlot: - # plt.figure() + plt.plot(newRefFlux[:,0],newRefFlux[:,1]*fitted_driftp[0],color='k',alpha=0.3, label="Reference aperture position") plt.plot(shifted_pixels,SumApFluxSpectrum,color='g',alpha=0.3, label="Observed aperture position") - # plt.show(block=False) + if PlotPrifix is not None: + fig2, ax2 = plt.subplots(figsize=(8,8)) + ax2.plot(newRefFlux[:,0],newRefFlux[:,1]*fitted_driftp[0],color='k',alpha=0.6, label="Reference aperture position") + ax2.plot(shifted_pixels,SumApFluxSpectrum,color='g',alpha=0.6, label="Observed aperture position") + plt.xlabel('XD pixels') + plt.ylabel('Apodized counts') + ax2.legend() + fig2.savefig(PlotPrifix + "_{}.png".format(i)) + plt.close(fig2) if int(Coeffmodel[1:]) == 0: Avg_XD_shift = biweight_location(np.array(list(XDShiftCoeffDict.values())),axis=0)[1:] #remove the flux scale coeff @@ -1295,7 +1303,17 @@ def main(raw_args=None): logging.warning('WARNING: Output file {0} already exist'.format(OutputFile)) logging.warning('Skipping this image extraction..') sys.exit(1) - + if Config['ShowPlot_Trace']: + parent_dir = os.path.dirname(OutputFile) + plot_dir = os.path.join(parent_dir, "ApertureTrace_Plots") + if not os.path.exists(plot_dir): + os.mkdir(plot_dir) + plot_fname = os.path.splitext(os.path.basename(OutputFile))[0] + plot_fname = os.path.join(plot_dir, plot_fname) + else: + plot_fname = None + + ################################################################################ # Starting Extraction process ################################################################################ @@ -1411,7 +1429,7 @@ def main(raw_args=None): XDshiftmodel=XDshiftmodel,Coeffmodel=DCoeffmodel,DWindowToUse=Config['ReFitApertureInXD_DWindow'], StripWidth=4*Config['AvgHWindow_forTrace'],Apodize=True, bkg_medianfilt=Config['ReFitApertureInXD_BkgMedianFilt'], - dispersion_Xaxis=Config['dispersion_Xaxis'],ShowPlot=Config['ShowPlot_Trace']) + dispersion_Xaxis=Config['dispersion_Xaxis'],ShowPlot=Config['ShowPlot_Trace'],PlotPrifix=plot_fname) logging.info('Fitted shift in XD position :{0} in -1to1 domain of {1}'.format(tuple(Avg_XD_shift),tuple(PixDomain))) # Apply the XD shift to the aperture centers ApertureCenters = ApplyXDshiftToApertureCenters(ApertureCenters,Avg_XD_shift,PixDomain) @@ -1427,7 +1445,7 @@ def main(raw_args=None): if Config['ShowPlot_Trace']: norm = ImageNormalize(SpectrumImage, interval=PercentileInterval(95.), stretch=SqrtStretch()) - fig = plt.figure() + fig = plt.figure(figsize=(12,12)) ax = fig.add_subplot(1, 1, 1) if Config['dispersion_Xaxis']: im = ax.imshow(SpectrumImage, origin='lower', norm=norm, cmap='gray') @@ -1448,6 +1466,8 @@ def main(raw_args=None): ax.plot(x,ApertureTraceFuncDic[order](x)+bkgw_offset,ls='--',color='deeppink') ax.set_title('Fitted Aperture: Star in Cyan & Background in Pink') ax.set_ylim(ylim) + plt.tight_layout() + plt.savefig(plot_fname + "_Frame.png") plt.show() ################################################################################ # Spectral Extraction starts here