API Documentation

class koala.CUBE(filename)[source]

This class reads the FITS files with COMBINED datacubes.

Routines included:

  • cube.map_wavelength(wavelength, contours=True)

  • cube.plot_spectrum_cube(x,y, fcal=True)

ADR_correction(plot=True, force_ADR=False)

Correct for Atmospheric Diferential Refraction (ADR)

Parameters
  • plot

  • force_ADR

RSS_image(image=[0], norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='seismic_r', clow=0, chigh=0, labelpad=10, title=' - RSS image', color_bar_text='Integrated Flux [Arbitrary units]', fig_size=13.5)

Plot RSS image coloured by variable. cmap = “binary_r” nice greyscale

Parameters
  • image

  • norm

  • cmap

  • clow

  • chigh

  • labelpad

  • title

  • color_bar_text

  • fig_size

RSS_map(variable, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, list_spectra=[], title=' - RSS map', color_bar_text='Integrated Flux [Arbitrary units]')

Plot map showing the offsets, coloured by variable.

Parameters
  • variable

  • norm

  • list_spectra

  • title

  • color_bar_text

add_spectrum(intensity, offset_rows, offset_cols)

Add one single spectrum to the datacube

Parameters
  • intensity (np.array(float)) – Spectrum.

  • offset_rows (float) – Offset with respect to the image centre, in pixels.

  • offset_cols (float) – Offset with respect to the image centre, in pixels.

  • kernel_FWHM_pixels (float) – FWHM of the interpolating kernel, in pixels

calculateRatio(x, y, aStart, aEnd, bStart, bEnd, fcal=False)[source]

Given two wavelengths ranges, find the peak intensities and calculate the ratio between them.

Parameters
  • x – The spaxel we are interested in.

  • y – The spaxel we are interested in.

  • aStart – The startpoint and endpoint of the range that the first emission line will fall in.

  • aEnd – The startpoint and endpoint of the range that the first emission line will fall in.

  • bStart – The startpoint and endpoint of the range that the second emission line will fall in.

  • bEnd – The startpoint and endpoint of the range that the second emission line will fall in.

clean_sky_residuals(extra_w=1.3, step=25, dclip=3.0, wave_min=0, wave_max=0, verbose=False, plot=False, fig_size=12, fibre=0)

This task HAVE TO BE USED WITH EXTREME CARE as it has not been properly tested!!! It CAN DELETE REAL (faint) ABSORPTION/EMISSION features in spectra!!! Use the “1dfit” option for getting a better sky substraction ANGEL is keeping this here just in case it is eventually useful…

Parameters
  • extra_w

  • step

  • dclip

  • wave_min

  • wave_max

  • verbose

  • plot

  • fig_size

  • fibre

compute_integrated_fibre(list_spectra='all', valid_wave_min=0, valid_wave_max=0, min_value=0.1, plot=False, title=' - Integrated values', text='...', correct_negative_sky=False)

Compute the integrated flux of a fibre in a particular range, valid_wave_min to valid_wave_max.

