Commit 1da1e008 authored by Simon Conseil's avatar Simon Conseil

Merge branch 'imports' into 'master'

Delay matplotlib and other imports to speedup mpdaf import

See merge request !156
parents 4c79dda0 d7f1700f
Pipeline #2839 failed with stage
in 28 minutes and 31 seconds
......@@ -34,7 +34,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import astropy.units as u
import numpy as np
from astropy.modeling.models import Moffat2D, Gaussian2D
from astropy.stats import gaussian_fwhm_to_sigma
from scipy import special
......@@ -175,6 +174,7 @@ def Moffat(step_arcsec, Nfsf, beta, fwhm):
center = Nfsf // 2
yy, xx = np.mgrid[:Nfsf, :Nfsf]
from astropy.modeling.models import Moffat2D
if np.isscalar(alpha):
moffat = Moffat2D(amplitude, center, center, alpha, beta)
PSF_Moffat = moffat(xx, yy)
......@@ -395,6 +395,7 @@ def create_psf_cube(shape, fwhm, beta=None, wcs=None, unit_fwhm=u.arcsec):
if unit_fwhm is not None:
fwhm = fwhm / wcs.get_step(unit=unit_fwhm)[0]
from astropy.modeling.models import Moffat2D, Gaussian2D
if beta is None:
# a Gaussian expected.
stddev = fwhm * gaussian_fwhm_to_sigma
......
......@@ -36,8 +36,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import astropy.units as u
import datetime
import logging
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import warnings
......@@ -350,6 +348,7 @@ def plot_autocal_factors(filename, savefig=None, plot_rejected=False,
Colormap.
"""
import matplotlib.pyplot as plt
t = Table.read(filename) if isinstance(filename, str) else filename
fig, axes = plt.subplots(6, 4, figsize=(4 * figsize, 6 * figsize),
sharex=sharex, sharey=sharey)
......@@ -382,6 +381,7 @@ def plot_autocal_factors(filename, savefig=None, plot_rejected=False,
fig.suptitle('{} (y) for each wavelength segment (x), each slice (color) '
'and each IFU'.format(title), fontsize=16)
import matplotlib as mpl
bounds = np.linspace(0, 48, 49)
norm = mpl.colors.BoundaryNorm(bounds, cm.N)
ax2 = fig.add_axes([0.1, 0.96, 0.8, 0.01])
......
......@@ -33,12 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import logging
import matplotlib.pyplot as plt
import numpy as np
import os
from astropy.io import fits
from scipy.integrate import quad
from ..obj import Image, WCS
......@@ -429,6 +427,7 @@ class RawFile:
Additional options passed to ``Image.plot``.
"""
import matplotlib.pyplot as plt
fig = plt.figure(figsize=figsize)
fig.subplots_adjust(wspace=0.02, hspace=0.01)
......@@ -484,6 +483,7 @@ class RawFile:
if channels == "all":
channels = self.get_channels_extname_list()
from scipy.integrate import quad
raw_mask = RawFile(mask)
white_ima = np.zeros((12 * 24, 300))
......@@ -545,6 +545,8 @@ class RawFile:
# plot channel
ymin = NB_SLICES * (24 - ifu) - 0.5
ymax = ymin + NB_SLICES
import matplotlib.pyplot as plt
plt.plot(np.arange(-0.5, 299.5), np.ones(300) * ymin, 'b-')
plt.plot(np.arange(-0.5, 299.5), np.ones(300) * ymax, 'b-')
plt.annotate('%02d' % ifu, xy=(0, (ymin + ymax) / 2.0),
......@@ -585,6 +587,7 @@ class RawFile:
if yend > (mhdr["ESO DET CHIP NY"] / 2.0):
yend -= 2 * OVERSCAN
import matplotlib.pyplot as plt
plt.plot(np.arange(xstart, xend + 1),
np.ones(xend + 1 - xstart) * ystart, 'r-')
plt.plot(np.arange(xstart, xend + 1),
......@@ -604,6 +607,7 @@ class RawFile:
if event.button != 1:
if event.inaxes is not None:
if (event.x < self.fig.canvas.get_width_height()[0] // 2):
import matplotlib.pyplot as plt
p = event.ydata
q = event.xdata
ifu = 24 - int(p + 0.5) // NB_SLICES
......@@ -660,7 +664,9 @@ class RawFile:
channels=channels)
# highlighted ifu
selected_ifu = 12
# plot white image
import matplotlib.pyplot as plt
self.fig = plt.figure()
plt.subplot(1, 2, 1)
self._plot_ifu_slice_on_white_image(selected_ifu, 1)
......
......@@ -38,7 +38,6 @@ import logging
import numbers
import numpy as np
from astropy.coordinates import Angle
from astropy.io import fits
from .objs import UnitArray
......@@ -128,6 +127,7 @@ def deg2hms(x):
form, hours:minutes:seconds.
"""
from astropy.coordinates import Angle
ac = Angle(x, unit='degree')
hms = ac.to_string(unit='hour', sep=':', pad=True)
return str(hms)
......@@ -147,6 +147,7 @@ def hms2deg(x):
The angle as a number of degrees.
"""
from astropy.coordinates import Angle
ac = Angle(x, unit='hour')
deg = float(ac.to_string(unit='degree', decimal=True))
return deg
......@@ -166,6 +167,7 @@ def deg2dms(x):
The input angle as a string, written as degrees:minutes:seconds.
"""
from astropy.coordinates import Angle
ac = Angle(x, unit='degree')
dms = ac.to_string(unit='degree', sep=':', pad=True)
return str(dms)
......@@ -185,6 +187,7 @@ def dms2deg(x):
The input angle as a number of degrees.
"""
from astropy.coordinates import Angle
ac = Angle(x, unit='degree')
deg = float(ac.to_string(unit='degree', decimal=True))
return deg
......@@ -343,6 +346,7 @@ def axis_increments_from_cd(cd):
# Wrap the difference east-north into the range -pi to pi radians.
from astropy.coordinates import Angle
delta = Angle((east - north) * u.rad).wrap_at(np.pi * u.rad).value
# If east is anticlockwise of north make the X-axis pixel increment
......
......@@ -44,9 +44,8 @@ import types
import warnings
from astropy.io import fits
from matplotlib.path import Path
from numpy import ma
from scipy import integrate, interpolate, signal, ndimage as ndi
from scipy import interpolate, signal, ndimage as ndi
from .arithmetic import ArithmeticMixin
from .data import DataArray
......@@ -556,6 +555,7 @@ class Cube(ArithmeticMixin, DataArray):
# Use a matplotlib method to create a path, which is the polygon we
# want to use.
from matplotlib.path import Path
polymask = Path(poly)
# Go through all pixels in the image to see if they are within the
......@@ -1639,6 +1639,7 @@ class Cube(ArithmeticMixin, DataArray):
of the filter curve.
"""
from scipy import integrate
wavelengths = np.asarray(wavelengths, dtype=float)
sensitivities = np.asarray(sensitivities, dtype=float)
......
......@@ -39,14 +39,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import logging
import matplotlib.pyplot as plt
import numpy as np
from numpy import ma
import astropy.units as u
from astropy.io import fits
from astropy.stats import gaussian_sigma_to_fwhm, gaussian_fwhm_to_sigma
from astropy.visualization import ZScaleInterval
from scipy import interpolate, signal
from scipy import ndimage as ndi
from scipy.ndimage.interpolation import affine_transform
......@@ -3725,6 +3723,7 @@ class Image(ArithmeticMixin, DataArray):
out : matplotlib AxesImage
"""
import matplotlib.pyplot as plt
cax = None
# Default X and Y axes are labeled in pixels.
xlabel = 'q (pixel)'
......@@ -4006,7 +4005,7 @@ def get_plot_norm(data, vmin=None, vmax=None, zscale=False, scale='linear'):
# Choose vmin and vmax automatically?
if zscale:
interval = ZScaleInterval()
interval = viz.ZScaleInterval()
if data.dtype == np.float64:
try:
vmin, vmax = interval.get_limits(data.filled(np.nan))
......@@ -4139,6 +4138,7 @@ def plot_rgb(images, title=None, scale='linear', vmin=None, vmax=None,
ylabel = 'p (pixel)'
if ax is None:
import matplotlib.pyplot as plt
if use_wcs:
ax = plt.subplot(projection=images[0].wcs.wcs)
xlabel = 'ra'
......
......@@ -34,7 +34,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import matplotlib.pyplot as plt
import numpy as np
import types
......@@ -1500,6 +1499,7 @@ class Spectrum(ArithmeticMixin, DataArray):
err = [np.nan] * len(v)
if plot:
import matplotlib.pyplot as plt
xxx = np.arange(l[0], l[-1], (l[1] - l[0]) / plot_factor)
ccc = gaussfit(v, xxx)
plt.plot(xxx, ccc, 'r--')
......@@ -1724,8 +1724,8 @@ class Spectrum(ArithmeticMixin, DataArray):
else:
err = None
# plot
if plot:
import matplotlib.pyplot as plt
xxx = np.arange(l[0], l[-1], (l[1] - l[0]) / plot_factor)
ccc = gaussfit(v, xxx)
plt.plot(xxx, ccc, 'r--')
......@@ -1916,7 +1916,8 @@ class Spectrum(ArithmeticMixin, DataArray):
err = None
if plot:
# Same wavelenght grid as input spectrum
# Same wavelength grid as input spectrum
import matplotlib.pyplot as plt
xxx = np.arange(l[0], l[-1], (l[1] - l[0]) / plot_factor)
ccc = asymfit(v, xxx)
if ax is None:
......@@ -2366,6 +2367,7 @@ class Spectrum(ArithmeticMixin, DataArray):
"""
# Create an Axes instance for the plot?
import matplotlib.pyplot as plt
if ax is None:
ax = plt.gca()
......
......@@ -42,8 +42,6 @@ import sys
from astropy.coordinates import SkyCoord
from astropy.table import Table, Column, MaskedColumn, hstack, vstack, join
from astropy import units as u
from matplotlib.patches import Circle, Rectangle, Ellipse, RegularPolygon
from ..tools import deprecated, LowercaseOrderedDict
......@@ -1120,10 +1118,9 @@ class Catalog(Table):
if label and (id not in self.colnames):
raise IOError('column %s not found in catalog' % id)
from matplotlib.patches import Circle, Rectangle, RegularPolygon
texts = []
step = wcs.get_step(unit=u.arcsec)
arr = np.vstack([self[dec].data, self[ra].data]).T
arr = wcs.sky2pix(arr, unit=u.deg)
......@@ -1238,6 +1235,7 @@ class Catalog(Table):
if iden not in self.colnames:
raise IOError('column %s not found in catalog' % iden)
from matplotlib.patches import Ellipse
ellipse_kwargs = ellipse_kwargs or {}
cat = self.select(wcs, ra, dec)
size = 2 * symb / wcs.get_step(unit=u.arcsec)[0]
......
......@@ -50,8 +50,6 @@ import warnings
from astropy.io import fits as pyfits
from astropy.table import Table, MaskedColumn, vstack
from functools import partial
from matplotlib import cm
from matplotlib.patches import Ellipse
from numpy import ma
from scipy.optimize import leastsq
......@@ -1953,7 +1951,7 @@ class Source:
self.lines = vstack([subtab1, subtab2[0:n2]])
def show_ima(self, ax, name, showcenter=None,
cuts=None, cmap=cm.gray_r, **kwargs):
cuts=None, cmap='gray_r', **kwargs):
"""Show image.
Parameters
......@@ -1985,6 +1983,7 @@ class Source:
kwargs['title'] = '%s' % (name)
zima.plot(vmin=vmin, vmax=vmax, cmap=cmap, ax=ax, **kwargs)
if showcenter is not None:
from matplotlib.patches import Ellipse
rad, col = showcenter
pix = zima.wcs.sky2pix((self.DEC, self.RA))[0]
rpix = rad / zima.wcs.get_step(unit=u.arcsec)[0]
......@@ -2038,9 +2037,10 @@ class Source:
kwargs['title'] = ' '.join(names)
_, images_aligned = plot_rgb(images, vmin=vmin, vmax=vmax, ax=ax,
**kwargs)
**kwargs)
if showcenter is not None:
from matplotlib.patches import Ellipse
rad, col = showcenter
pix = images_aligned[0].wcs.sky2pix((self.DEC, self.RA))[0]
rpix = rad / images_aligned[0].wcs.get_step(unit=u.arcsec)[0]
......
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