Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spectractor/extractor/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def remove_image_background_sextractor(data, sigma=3.0, box_size=(50, 50), filte
plot_image_simple(ax[0], bkg.background, scale="lin")
plot_image_simple(ax[1], data_wo_bkg, scale="symlog")
fig.tight_layout()
plt.show()
if parameters.DISPLAY:
plt.show()
if parameters.PdfPages:
parameters.PdfPages.savefig()
return data_wo_bkg
Expand Down
2 changes: 1 addition & 1 deletion spectractor/extractor/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,4 +1781,4 @@ def plot_comparison_truth(spectrum, w): # pragma: no cover
plt.show()
if parameters.LSST_SAVEFIGPATH:
fig.savefig(os.path.join(parameters.LSST_SAVEFIGPATH, 'deconvolution_truth.pdf'), transparent=True)
plt.show()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erykoff I assume this was deleted because there is a show only 3 lines above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's DISPLAY it should show. This was showing the figure even if DISPLAY was false.


3 changes: 2 additions & 1 deletion spectractor/extractor/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,8 @@ def find_target(image, guess=None, rotated=False, widths=[parameters.XWINDOW, pa
plt.figure(figsize=(5, 5))
plot_image_simple(plt.gca(), data=sub_image_subtracted, scale="lin", title="", units=image.units,
target_pixcoords=[theX - x0 + Dx, theX - x0 + Dx])
plt.show()
if parameters.DISPLAY:
plt.show()
if parameters.PdfPages:
parameters.PdfPages.savefig()

Expand Down
2 changes: 1 addition & 1 deletion spectractor/extractor/spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def build_detected_line_table(self, amplitude_units="", calibration_only=False):
t = Table(rows=rows, names=(
'Line', 'Tabulated', 'Detected', 'Shift', 'Err', 'FWHM', 'Amplitude', 'SNR', 'Chisq', 'Eqwidth_mod',
'Eqwidth_data'),
dtype=('a12', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4'))
dtype=('S12', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4'))
for col in t.colnames[1:6]:
t[col].unit = 'nm'
t[t.colnames[5]].unit = amplitude_units
Expand Down
3 changes: 2 additions & 1 deletion spectractor/extractor/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ def generate_axes(fig):
fig.subplots_adjust(hspace=0)
if save_as:
plt.savefig(save_as)
plt.show()
if parameters.DISPLAY:
plt.show()

def save_spectrum(self, output_file_name, overwrite=False):
"""Save the spectrum into a fits file (data, error and wavelengths).
Expand Down
3 changes: 2 additions & 1 deletion spectractor/fit/fit_multispectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def plot_A1s(self): # pragma: no cover
plt.legend()
if parameters.SAVE:
fig.savefig(self.output_file_name + '_A1s.pdf', dpi=100, bbox_inches='tight')
plt.show()
if parameters.DISPLAY:
plt.show()

def save_transmissions(self):
aerosols, angstrom_exponent, ozone, pwv, reso, *A1s = self.params.values
Expand Down
3 changes: 2 additions & 1 deletion spectractor/fit/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,8 @@ def simple_newton_minimisation(fit_workspace, niter=10, xtol=1e-3, ftol=1e-3):
plt.plot(r, js, label="J")
plt.grid()
plt.legend()
plt.show()
if parameters.DISPLAY:
plt.show()

if parameters.DISPLAY:
fig = plt.figure()
Expand Down
31 changes: 16 additions & 15 deletions spectractor/fit/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def getMaximum(self):

def getTotal(self):
if len(self.axes[-1].axis) > 1:
self.total = np.trapz(y=self.grid, x=self.axes[-1].axis, axis=self.rangedim[-1])
self.total = np.trapezoid(y=self.grid, x=self.axes[-1].axis, axis=self.rangedim[-1])
else:
self.total = np.sum(self.grid)
if self.dim > 1:
for i in reversed(self.rangedim[:-1]):
if len(self.axes[i].axis) > 1:
self.total = np.trapz(y=self.total, x=self.axes[i].axis, axis=i)
self.total = np.trapezoid(y=self.total, x=self.axes[i].axis, axis=i)
else:
self.total = np.sum(self.total, axis=i)
return self.total
Expand All @@ -106,7 +106,7 @@ def normalize(self):

def marginalizeAlongAxis(self, axis_index):
# return(np.sum(self.grid,axis=axis_index))
return np.trapz(self.grid, self.axes[axis_index].axis, axis=axis_index)
return np.trapezoid(self.grid, self.axes[axis_index].axis, axis=axis_index)


class PDF(Grid):
Expand Down Expand Up @@ -174,7 +174,7 @@ def stats(self, verbose=True):
xprod = np.zeros_like(self.grid)
for xindex, x in enumerate(self.axe.axis):
xprod[xindex] = x * self.grid[xindex]
self.mean = np.trapz(xprod, x=self.axe.axis)
self.mean = np.trapezoid(xprod, x=self.axe.axis)
# cumprob = np.cumsum(self.grid)
cumprob = np.zeros_like(self.grid)
cumprob[0] = self.grid[0]
Expand Down Expand Up @@ -226,7 +226,7 @@ def stats(self, verbose=True):
xxprod = np.zeros_like(self.grid)
for xindex, x in enumerate(self.axe.axis):
xxprod[xindex] = self.grid[xindex] * (x - self.mean) ** 2
self.variance = np.trapz(xxprod, self.axe.axis)
self.variance = np.trapezoid(xxprod, self.axe.axis)
txt = "%s: %s +%s -%s (std: %s)" % formatting_numbers(self.mean, self.error_high, self.error_low,
std=np.sqrt(self.variance), label=self.label)
self.title = '$%s^{+%s}_{-%s}$' % formatting_numbers(self.mean, self.error_high, self.error_low)
Expand Down Expand Up @@ -254,9 +254,9 @@ def fill_histogram(self, data1, data2, weights=None):

def covariance(self):
self.normalize()
pdf = np.trapz(y=self.grid, x=self.axes[1].axis, axis=1)
pdf = np.trapezoid(y=self.grid, x=self.axes[1].axis, axis=1)
self.pdfs[0].fill(pdf)
pdf = np.trapz(y=self.grid, x=self.axes[0].axis, axis=0)
pdf = np.trapezoid(y=self.grid, x=self.axes[0].axis, axis=0)
self.pdfs[1].fill(pdf)
if self.pdfs[0].max_pdf is None:
self.pdfs[0].stats(verbose=False)
Expand All @@ -270,7 +270,7 @@ def covariance(self):
for xindex, x in enumerate(self.axes[0].axis):
for yindex, y in enumerate(self.axes[1].axis):
xyprod[xindex][yindex] = (x - self.pdfs[0].mean) * (y - self.pdfs[1].mean) * self.grid[xindex][yindex]
self.cov = np.trapz(np.trapz(y=xyprod, x=self.axes[1].axis, axis=1), self.axes[0].axis, axis=0)
self.cov = np.trapezoid(np.trapezoid(y=xyprod, x=self.axes[1].axis, axis=1), self.axes[0].axis, axis=0)
self.rho = self.cov / (np.sqrt(self.pdfs[0].variance * self.pdfs[1].variance))
return self.cov

Expand Down Expand Up @@ -346,7 +346,8 @@ def plot(self, plot=False, truth=None):
if plot:
plt.xlabel(self.axis_names[0])
plt.ylabel(self.axis_names[1])
plt.show()
if parameters.DISPLAY:
plt.show()
if parameters.PdfPages:
parameters.PdfPages.savefig()

Expand Down Expand Up @@ -394,12 +395,12 @@ def marginalize(self, pdfonly=False): # pragma: no cover
if len(self.axes[axes[-1]].axis) == 1:
pdf = np.sum(self.grid, axis=axes[-1])
else:
pdf = np.trapz(y=self.grid, x=self.axes[axes[-1]].axis, axis=axes[-1])
pdf = np.trapezoid(y=self.grid, x=self.axes[axes[-1]].axis, axis=axes[-1])
for axe in reversed(axes[:-1]):
if len(self.axes[axe].axis) == 1:
pdf = np.sum(pdf, axis=axe)
else:
pdf = np.trapz(y=pdf, x=self.axes[axe].axis, axis=axe)
pdf = np.trapezoid(y=pdf, x=self.axes[axe].axis, axis=axe)
self.pdfs[i].fill(pdf)
else:
self.pdfs[i].fill(self.grid)
Expand All @@ -409,13 +410,13 @@ def marginalize(self, pdfonly=False): # pragma: no cover
if len(self.axes[axes[-1]].axis) == 1:
self.contours[i][j].grid = np.sum(self.grid, axis=axes[-1])
else:
self.contours[i][j].grid = np.trapz(y=self.grid, x=self.axes[axes[-1]].axis,
self.contours[i][j].grid = np.trapezoid(y=self.grid, x=self.axes[axes[-1]].axis,
axis=axes[-1])
for axe in reversed(axes[:-1]):
if len(self.axes[axe].axis) == 1:
self.contours[i][j].grid = np.sum(self.contours[i][j].grid, axis=axe)
else:
self.contours[i][j].grid = np.trapz(y=self.contours[i][j].grid,
self.contours[i][j].grid = np.trapezoid(y=self.contours[i][j].grid,
x=self.axes[axe].axis, axis=axe)
if i < j:
self.contours[i][j].grid = self.contours[i][j].grid.T
Expand Down Expand Up @@ -962,5 +963,5 @@ def run_emcee(mcmc_fit_workspace, ln=lnprob):
p0 = sampler.get_last_sample()
for _ in sampler.sample(p0, iterations=max(0, nsamples - backend.iteration), progress=True, store=True):
continue
mcmc_fit_workspace.chains = sampler.chain
mcmc_fit_workspace.lnprobs = sampler.lnprobability
mcmc_fit_workspace.chains = sampler.get_chain()
mcmc_fit_workspace.lnprobs = sampler.get_log_prob()
4 changes: 2 additions & 2 deletions spectractor/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def __getattr__(name):

# Plots
DISPLAY = True
if os.environ.get('DISPLAY', '') == '':
mpl.use('agg')
backend = mpl.get_backend()
if os.environ.get('DISPLAY', '') == '' or backend.lower() in ["agg", "pdf", "ps", "svg", "pgf", "cairo"]:
DISPLAY = False
PLOT_XLABEL = r"$x$ [pixels]"
PLOT_YLABEL = r"$y$ [pixels]"
Expand Down
2 changes: 2 additions & 0 deletions ups/spectractor.table
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
setupRequired(utils)

envPrepend(PYTHONPATH, ${PRODUCT_DIR}/lib/python)
Loading