Parameters
  • list_spectra (float (default "all")) – list with the number of fibres for computing integrated value if using “all” it does all fibres

  • valid_wave_min (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • valid_wave_max (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • min_value (float (default 0)) – For values lower than min_value, we set them as min_value

  • plot (Boolean (default = False)) – Plot

  • title (string) – Title for the plot

  • text (string) – A bit of extra text

  • correct_negative_sky (Boolean (default = False)) – Corrects negative values making 0 the integrated flux of the lowest fibre

Example

integrated_fibre_6500_6600 = star1r.compute_integrated_fibre(valid_wave_min=6500, valid_wave_max=6600, title = ” - [6500,6600]”, plot = True)

correct_high_cosmics_and_defects(step=50, correct_high_cosmics=False, fibre_p=0, remove_5578=False, clip_high=100, plot=True, plot_suspicious_fibres=True, verbose=False, fig_size=12)

Task for correcting high cosmics and CCD defects using median values of nearby pixels. 2dFdr corrects for (the majority) of the cosmic rays, usually correct_high_cosmics = False. ANGEL COMMENT: Check, probably can be improved using MATT median running + plotting outside

Parameters
  • rect_high_cosmics (boolean (default = False)) – Correct ONLY CCD defects

  • re_p (integer (default = 0)) – Plots the corrections in fibre fibre_p

  • ove_5578 (boolean (default = False)) – Removes skyline 5578 (blue spectrum) using Gaussian fit ND CHECK: This also MODIFIES the throughput correction correcting for flux_5578_medfilt /median_flux_5578_medfilt

  • step (integer (default = 50)) – Number of points for calculating median value

  • clip_high (float (default = 100)) –

    Minimum value of flux/median in a pixel to be consider as a cosmic

    if s[wave] > clip_high*fit_median[wave] -> IT IS A COSMIC

  • verbose (boolean (default = False)) – Write results

  • plot (boolean (default = False)) – Plot results

  • plot_suspicious_fibres (boolean (default = False)) – Plots fibre(s) that could have a cosmic left (but it could be OK) IF self.integrated_fibre[fibre]/median_running[fibre] > max_value -> SUSPICIOUS FIBRE

Example

>>> self.correct_high_cosmics_and_defects(
...    correct_high_cosmics=False, step=40, remove_5578=True,
...    clip_high=120, plot_suspicious_fibres=True, verbose=False,
...    plot=True
... )
create_map(wavelength1, wavelength2, name='NEW_MAP')

Create map adding maps in a wavelength range.”

Parameters
  • wavelength1 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • wavelength2 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • map_name (string) – String with the name of the map, must be the same than file created here.

Example

>>> a = cube.create_map(6810,6830, "a")
> Created map with name  a  integrating range [ 6810 , 6830 ]
do_extinction_curve(observatory_file='/home/docs/checkouts/readthedocs.org/user_builds/pykoala/checkouts/master/src/koala/data/ssoextinct.dat', plot=True)
Parameters
  • observatory_file

  • plot

do_response_curve(filename, min_wave=0, max_wave=0, step=25.0, fit_degree=3, exp_time=60, smooth=0.03, ha_width=0, plot=True, verbose=False)

Compute the response curve of a spectrophotometric star.

Parameters
  • filename (string) – filename where the spectrophotometric data are included (e.g. ffeige56.dat)

  • min_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • max_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • 25 (step =) – Step (in A) for smoothing the data

  • 3 (fit_degree =) – degree of the polynomium used for the fit (3, 5, or 7). If fit_degree = 0 it interpolates the data

  • 60 (exp_time =) – Exposition time of the calibration star

  • 0.03 (smooth =) – Smooth value for interpolating the data for fit_degree = 0.

  • plot (boolean) – Plot yes/no

Example

>>> babbsdsad
find_relative_throughput(ymin=10000, ymax=200000, kernel_sky_spectrum=5, wave_min_scale=0, wave_max_scale=0, plot=True)

Determine the relative transmission of each spectrum using a skyflat.

Parameters
  • ymin

  • ymax

  • kernel_sky_spectrum

  • wave_min_scale

  • wave_max_scale

  • plot

find_sky_emission(intensidad=[0, 0], plot=True, n_sky=200, sky_fibres=[1000], sky_wave_min=0, sky_wave_max=0, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>)
Parameters
  • intensidad

  • plot

  • n_sky

  • sky_fibres

  • sky_wave_min

  • sky_wave_max

  • norm

fit_Moffat_between(min_wave=0, max_wave=0, r_max=5, plot=False)
Parameters
  • min_wave

  • max_wave

  • r_max

  • plot

fit_and_substract_sky_spectrum(sky, w=1000, spectra=1000, rebin=False, brightest_line='Ha', brightest_line_wavelength=6563.0, maxima_sigma=3.0, ymin=- 50, ymax=1000, wmin=0, wmax=0, auto_scale_sky=False, verbose=False, plot=False, fig_size=12, fibre=0)

Given a 1D sky spectrum, this task fits sky lines of each spectrum individually and substracts sky Needs the observed wavelength (brightest_line_wavelength) of the brightest emission line (brightest_line) . w is the wavelength spec the 2D spectra

Parameters
  • sky

  • w

  • spectra

  • rebin

  • brightest_line

  • brightest_line_wavelength

  • maxima_sigma

  • ymin

  • ymax

  • wmin

  • wmax

  • auto_scale_sky

  • verbose

  • plot

  • fig_size

  • fibre

fix_2dfdr_wavelengths(sol=[0, 0, 0], fibre=0, maxima_sigma=2.5, maxima_offset=1.5, xmin=7740, xmax=7770, ymin=0, ymax=1000, plot=True, verbose=True)
Parameters
  • sol

  • fibre

  • maxima_sigma

  • maxima_offset

  • xmin

  • xmax

  • ymin

  • ymax

  • plot

  • verbose

flux_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

get_integrated_map_and_plot(min_wave=[0], max_wave=[0], plot=True, fcal=False)

Integrated map and plot

Parameters
  • min_wave

  • max_wave

  • plot

  • fcal

get_telluric_correction(n_fibres=10, correct_from=6850.0, correct_to=10000.0, apply_tc=False, step=10, combined_cube=False, weight_fit_median=0.5, exclude_wlm=[[6450, 6700], [6850, 7050], [7130, 7380]], wave_min=0, wave_max=0, plot=True, fig_size=12, verbose=False)

# TODO BLAKE: always use false, use plots to make sure it’s good. prob just save as a different file. Get telluric correction using a spectrophotometric star

Parameters
  • n_fibres (integer) – number of fibers to add for obtaining spectrum

  • correct_from (float) – wavelength from which telluric correction is applied (default = 6850)

  • apply_tc (boolean (default = False)) – apply telluric correction to data

  • exclude_wlm=[[6450 – Wavelength ranges not considering for normalising stellar continuum

  • 6700] – Wavelength ranges not considering for normalising stellar continuum

  • [6850 – Wavelength ranges not considering for normalising stellar continuum

  • 7050] – Wavelength ranges not considering for normalising stellar continuum

  • [7130 – Wavelength ranges not considering for normalising stellar continuum

  • 7380]] – Wavelength ranges not considering for normalising stellar continuum

Example

telluric_correction_star1 = star1r.get_telluric_correction(n_fibres=15)

growth_curve_between(min_wave=0, max_wave=0, plot=False, verbose=False)

Compute growth curve in a wavelength range. Returns r2_growth_curve, F_growth_curve, flux, r2_half_light

Parameters
  • min_wave (floats) – wavelength range = [min_wave, max_wave].

  • max_wave (floats) – wavelength range = [min_wave, max_wave].

  • plot (boolean) – Plot yes/no

Example

>>>r2_growth_curve, F_growth_curve, flux, r2_half_light = self.growth_curve_between(min_wave, max_wave, plot=True) # 0,1E30 ??

half_light_spectrum(r_max=1, plot=False, smooth=21, min_wave=0, max_wave=0)

Compute half light spectrum (for r_max=1) or integrated star spectrum (for r_max=5) in a wavelength range.

Parameters
  • 1 (r_max =) – r_max to integrate, in units of r2_half_light (= seeing if object is a star, for flux calibration make r_max=5)

  • min_wave (floats) – wavelength range = [min_wave, max_wave]

  • max_wave (floats) – wavelength range = [min_wave, max_wave]

  • 21 (smooth =) – smooth the data

  • plot (boolean) – Plot yes/no

Example

>>> self.half_light_spectrum(5, plot=plot, min_wave=min_wave, max_wave=max_wave)
identify_el(high_fibres=10, brightest_line='Ha', cut=1.5, fibre=0, broad=1.0, verbose=True, plot=True)

Identify fibres with highest intensity (high_fibres=10). Add all in a single spectrum. Identify emission features. These emission features should be those expected in all the cube! Also, choosing fibre=number, it identifies el in a particular fibre.

Parameters
  • high_fibres (float (default 10)) – use the high_fibres highest intensity fibres for identifying

  • brightest_line (string (default "Ha")) – string name with the emission line that is expected to be the brightest in integrated spectrum

  • cut (float (default 1.5)) – The peak has to have a cut higher than cut to be considered as emission line

  • fibre (integer (default 0)) – If fibre is given, it identifies emission lines in the given fibre

  • broad (float (default 1.0)) – Broad (FWHM) of the expected emission lines

  • verbose (boolean (default = True)) – Write results

  • plot (boolean (default = False)) – Plot results

Example

self.el=self.identify_el(high_fibres=10, brightest_line = “Ha”,

cut=2., verbose=True, plot=True, fibre=0, broad=1.5)

line_flux(left_min, left_max, line_min, line_max, right_min, right_max, list_spectra=[])
Parameters
  • left_min

  • left_max

  • line_min

  • line_max

  • right_min

  • right_max

  • list_spectra

map_wavelength(wavelength, cmap='fuego', fig_size=10, norm=<MagicMock name='mock.colors.PowerNorm()' id='140524774247760'>, save_file='', contours=True, fcal=False)[source]

Plot map at a particular wavelength.

Parameters
  • wavelength (float) – wavelength to be mapped.

  • norm

    Colour scale, default = colors.PowerNorm(gamma=1./4.)

    Log scale: norm=colors.LogNorm()

    Lineal scale: norm=colors.Normalize().

  • cmap

    Color map used, default cmap=”fuego”

    Weight: cmap = “gist_gray”

    Velocities: cmap=”seismic”.

    Try also “inferno”,

  • save_file – (Optional) Save plot in file “file.extension”

Example

>>> cube.map_wavelength(6820, contours=True, cmap="seismic")
median_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

plot_combined_spectrum(list_spectra='all', sky=True, median=False, xmin='', xmax='', ymax='', ymin='', fig_size=10, save_file='', plot=True)

Plot combined spectrum of a list and return the combined spectrum.

Parameters
  • list_spectra – spaxels to show combined spectrum. Default is all.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_corrected_vs_uncorrected_spectrum(high_fibres=10, fig_size=12)
Parameters
  • high_fibres

  • fig_size

plot_map(mapa, cmap='fuego', fig_size=10, norm=<MagicMock name='mock.colors.PowerNorm()' id='140524774247760'>, save_file='', contours=True, title='', vmin=0, vmax=1000, fcal=False, log=False, clabel=False, barlabel='')[source]

Plot a given map.

Parameters
  • wavelength (float) – wavelength to be mapped.

  • norm

    Colour scale, default = colors.PowerNorm(gamma=1./4.)

    Log scale: norm=colors.LogNorm()

    Lineal scale: norm=colors.Normalize().

  • cmap

    Color map used, default cmap=”fuego”

    Weight: cmap = “gist_gray”

    Velocities: cmap=”seismic”.

    Try also “inferno”,

  • save_file – (Optional) Save plot in file “file.extension”

Example

>>> cube.plot_map(mapa, contours=True, cmap="seismic")
plot_spectra(list_spectra='all', wavelength_range=[0], xmin='', xmax='', ymax=1000, ymin=- 100, fig_size=10, save_file='', sky=True)

Plot spectrum of a list pf spaxels.

Parameters
  • list_spectra – spaxels to show spectrum. Default is all.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> rss1.plot_spectra([1200,1300])
plot_spectrum(spectrum_number, sky=True, xmin=0, xmax=0, ymax=0, ymin=0)

Plot spectrum of a particular spaxel.

Parameters
  • spectrum_number – spaxel to show spectrum.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_spectrum_cube(x, y, lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10.0, fig_size_y=0.0, save_file='', title='', z=0.0)

Plot spectrum of a particular spaxel.

Parameters
  • x – coordenates of spaxel to show spectrum.

  • y – coordenates of spaxel to show spectrum.

  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_spectrum_cube_ben(x, y, lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fig_size=10, save_file='', fcal=False)[source]

Plot spectrum of a particular spaxel.

Parameters
  • x – coordenates of spaxel to show spectrum.

  • y – coordenates of spaxel to show spectrum.

  • lmin – The range of wavelengths to plot. Default is whole spectrum.

  • lmax – The range of wavelengths to plot. Default is whole spectrum.

  • fmin – Plot spectrum in flux range [fmin, fmax]

  • fmax – Plot spectrum in flux range [fmin, fmax]

  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube_ben(20, 20, fcal=True)
plot_spectrum_integrated_cube(lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10, save_file='')

Plot integrated spectrum

Parameters
  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_wavelength(wavelength, w2=0.0, cmap=<MagicMock name='mock.colors.LinearSegmentedColormap.from_list()' id='140524763892048'>, fig_size=10, norm=<MagicMock name='mock.colors.PowerNorm()' id='140524774247760'>, save_file='', fcal=False)

Plot map at a particular wavelength or in a wavelength range

Parameters
  • wavelength (float) – wavelength to be mapped.

  • norm

    Colour scale, default = colors.PowerNorm(gamma=1./4.)

    Normalization scale Lineal scale: norm=colors.Normalize(). Log scale:norm=colors.LogNorm()

  • cmap – Color map used, default cmap=fuego_color_map Velocities: cmap=”seismic”

  • save_file – (Optional) Save plot in file “file.extension”

plot_weight(norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='gist_gray', fig_size=10, save_file='')

Plot weitgh map.”

Example

>>> cube1s.plot_weight()
subtractContinuum(spectrum)[source]

Subtract the median value from each intensity in a provided spectrum.

Parameters

spectrum – The list of intensities.

trace_peak(edgelow=10, edgehigh=10, plot=False, ADR=False, smoothfactor=2)
Parameters
  • edgelow

  • edgehigh

  • plot

  • ADR

  • smoothfactor

class koala.Interpolated_cube(RSS, pixel_size_arcsec, kernel_size_arcsec, centre_deg=[], size_arcsec=[], aligned_coor=False, plot=False, flux_calibration=[0], zeros=False, ADR=False, force_ADR=False, offsets_files='', offsets_files_position='', shape=[], rss_file='')[source]

Constructs a cube by accumulating RSS with given offsets.

ADR_correction(plot=True, force_ADR=False)[source]

Correct for Atmospheric Diferential Refraction (ADR)

Parameters
  • plot

  • force_ADR

add_spectrum(intensity, offset_rows, offset_cols)[source]

Add one single spectrum to the datacube

Parameters
  • intensity (np.array(float)) – Spectrum.

  • offset_rows (float) – Offset with respect to the image centre, in pixels.

  • offset_cols (float) – Offset with respect to the image centre, in pixels.

  • kernel_FWHM_pixels (float) – FWHM of the interpolating kernel, in pixels

create_map(wavelength1, wavelength2, name='NEW_MAP')[source]

Create map adding maps in a wavelength range.”

Parameters
  • wavelength1 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • wavelength2 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • map_name (string) – String with the name of the map, must be the same than file created here.

Example

>>> a = cube.create_map(6810,6830, "a")
> Created map with name  a  integrating range [ 6810 , 6830 ]
do_response_curve(filename, min_wave=0, max_wave=0, step=25.0, fit_degree=3, exp_time=60, smooth=0.03, ha_width=0, plot=True, verbose=False)[source]

Compute the response curve of a spectrophotometric star.

Parameters
  • filename (string) – filename where the spectrophotometric data are included (e.g. ffeige56.dat)

  • min_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • max_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • 25 (step =) – Step (in A) for smoothing the data

  • 3 (fit_degree =) – degree of the polynomium used for the fit (3, 5, or 7). If fit_degree = 0 it interpolates the data

  • 60 (exp_time =) – Exposition time of the calibration star

  • 0.03 (smooth =) – Smooth value for interpolating the data for fit_degree = 0.

  • plot (boolean) – Plot yes/no

Example

>>> babbsdsad
fit_Moffat_between(min_wave=0, max_wave=0, r_max=5, plot=False)[source]
Parameters
  • min_wave

  • max_wave

  • r_max

  • plot

get_integrated_map_and_plot(min_wave=[0], max_wave=[0], plot=True, fcal=False)[source]

Integrated map and plot

Parameters
  • min_wave

  • max_wave

  • plot

  • fcal

growth_curve_between(min_wave=0, max_wave=0, plot=False, verbose=False)[source]

Compute growth curve in a wavelength range. Returns r2_growth_curve, F_growth_curve, flux, r2_half_light

Parameters
  • min_wave (floats) – wavelength range = [min_wave, max_wave].

  • max_wave (floats) – wavelength range = [min_wave, max_wave].

  • plot (boolean) – Plot yes/no

Example

>>>r2_growth_curve, F_growth_curve, flux, r2_half_light = self.growth_curve_between(min_wave, max_wave, plot=True) # 0,1E30 ??

half_light_spectrum(r_max=1, plot=False, smooth=21, min_wave=0, max_wave=0)[source]

Compute half light spectrum (for r_max=1) or integrated star spectrum (for r_max=5) in a wavelength range.

Parameters
  • 1 (r_max =) – r_max to integrate, in units of r2_half_light (= seeing if object is a star, for flux calibration make r_max=5)

  • min_wave (floats) – wavelength range = [min_wave, max_wave]

  • max_wave (floats) – wavelength range = [min_wave, max_wave]

  • 21 (smooth =) – smooth the data

  • plot (boolean) – Plot yes/no

Example

>>> self.half_light_spectrum(5, plot=plot, min_wave=min_wave, max_wave=max_wave)
plot_map(mapa='', norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='fuego', fig_size=10, fcal=False, save_file='', description='', contours=True, clabel=False, spaxel=0, spaxel2=0, spaxel3=0)[source]

Show a given map.

Parameters
  • map (np.array(float)) – Map to be plotted. If not given, it plots the integrated map.

  • norm – Normalization scale, default is lineal scale. Lineal scale: norm=colors.Normalize(). Log scale: norm=colors.LogNorm() Power law: norm=colors.PowerNorm(gamma=1./4.)

  • cmap ((default cmap="fuego")) – Color map used. Weight: cmap = “gist_gray” Velocities: cmap=”seismic”. Try also “inferno”,

  • spaxel – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

  • spaxel2 – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

  • spaxel3 – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

plot_spectrum_cube(x, y, lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10.0, fig_size_y=0.0, save_file='', title='', z=0.0)[source]

Plot spectrum of a particular spaxel.

Parameters
  • x – coordenates of spaxel to show spectrum.

  • y – coordenates of spaxel to show spectrum.

  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_spectrum_integrated_cube(lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10, save_file='')[source]

Plot integrated spectrum

Parameters
  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_wavelength(wavelength, w2=0.0, cmap=<MagicMock name='mock.colors.LinearSegmentedColormap.from_list()' id='140524763892048'>, fig_size=10, norm=<MagicMock name='mock.colors.PowerNorm()' id='140524774247760'>, save_file='', fcal=False)[source]

Plot map at a particular wavelength or in a wavelength range

Parameters
  • wavelength (float) – wavelength to be mapped.

  • norm

    Colour scale, default = colors.PowerNorm(gamma=1./4.)

    Normalization scale Lineal scale: norm=colors.Normalize(). Log scale:norm=colors.LogNorm()

  • cmap – Color map used, default cmap=fuego_color_map Velocities: cmap=”seismic”

  • save_file – (Optional) Save plot in file “file.extension”

plot_weight(norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='gist_gray', fig_size=10, save_file='')[source]

Plot weitgh map.”

Example

>>> cube1s.plot_weight()
trace_peak(edgelow=10, edgehigh=10, plot=False, ADR=False, smoothfactor=2)[source]
Parameters
  • edgelow

  • edgehigh

  • plot

  • ADR

  • smoothfactor

class koala.KOALA_RSS(filename, save_rss_to_fits_file='', rss_clean=False, apply_throughput=True, skyflat='', plot_skyflat=False, flat='', nskyflat=True, correct_ccd_defects=False, correct_high_cosmics=False, clip_high=100, step_ccd=50, remove_5578=False, plot_suspicious_fibres=False, fix_wavelengths=False, sol=[0, 0, 0], sky_method='self', n_sky=50, sky_fibres=[1000], sky_spectrum=[0], sky_rss=[0], scale_sky_rss=0, scale_sky_1D=1.0, is_sky=False, win_sky=151, auto_scale_sky=False, correct_negative_sky=False, sky_wave_min=0, sky_wave_max=0, cut_sky=5.0, fmin=1, fmax=10, individual_sky_substraction=False, fibre_list=[100, 200, 300, 400, 500, 600, 700, 800, 900], do_extinction=True, telluric_correction=[0], id_el=False, high_fibres=10, brightest_line='Ha', cut=1.5, broad=1.0, plot_id_el=False, id_list=[0], brightest_line_wavelength=0, clean_sky_residuals=False, dclip=3.0, extra_w=1.3, step_csr=25, fibre=0, valid_wave_min=0, valid_wave_max=0, verbose=False, plot=True, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, fig_size=12)[source]

This class reads the FITS files returned by 2dfdr and performs basic analysis tasks (see description under each method).

Parameters

filename (string) – FITS file returned by 2dfdr, containing the Raw Stacked Spectra. The code makes sure that it contains 1000 spectra with 2048 wavelengths each.

Example

>>> pointing1 = KOALA_RSS('data/16jan20058red.fits')
> Reading file "data/16jan20058red.fits" ...
  2048 wavelength points between 6271.33984375 and 7435.43408203
  1000 spaxels
  These numbers are the right ones for KOALA!
  DONE!
RSS_image(image=[0], norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='seismic_r', clow=0, chigh=0, labelpad=10, title=' - RSS image', color_bar_text='Integrated Flux [Arbitrary units]', fig_size=13.5)

Plot RSS image coloured by variable. cmap = “binary_r” nice greyscale

Parameters
  • image

  • norm

  • cmap

  • clow

  • chigh

  • labelpad

  • title

  • color_bar_text

  • fig_size

RSS_map(variable, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, list_spectra=[], title=' - RSS map', color_bar_text='Integrated Flux [Arbitrary units]')

Plot map showing the offsets, coloured by variable.

Parameters
  • variable

  • norm

  • list_spectra

  • title

  • color_bar_text

clean_sky_residuals(extra_w=1.3, step=25, dclip=3.0, wave_min=0, wave_max=0, verbose=False, plot=False, fig_size=12, fibre=0)

This task HAVE TO BE USED WITH EXTREME CARE as it has not been properly tested!!! It CAN DELETE REAL (faint) ABSORPTION/EMISSION features in spectra!!! Use the “1dfit” option for getting a better sky substraction ANGEL is keeping this here just in case it is eventually useful…

Parameters
  • extra_w

  • step

  • dclip

  • wave_min

  • wave_max

  • verbose

  • plot

  • fig_size

  • fibre

compute_integrated_fibre(list_spectra='all', valid_wave_min=0, valid_wave_max=0, min_value=0.1, plot=False, title=' - Integrated values', text='...', correct_negative_sky=False)

Compute the integrated flux of a fibre in a particular range, valid_wave_min to valid_wave_max.

Parameters
  • list_spectra (float (default "all")) – list with the number of fibres for computing integrated value if using “all” it does all fibres

  • valid_wave_min (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • valid_wave_max (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • min_value (float (default 0)) – For values lower than min_value, we set them as min_value

  • plot (Boolean (default = False)) – Plot

  • title (string) – Title for the plot

  • text (string) – A bit of extra text

  • correct_negative_sky (Boolean (default = False)) – Corrects negative values making 0 the integrated flux of the lowest fibre

Example

integrated_fibre_6500_6600 = star1r.compute_integrated_fibre(valid_wave_min=6500, valid_wave_max=6600, title = ” - [6500,6600]”, plot = True)

correct_high_cosmics_and_defects(step=50, correct_high_cosmics=False, fibre_p=0, remove_5578=False, clip_high=100, plot=True, plot_suspicious_fibres=True, verbose=False, fig_size=12)

Task for correcting high cosmics and CCD defects using median values of nearby pixels. 2dFdr corrects for (the majority) of the cosmic rays, usually correct_high_cosmics = False. ANGEL COMMENT: Check, probably can be improved using MATT median running + plotting outside

Parameters
  • rect_high_cosmics (boolean (default = False)) – Correct ONLY CCD defects

  • re_p (integer (default = 0)) – Plots the corrections in fibre fibre_p

  • ove_5578 (boolean (default = False)) – Removes skyline 5578 (blue spectrum) using Gaussian fit ND CHECK: This also MODIFIES the throughput correction correcting for flux_5578_medfilt /median_flux_5578_medfilt

  • step (integer (default = 50)) – Number of points for calculating median value

  • clip_high (float (default = 100)) –

    Minimum value of flux/median in a pixel to be consider as a cosmic

    if s[wave] > clip_high*fit_median[wave] -> IT IS A COSMIC

  • verbose (boolean (default = False)) – Write results

  • plot (boolean (default = False)) – Plot results

  • plot_suspicious_fibres (boolean (default = False)) – Plots fibre(s) that could have a cosmic left (but it could be OK) IF self.integrated_fibre[fibre]/median_running[fibre] > max_value -> SUSPICIOUS FIBRE

Example

>>> self.correct_high_cosmics_and_defects(
...    correct_high_cosmics=False, step=40, remove_5578=True,
...    clip_high=120, plot_suspicious_fibres=True, verbose=False,
...    plot=True
... )
do_extinction_curve(observatory_file='/home/docs/checkouts/readthedocs.org/user_builds/pykoala/checkouts/master/src/koala/data/ssoextinct.dat', plot=True)
Parameters
  • observatory_file

  • plot

find_relative_throughput(ymin=10000, ymax=200000, kernel_sky_spectrum=5, wave_min_scale=0, wave_max_scale=0, plot=True)

Determine the relative transmission of each spectrum using a skyflat.

Parameters
  • ymin

  • ymax

  • kernel_sky_spectrum

  • wave_min_scale

  • wave_max_scale

  • plot

find_sky_emission(intensidad=[0, 0], plot=True, n_sky=200, sky_fibres=[1000], sky_wave_min=0, sky_wave_max=0, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>)
Parameters
  • intensidad

  • plot

  • n_sky

  • sky_fibres

  • sky_wave_min

  • sky_wave_max

  • norm

fit_and_substract_sky_spectrum(sky, w=1000, spectra=1000, rebin=False, brightest_line='Ha', brightest_line_wavelength=6563.0, maxima_sigma=3.0, ymin=- 50, ymax=1000, wmin=0, wmax=0, auto_scale_sky=False, verbose=False, plot=False, fig_size=12, fibre=0)

Given a 1D sky spectrum, this task fits sky lines of each spectrum individually and substracts sky Needs the observed wavelength (brightest_line_wavelength) of the brightest emission line (brightest_line) . w is the wavelength spec the 2D spectra

Parameters
  • sky

  • w

  • spectra

  • rebin

  • brightest_line

  • brightest_line_wavelength

  • maxima_sigma

  • ymin

  • ymax

  • wmin

  • wmax

  • auto_scale_sky

  • verbose

  • plot

  • fig_size

  • fibre

fix_2dfdr_wavelengths(sol=[0, 0, 0], fibre=0, maxima_sigma=2.5, maxima_offset=1.5, xmin=7740, xmax=7770, ymin=0, ymax=1000, plot=True, verbose=True)
Parameters
  • sol

  • fibre

  • maxima_sigma

  • maxima_offset

  • xmin

  • xmax

  • ymin

  • ymax

  • plot

  • verbose

flux_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

get_telluric_correction(n_fibres=10, correct_from=6850.0, correct_to=10000.0, apply_tc=False, step=10, combined_cube=False, weight_fit_median=0.5, exclude_wlm=[[6450, 6700], [6850, 7050], [7130, 7380]], wave_min=0, wave_max=0, plot=True, fig_size=12, verbose=False)

# TODO BLAKE: always use false, use plots to make sure it’s good. prob just save as a different file. Get telluric correction using a spectrophotometric star

Parameters
  • n_fibres (integer) – number of fibers to add for obtaining spectrum

  • correct_from (float) – wavelength from which telluric correction is applied (default = 6850)

  • apply_tc (boolean (default = False)) – apply telluric correction to data

  • exclude_wlm=[[6450 – Wavelength ranges not considering for normalising stellar continuum

  • 6700] – Wavelength ranges not considering for normalising stellar continuum

  • [6850 – Wavelength ranges not considering for normalising stellar continuum

  • 7050] – Wavelength ranges not considering for normalising stellar continuum

  • [7130 – Wavelength ranges not considering for normalising stellar continuum

  • 7380]] – Wavelength ranges not considering for normalising stellar continuum

Example

telluric_correction_star1 = star1r.get_telluric_correction(n_fibres=15)

identify_el(high_fibres=10, brightest_line='Ha', cut=1.5, fibre=0, broad=1.0, verbose=True, plot=True)

Identify fibres with highest intensity (high_fibres=10). Add all in a single spectrum. Identify emission features. These emission features should be those expected in all the cube! Also, choosing fibre=number, it identifies el in a particular fibre.

Parameters
  • high_fibres (float (default 10)) – use the high_fibres highest intensity fibres for identifying

  • brightest_line (string (default "Ha")) – string name with the emission line that is expected to be the brightest in integrated spectrum

  • cut (float (default 1.5)) – The peak has to have a cut higher than cut to be considered as emission line

  • fibre (integer (default 0)) – If fibre is given, it identifies emission lines in the given fibre

  • broad (float (default 1.0)) – Broad (FWHM) of the expected emission lines

  • verbose (boolean (default = True)) – Write results

  • plot (boolean (default = False)) – Plot results

Example

self.el=self.identify_el(high_fibres=10, brightest_line = “Ha”,

cut=2., verbose=True, plot=True, fibre=0, broad=1.5)

line_flux(left_min, left_max, line_min, line_max, right_min, right_max, list_spectra=[])
Parameters
  • left_min

  • left_max

  • line_min

  • line_max

  • right_min

  • right_max

  • list_spectra

median_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

plot_combined_spectrum(list_spectra='all', sky=True, median=False, xmin='', xmax='', ymax='', ymin='', fig_size=10, save_file='', plot=True)

Plot combined spectrum of a list and return the combined spectrum.

Parameters
  • list_spectra – spaxels to show combined spectrum. Default is all.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_corrected_vs_uncorrected_spectrum(high_fibres=10, fig_size=12)
Parameters
  • high_fibres

  • fig_size

plot_spectra(list_spectra='all', wavelength_range=[0], xmin='', xmax='', ymax=1000, ymin=- 100, fig_size=10, save_file='', sky=True)

Plot spectrum of a list pf spaxels.

Parameters
  • list_spectra – spaxels to show spectrum. Default is all.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> rss1.plot_spectra([1200,1300])
plot_spectrum(spectrum_number, sky=True, xmin=0, xmax=0, ymax=0, ymin=0)

Plot spectrum of a particular spaxel.

Parameters
  • spectrum_number – spaxel to show spectrum.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
class koala.KOALA_reduce(rss_list, fits_file='', obj_name='', description='', do_rss=True, do_cubing=True, do_alignment=True, make_combined_cube=True, rss_clean=False, save_rss_to_fits_file_list=['', '', '', '', '', '', '', '', '', ''], save_aligned_cubes=False, apply_throughput=True, skyflat='', skyflat_file='', flat='', skyflat_list=['', '', '', '', '', '', '', '', '', ''], plot_skyflat=False, wave_min_scale=0, wave_max_scale=0, ymin=0, ymax=0, correct_ccd_defects=False, correct_high_cosmics=False, clip_high=100, step_ccd=50, remove_5578=False, plot_suspicious_fibres=False, fix_wavelengths=False, sol=[0, 0, 0], do_extinction=True, sky_method='self', n_sky=50, sky_fibres=[1000], sky_spectrum=[0], sky_rss=[0], scale_sky_rss=0, scale_sky_1D=0, correct_negative_sky=False, auto_scale_sky=False, sky_wave_min=0, sky_wave_max=0, cut_sky=5.0, fmin=1, fmax=10, individual_sky_substraction=False, fibre_list=[100, 200, 300, 400, 500, 600, 700, 800, 900], sky_list=[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], telluric_correction=[0], telluric_correction_list=[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], id_el=False, high_fibres=10, brightest_line='Ha', cut=1.5, plot_id_el=True, broad=2.0, id_list=[0], brightest_line_wavelength=0, clean_sky_residuals=False, dclip=3.0, extra_w=1.3, step_csr=25, pixel_size_arcsec=0.4, kernel_size_arcsec=1.2, offsets=[1000], ADR=False, flux_calibration=[0], flux_calibration_list=[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], valid_wave_min=0, valid_wave_max=0, plot=True, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, fig_size=12, verbose=False)[source]
ADR_correction(plot=True, force_ADR=False)

Correct for Atmospheric Diferential Refraction (ADR)

Parameters
  • plot

  • force_ADR

RSS_image(image=[0], norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='seismic_r', clow=0, chigh=0, labelpad=10, title=' - RSS image', color_bar_text='Integrated Flux [Arbitrary units]', fig_size=13.5)

Plot RSS image coloured by variable. cmap = “binary_r” nice greyscale

Parameters
  • image

  • norm

  • cmap

  • clow

  • chigh

  • labelpad

  • title

  • color_bar_text

  • fig_size

RSS_map(variable, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, list_spectra=[], title=' - RSS map', color_bar_text='Integrated Flux [Arbitrary units]')

Plot map showing the offsets, coloured by variable.

Parameters
  • variable

  • norm

  • list_spectra

  • title

  • color_bar_text

add_spectrum(intensity, offset_rows, offset_cols)

Add one single spectrum to the datacube

Parameters
  • intensity (np.array(float)) – Spectrum.

  • offset_rows (float) – Offset with respect to the image centre, in pixels.

  • offset_cols (float) – Offset with respect to the image centre, in pixels.

  • kernel_FWHM_pixels (float) – FWHM of the interpolating kernel, in pixels

clean_sky_residuals(extra_w=1.3, step=25, dclip=3.0, wave_min=0, wave_max=0, verbose=False, plot=False, fig_size=12, fibre=0)

This task HAVE TO BE USED WITH EXTREME CARE as it has not been properly tested!!! It CAN DELETE REAL (faint) ABSORPTION/EMISSION features in spectra!!! Use the “1dfit” option for getting a better sky substraction ANGEL is keeping this here just in case it is eventually useful…

Parameters
  • extra_w

  • step

  • dclip

  • wave_min

  • wave_max

  • verbose

  • plot

  • fig_size

  • fibre

compute_integrated_fibre(list_spectra='all', valid_wave_min=0, valid_wave_max=0, min_value=0.1, plot=False, title=' - Integrated values', text='...', correct_negative_sky=False)

Compute the integrated flux of a fibre in a particular range, valid_wave_min to valid_wave_max.

Parameters
  • list_spectra (float (default "all")) – list with the number of fibres for computing integrated value if using “all” it does all fibres

  • valid_wave_min (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • valid_wave_max (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • min_value (float (default 0)) – For values lower than min_value, we set them as min_value

  • plot (Boolean (default = False)) – Plot

  • title (string) – Title for the plot

  • text (string) – A bit of extra text

  • correct_negative_sky (Boolean (default = False)) – Corrects negative values making 0 the integrated flux of the lowest fibre

Example

integrated_fibre_6500_6600 = star1r.compute_integrated_fibre(valid_wave_min=6500, valid_wave_max=6600, title = ” - [6500,6600]”, plot = True)

correct_high_cosmics_and_defects(step=50, correct_high_cosmics=False, fibre_p=0, remove_5578=False, clip_high=100, plot=True, plot_suspicious_fibres=True, verbose=False, fig_size=12)

Task for correcting high cosmics and CCD defects using median values of nearby pixels. 2dFdr corrects for (the majority) of the cosmic rays, usually correct_high_cosmics = False. ANGEL COMMENT: Check, probably can be improved using MATT median running + plotting outside

Parameters
  • rect_high_cosmics (boolean (default = False)) – Correct ONLY CCD defects

  • re_p (integer (default = 0)) – Plots the corrections in fibre fibre_p

  • ove_5578 (boolean (default = False)) – Removes skyline 5578 (blue spectrum) using Gaussian fit ND CHECK: This also MODIFIES the throughput correction correcting for flux_5578_medfilt /median_flux_5578_medfilt

  • step (integer (default = 50)) – Number of points for calculating median value

  • clip_high (float (default = 100)) –

    Minimum value of flux/median in a pixel to be consider as a cosmic

    if s[wave] > clip_high*fit_median[wave] -> IT IS A COSMIC

  • verbose (boolean (default = False)) – Write results

  • plot (boolean (default = False)) – Plot results

  • plot_suspicious_fibres (boolean (default = False)) – Plots fibre(s) that could have a cosmic left (but it could be OK) IF self.integrated_fibre[fibre]/median_running[fibre] > max_value -> SUSPICIOUS FIBRE

Example

>>> self.correct_high_cosmics_and_defects(
...    correct_high_cosmics=False, step=40, remove_5578=True,
...    clip_high=120, plot_suspicious_fibres=True, verbose=False,
...    plot=True
... )
create_map(wavelength1, wavelength2, name='NEW_MAP')

Create map adding maps in a wavelength range.”

Parameters
  • wavelength1 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • wavelength2 (floats) – The map will integrate all flux in the range [wavelength1, wavelength2].

  • map_name (string) – String with the name of the map, must be the same than file created here.

Example

>>> a = cube.create_map(6810,6830, "a")
> Created map with name  a  integrating range [ 6810 , 6830 ]
do_extinction_curve(observatory_file='/home/docs/checkouts/readthedocs.org/user_builds/pykoala/checkouts/master/src/koala/data/ssoextinct.dat', plot=True)
Parameters
  • observatory_file

  • plot

do_response_curve(filename, min_wave=0, max_wave=0, step=25.0, fit_degree=3, exp_time=60, smooth=0.03, ha_width=0, plot=True, verbose=False)

Compute the response curve of a spectrophotometric star.

Parameters
  • filename (string) – filename where the spectrophotometric data are included (e.g. ffeige56.dat)

  • min_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • max_wave (floats) – wavelength range = [min_wave, max_wave] where the fit is performed

  • 25 (step =) – Step (in A) for smoothing the data

  • 3 (fit_degree =) – degree of the polynomium used for the fit (3, 5, or 7). If fit_degree = 0 it interpolates the data

  • 60 (exp_time =) – Exposition time of the calibration star

  • 0.03 (smooth =) – Smooth value for interpolating the data for fit_degree = 0.

  • plot (boolean) – Plot yes/no

Example

>>> babbsdsad
find_relative_throughput(ymin=10000, ymax=200000, kernel_sky_spectrum=5, wave_min_scale=0, wave_max_scale=0, plot=True)

Determine the relative transmission of each spectrum using a skyflat.

Parameters
  • ymin

  • ymax

  • kernel_sky_spectrum

  • wave_min_scale

  • wave_max_scale

  • plot

find_sky_emission(intensidad=[0, 0], plot=True, n_sky=200, sky_fibres=[1000], sky_wave_min=0, sky_wave_max=0, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>)
Parameters
  • intensidad

  • plot

  • n_sky

  • sky_fibres

  • sky_wave_min

  • sky_wave_max

  • norm

fit_Moffat_between(min_wave=0, max_wave=0, r_max=5, plot=False)
Parameters
  • min_wave

  • max_wave

  • r_max

  • plot

fit_and_substract_sky_spectrum(sky, w=1000, spectra=1000, rebin=False, brightest_line='Ha', brightest_line_wavelength=6563.0, maxima_sigma=3.0, ymin=- 50, ymax=1000, wmin=0, wmax=0, auto_scale_sky=False, verbose=False, plot=False, fig_size=12, fibre=0)

Given a 1D sky spectrum, this task fits sky lines of each spectrum individually and substracts sky Needs the observed wavelength (brightest_line_wavelength) of the brightest emission line (brightest_line) . w is the wavelength spec the 2D spectra

Parameters
  • sky

  • w

  • spectra

  • rebin

  • brightest_line

  • brightest_line_wavelength

  • maxima_sigma

  • ymin

  • ymax

  • wmin

  • wmax

  • auto_scale_sky

  • verbose

  • plot

  • fig_size

  • fibre

fix_2dfdr_wavelengths(sol=[0, 0, 0], fibre=0, maxima_sigma=2.5, maxima_offset=1.5, xmin=7740, xmax=7770, ymin=0, ymax=1000, plot=True, verbose=True)
Parameters
  • sol

  • fibre

  • maxima_sigma

  • maxima_offset

  • xmin

  • xmax

  • ymin

  • ymax

  • plot

  • verbose

flux_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

get_integrated_map_and_plot(min_wave=[0], max_wave=[0], plot=True, fcal=False)

Integrated map and plot

Parameters
  • min_wave

  • max_wave

  • plot

  • fcal

get_telluric_correction(n_fibres=10, correct_from=6850.0, correct_to=10000.0, apply_tc=False, step=10, combined_cube=False, weight_fit_median=0.5, exclude_wlm=[[6450, 6700], [6850, 7050], [7130, 7380]], wave_min=0, wave_max=0, plot=True, fig_size=12, verbose=False)

# TODO BLAKE: always use false, use plots to make sure it’s good. prob just save as a different file. Get telluric correction using a spectrophotometric star

Parameters
  • n_fibres (integer) – number of fibers to add for obtaining spectrum

  • correct_from (float) – wavelength from which telluric correction is applied (default = 6850)

  • apply_tc (boolean (default = False)) – apply telluric correction to data

  • exclude_wlm=[[6450 – Wavelength ranges not considering for normalising stellar continuum

  • 6700] – Wavelength ranges not considering for normalising stellar continuum

  • [6850 – Wavelength ranges not considering for normalising stellar continuum

  • 7050] – Wavelength ranges not considering for normalising stellar continuum

  • [7130 – Wavelength ranges not considering for normalising stellar continuum

  • 7380]] – Wavelength ranges not considering for normalising stellar continuum

Example

telluric_correction_star1 = star1r.get_telluric_correction(n_fibres=15)

growth_curve_between(min_wave=0, max_wave=0, plot=False, verbose=False)

Compute growth curve in a wavelength range. Returns r2_growth_curve, F_growth_curve, flux, r2_half_light

Parameters
  • min_wave (floats) – wavelength range = [min_wave, max_wave].

  • max_wave (floats) – wavelength range = [min_wave, max_wave].

  • plot (boolean) – Plot yes/no

Example

>>>r2_growth_curve, F_growth_curve, flux, r2_half_light = self.growth_curve_between(min_wave, max_wave, plot=True) # 0,1E30 ??

half_light_spectrum(r_max=1, plot=False, smooth=21, min_wave=0, max_wave=0)

Compute half light spectrum (for r_max=1) or integrated star spectrum (for r_max=5) in a wavelength range.

Parameters
  • 1 (r_max =) – r_max to integrate, in units of r2_half_light (= seeing if object is a star, for flux calibration make r_max=5)

  • min_wave (floats) – wavelength range = [min_wave, max_wave]

  • max_wave (floats) – wavelength range = [min_wave, max_wave]

  • 21 (smooth =) – smooth the data

  • plot (boolean) – Plot yes/no

Example

>>> self.half_light_spectrum(5, plot=plot, min_wave=min_wave, max_wave=max_wave)
identify_el(high_fibres=10, brightest_line='Ha', cut=1.5, fibre=0, broad=1.0, verbose=True, plot=True)

Identify fibres with highest intensity (high_fibres=10). Add all in a single spectrum. Identify emission features. These emission features should be those expected in all the cube! Also, choosing fibre=number, it identifies el in a particular fibre.

Parameters
  • high_fibres (float (default 10)) – use the high_fibres highest intensity fibres for identifying

  • brightest_line (string (default "Ha")) – string name with the emission line that is expected to be the brightest in integrated spectrum

  • cut (float (default 1.5)) – The peak has to have a cut higher than cut to be considered as emission line

  • fibre (integer (default 0)) – If fibre is given, it identifies emission lines in the given fibre

  • broad (float (default 1.0)) – Broad (FWHM) of the expected emission lines

  • verbose (boolean (default = True)) – Write results

  • plot (boolean (default = False)) – Plot results

Example

self.el=self.identify_el(high_fibres=10, brightest_line = “Ha”,

cut=2., verbose=True, plot=True, fibre=0, broad=1.5)

line_flux(left_min, left_max, line_min, line_max, right_min, right_max, list_spectra=[])
Parameters
  • left_min

  • left_max

  • line_min

  • line_max

  • right_min

  • right_max

  • list_spectra

median_between(lambda_min, lambda_max, list_spectra=[])
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

plot_combined_spectrum(list_spectra='all', sky=True, median=False, xmin='', xmax='', ymax='', ymin='', fig_size=10, save_file='', plot=True)

Plot combined spectrum of a list and return the combined spectrum.

Parameters
  • list_spectra – spaxels to show combined spectrum. Default is all.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_corrected_vs_uncorrected_spectrum(high_fibres=10, fig_size=12)
Parameters
  • high_fibres

  • fig_size

plot_map(mapa='', norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='fuego', fig_size=10, fcal=False, save_file='', description='', contours=True, clabel=False, spaxel=0, spaxel2=0, spaxel3=0)

Show a given map.

Parameters
  • map (np.array(float)) – Map to be plotted. If not given, it plots the integrated map.

  • norm – Normalization scale, default is lineal scale. Lineal scale: norm=colors.Normalize(). Log scale: norm=colors.LogNorm() Power law: norm=colors.PowerNorm(gamma=1./4.)

  • cmap ((default cmap="fuego")) – Color map used. Weight: cmap = “gist_gray” Velocities: cmap=”seismic”. Try also “inferno”,

  • spaxel – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

  • spaxel2 – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

  • spaxel3 – [x,y] positions of spaxels to show with a green circle, blue square and red triangle

plot_spectra(list_spectra='all', wavelength_range=[0], xmin='', xmax='', ymax=1000, ymin=- 100, fig_size=10, save_file='', sky=True)

Plot spectrum of a list pf spaxels.

Parameters
  • list_spectra – spaxels to show spectrum. Default is all.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> rss1.plot_spectra([1200,1300])
plot_spectrum(spectrum_number, sky=True, xmin=0, xmax=0, ymax=0, ymin=0)

Plot spectrum of a particular spaxel.

Parameters
  • spectrum_number – spaxel to show spectrum.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_spectrum_cube(x, y, lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10.0, fig_size_y=0.0, save_file='', title='', z=0.0)

Plot spectrum of a particular spaxel.

Parameters
  • x – coordenates of spaxel to show spectrum.

  • y – coordenates of spaxel to show spectrum.

  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_spectrum_integrated_cube(lmin=0, lmax=0, fmin=1e-30, fmax=1e+30, fcal=False, fig_size=10, save_file='')

Plot integrated spectrum

Parameters
  • fcal

    Use flux calibration, default fcal=False.

    If fcal=True, cube.flux_calibration is used.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> cube.plot_spectrum_cube(20, 20, fcal=True)
plot_wavelength(wavelength, w2=0.0, cmap=<MagicMock name='mock.colors.LinearSegmentedColormap.from_list()' id='140524763892048'>, fig_size=10, norm=<MagicMock name='mock.colors.PowerNorm()' id='140524774247760'>, save_file='', fcal=False)

Plot map at a particular wavelength or in a wavelength range

Parameters
  • wavelength (float) – wavelength to be mapped.

  • norm

    Colour scale, default = colors.PowerNorm(gamma=1./4.)

    Normalization scale Lineal scale: norm=colors.Normalize(). Log scale:norm=colors.LogNorm()

  • cmap – Color map used, default cmap=fuego_color_map Velocities: cmap=”seismic”

  • save_file – (Optional) Save plot in file “file.extension”

plot_weight(norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='gist_gray', fig_size=10, save_file='')

Plot weitgh map.”

Example

>>> cube1s.plot_weight()
trace_peak(edgelow=10, edgehigh=10, plot=False, ADR=False, smoothfactor=2)
Parameters
  • edgelow

  • edgehigh

  • plot

  • ADR

  • smoothfactor

class koala.RSS[source]

Collection of row-stacked spectra (RSS).

wavelength

Wavelength, in Angstroms.

Type

np.array(float)

intensity

Intensity \(I_\lambda\) per unit wavelength.

Type

np.array(float)

variance

Variance \(\sigma^2_\lambda\) per unit wavelength (note the square in the definition of the variance).

Type

np.array(float)

RSS_image(image=[0], norm=<MagicMock name='mock.colors.Normalize()' id='140524774257680'>, cmap='seismic_r', clow=0, chigh=0, labelpad=10, title=' - RSS image', color_bar_text='Integrated Flux [Arbitrary units]', fig_size=13.5)[source]

Plot RSS image coloured by variable. cmap = “binary_r” nice greyscale

Parameters
  • image

  • norm

  • cmap

  • clow

  • chigh

  • labelpad

  • title

  • color_bar_text

  • fig_size

RSS_map(variable, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>, list_spectra=[], title=' - RSS map', color_bar_text='Integrated Flux [Arbitrary units]')[source]

Plot map showing the offsets, coloured by variable.

Parameters
  • variable

  • norm

  • list_spectra

  • title

  • color_bar_text

clean_sky_residuals(extra_w=1.3, step=25, dclip=3.0, wave_min=0, wave_max=0, verbose=False, plot=False, fig_size=12, fibre=0)[source]

This task HAVE TO BE USED WITH EXTREME CARE as it has not been properly tested!!! It CAN DELETE REAL (faint) ABSORPTION/EMISSION features in spectra!!! Use the “1dfit” option for getting a better sky substraction ANGEL is keeping this here just in case it is eventually useful…

Parameters
  • extra_w

  • step

  • dclip

  • wave_min

  • wave_max

  • verbose

  • plot

  • fig_size

  • fibre

compute_integrated_fibre(list_spectra='all', valid_wave_min=0, valid_wave_max=0, min_value=0.1, plot=False, title=' - Integrated values', text='...', correct_negative_sky=False)[source]

Compute the integrated flux of a fibre in a particular range, valid_wave_min to valid_wave_max.

Parameters
  • list_spectra (float (default "all")) – list with the number of fibres for computing integrated value if using “all” it does all fibres

  • valid_wave_min (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • valid_wave_max (float) – the integrated flux value will be computed in the range [valid_wave_min, valid_wave_max] (default = , if they all 0 we use [self.valid_wave_min, self.valid_wave_max]

  • min_value (float (default 0)) – For values lower than min_value, we set them as min_value

  • plot (Boolean (default = False)) – Plot

  • title (string) – Title for the plot

  • text (string) – A bit of extra text

  • correct_negative_sky (Boolean (default = False)) – Corrects negative values making 0 the integrated flux of the lowest fibre

Example

integrated_fibre_6500_6600 = star1r.compute_integrated_fibre(valid_wave_min=6500, valid_wave_max=6600, title = ” - [6500,6600]”, plot = True)

correct_high_cosmics_and_defects(step=50, correct_high_cosmics=False, fibre_p=0, remove_5578=False, clip_high=100, plot=True, plot_suspicious_fibres=True, verbose=False, fig_size=12)[source]

Task for correcting high cosmics and CCD defects using median values of nearby pixels. 2dFdr corrects for (the majority) of the cosmic rays, usually correct_high_cosmics = False. ANGEL COMMENT: Check, probably can be improved using MATT median running + plotting outside

Parameters
  • rect_high_cosmics (boolean (default = False)) – Correct ONLY CCD defects

  • re_p (integer (default = 0)) – Plots the corrections in fibre fibre_p

  • ove_5578 (boolean (default = False)) – Removes skyline 5578 (blue spectrum) using Gaussian fit ND CHECK: This also MODIFIES the throughput correction correcting for flux_5578_medfilt /median_flux_5578_medfilt

  • step (integer (default = 50)) – Number of points for calculating median value

  • clip_high (float (default = 100)) –

    Minimum value of flux/median in a pixel to be consider as a cosmic

    if s[wave] > clip_high*fit_median[wave] -> IT IS A COSMIC

  • verbose (boolean (default = False)) – Write results

  • plot (boolean (default = False)) – Plot results

  • plot_suspicious_fibres (boolean (default = False)) – Plots fibre(s) that could have a cosmic left (but it could be OK) IF self.integrated_fibre[fibre]/median_running[fibre] > max_value -> SUSPICIOUS FIBRE

Example

>>> self.correct_high_cosmics_and_defects(
...    correct_high_cosmics=False, step=40, remove_5578=True,
...    clip_high=120, plot_suspicious_fibres=True, verbose=False,
...    plot=True
... )
do_extinction_curve(observatory_file='/home/docs/checkouts/readthedocs.org/user_builds/pykoala/checkouts/master/src/koala/data/ssoextinct.dat', plot=True)[source]
Parameters
  • observatory_file

  • plot

find_relative_throughput(ymin=10000, ymax=200000, kernel_sky_spectrum=5, wave_min_scale=0, wave_max_scale=0, plot=True)[source]

Determine the relative transmission of each spectrum using a skyflat.

Parameters
  • ymin

  • ymax

  • kernel_sky_spectrum

  • wave_min_scale

  • wave_max_scale

  • plot

find_sky_emission(intensidad=[0, 0], plot=True, n_sky=200, sky_fibres=[1000], sky_wave_min=0, sky_wave_max=0, norm=<MagicMock name='mock.colors.LogNorm()' id='140524774230160'>)[source]
Parameters
  • intensidad

  • plot

  • n_sky

  • sky_fibres

  • sky_wave_min

  • sky_wave_max

  • norm

fit_and_substract_sky_spectrum(sky, w=1000, spectra=1000, rebin=False, brightest_line='Ha', brightest_line_wavelength=6563.0, maxima_sigma=3.0, ymin=- 50, ymax=1000, wmin=0, wmax=0, auto_scale_sky=False, verbose=False, plot=False, fig_size=12, fibre=0)[source]

Given a 1D sky spectrum, this task fits sky lines of each spectrum individually and substracts sky Needs the observed wavelength (brightest_line_wavelength) of the brightest emission line (brightest_line) . w is the wavelength spec the 2D spectra

Parameters
  • sky

  • w

  • spectra

  • rebin

  • brightest_line

  • brightest_line_wavelength

  • maxima_sigma

  • ymin

  • ymax

  • wmin

  • wmax

  • auto_scale_sky

  • verbose

  • plot

  • fig_size

  • fibre

fix_2dfdr_wavelengths(sol=[0, 0, 0], fibre=0, maxima_sigma=2.5, maxima_offset=1.5, xmin=7740, xmax=7770, ymin=0, ymax=1000, plot=True, verbose=True)[source]
Parameters
  • sol

  • fibre

  • maxima_sigma

  • maxima_offset

  • xmin

  • xmax

  • ymin

  • ymax

  • plot

  • verbose

flux_between(lambda_min, lambda_max, list_spectra=[])[source]
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

get_telluric_correction(n_fibres=10, correct_from=6850.0, correct_to=10000.0, apply_tc=False, step=10, combined_cube=False, weight_fit_median=0.5, exclude_wlm=[[6450, 6700], [6850, 7050], [7130, 7380]], wave_min=0, wave_max=0, plot=True, fig_size=12, verbose=False)[source]

# TODO BLAKE: always use false, use plots to make sure it’s good. prob just save as a different file. Get telluric correction using a spectrophotometric star

Parameters
  • n_fibres (integer) – number of fibers to add for obtaining spectrum

  • correct_from (float) – wavelength from which telluric correction is applied (default = 6850)

  • apply_tc (boolean (default = False)) – apply telluric correction to data

  • exclude_wlm=[[6450 – Wavelength ranges not considering for normalising stellar continuum

  • 6700] – Wavelength ranges not considering for normalising stellar continuum

  • [6850 – Wavelength ranges not considering for normalising stellar continuum

  • 7050] – Wavelength ranges not considering for normalising stellar continuum

  • [7130 – Wavelength ranges not considering for normalising stellar continuum

  • 7380]] – Wavelength ranges not considering for normalising stellar continuum

Example

telluric_correction_star1 = star1r.get_telluric_correction(n_fibres=15)

identify_el(high_fibres=10, brightest_line='Ha', cut=1.5, fibre=0, broad=1.0, verbose=True, plot=True)[source]

Identify fibres with highest intensity (high_fibres=10). Add all in a single spectrum. Identify emission features. These emission features should be those expected in all the cube! Also, choosing fibre=number, it identifies el in a particular fibre.

Parameters
  • high_fibres (float (default 10)) – use the high_fibres highest intensity fibres for identifying

  • brightest_line (string (default "Ha")) – string name with the emission line that is expected to be the brightest in integrated spectrum

  • cut (float (default 1.5)) – The peak has to have a cut higher than cut to be considered as emission line

  • fibre (integer (default 0)) – If fibre is given, it identifies emission lines in the given fibre

  • broad (float (default 1.0)) – Broad (FWHM) of the expected emission lines

  • verbose (boolean (default = True)) – Write results

  • plot (boolean (default = False)) – Plot results

Example

self.el=self.identify_el(high_fibres=10, brightest_line = “Ha”,

cut=2., verbose=True, plot=True, fibre=0, broad=1.5)

line_flux(left_min, left_max, line_min, line_max, right_min, right_max, list_spectra=[])[source]
Parameters
  • left_min

  • left_max

  • line_min

  • line_max

  • right_min

  • right_max

  • list_spectra

median_between(lambda_min, lambda_max, list_spectra=[])[source]
Parameters
  • lambda_min

  • lambda_max

  • list_spectra

plot_combined_spectrum(list_spectra='all', sky=True, median=False, xmin='', xmax='', ymax='', ymin='', fig_size=10, save_file='', plot=True)[source]

Plot combined spectrum of a list and return the combined spectrum.

Parameters
  • list_spectra – spaxels to show combined spectrum. Default is all.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)
plot_corrected_vs_uncorrected_spectrum(high_fibres=10, fig_size=12)[source]
Parameters
  • high_fibres

  • fig_size

plot_spectra(list_spectra='all', wavelength_range=[0], xmin='', xmax='', ymax=1000, ymin=- 100, fig_size=10, save_file='', sky=True)[source]

Plot spectrum of a list pf spaxels.

Parameters
  • list_spectra – spaxels to show spectrum. Default is all.

  • save_file – (Optional) Save plot in file “file.extension”

  • fig_size – Size of the figure (in x-axis), default: fig_size=10

Example

>>> rss1.plot_spectra([1200,1300])
plot_spectrum(spectrum_number, sky=True, xmin=0, xmax=0, ymax=0, ymin=0)[source]

Plot spectrum of a particular spaxel.

Parameters
  • spectrum_number – spaxel to show spectrum.

  • sky – if True substracts the sky

Example

>>> rss1.plot_spectrum(550, sky=True)