Exemplo n.º 1
0
def plotEmLines(EADir, galaxy, plotType, emLineInd, emLineFancy, nFP, dataInd):

    units = '$' + galaxy.myHDU[dataInd].header['BUNIT'] + '$'
    # galaxy.printInfo()
    hex_at_Cen, gal_at_Cen = fE.getCenters(galaxy.myHDU, galaxy.PLATEIFU,
                                           dataInd)

    print("plotEmLines(" + galaxy.PLATEIFU + ")")

    # cycle through 11 chosen wavelengths
    for j in emLineInd.keys():
        # print(plotType + ": " + j)

        slice = EmissionLineSlice.EmissionLineSlice(galaxy, emLineInd[j], j,
                                                    emLineFancy[j], units)

        ############ data Correction #############

        # dC.printDataInfo(dataMat)

        ############ action #############

        # average = get_average(galaxy, slice)
        # print(galaxy.PLATEIFU, slice.myName, average)

        actuallyPlot(EADir, galaxy, plotType, nFP, dataInd, slice)
Exemplo n.º 2
0
def plotReSpectra(EADir, galaxy, DAPtype, plotType, dataInd, dataCube, waveVec):
    nFP = dF.assure_path_exists(os.path.join(
        EADir, DAPtype, 'PLOTS', 'DAP', galaxy.PLATEIFU, 'ReSpectra'))
    # unitsY = hdu[0].header['BUNIT']
    unitsX = 'Wavelength (Angstroms)'
    # unitsY = '$' + unitsY + '$'
    # unitsX = '$' + unitsX + '$'

    unitsY = '$f_{\\lambda}$ ' + \
        ' (' + '$10^{-17}$' + 'erg/s/cm' + '$^{2}$' + '/Ang)'

    hex_at_Cen, gal_at_Cen = fE.getCenters(
        galaxy.myHDU, galaxy.PLATEIFU, dataInd)

    refPnt = [hex_at_Cen[1], hex_at_Cen[0]]

    radii = [0.25, .5, 1.0]
    # radii = [1, 2, 3]

    # ReSpectra, dictRadiiSpaxNum = createRadialSpectra(waveVec, dataCube, radii, refPnt, Re)
    NormalizedReSpectra, dictRadiiSpaxNum = createRadialSpectra(
        waveVec, dataCube, radii, refPnt, galaxy.Re, normWavelength=5500)

    # ReSpectra, dictWedgeSpaxNum = createWedgeSpectra(dataCube, radii, refPnt, Re, hdu, plate_IFU, dataInd, center)

    # plotSideBySideSpectra(plate_IFU, radii, waveVec, ReSpectra, dictRadiiSpaxNum, unitsX, unitsY, EADir, nFP, '123')
    # plotStackedSpectra(plate_IFU, radii, waveVec, ReSpectra, dictRadiiSpaxNum, unitsX, unitsY, EADir, nFP)
    plotStackedSpectra(galaxy.PLATEIFU, radii, waveVec, NormalizedReSpectra, dictRadiiSpaxNum,
                       unitsX, unitsY, EADir, nFP, extraLabel='Normed')
Exemplo n.º 3
0
def plotLonePlot(EADir,
                 galaxy,
                 nFP,
                 dataInd,
                 slice,
                 newFileName,
                 plotTitle,
                 plotType='',
                 vmax=None,
                 vmin=None):
    hex_at_Cen, gal_at_Cen = fE.getCenters(galaxy.myHDU, galaxy.PLATEIFU,
                                           dataInd)

    # print("Masking " + str(round(float(sum(sum(maskMat)) * 100) /
    #                              (maskMat.shape[0] * maskMat.shape[1]), 2)) + ' percent of the data matrix; ~40 percent is great data')

    aspectRatio = 34.0 / 13
    height = 19.0 / 2
    fig = plt.figure(figsize=(height * aspectRatio / 2, height))
    fig.subplots_adjust(hspace=0.25)
    # plt.figure()
    plt.suptitle(plotTitle, fontsize=fontsize + 5, fontweight='bold')

    is_eps = True

    axes1 = plt.subplot(1, 1, 1)
    if is_eps:
        axes1.set_rasterized(True)
    spatiallyResolvedPlot(galaxy, plotType, newFileName, dataInd, slice,
                          hex_at_Cen, gal_at_Cen, vmax, vmin, axes1)

    # fig.tight_layout()
    try:
        # plt.show()
        # print(jello)
        # print("saving to " + os.path.join(nFP, newFileName + 'lone.png'))
        if is_eps:
            plt.savefig(os.path.join(nFP, newFileName + 'lone.eps'),
                        format='eps')
        else:
            plt.savefig(os.path.join(nFP, newFileName + 'lone.png'))
    except AttributeError:
        print("Error generating plots. Plot not saved :: " +
              os.path.join(nFP, newFileName + '.png'))
    #print(jello)
    plt.close()
Exemplo n.º 4
0
def plotQuadPlot(EADir,
                 galaxy,
                 nFP,
                 dataInd,
                 slice,
                 newFileName,
                 plotTitle,
                 vmax=None,
                 vmin=None):

    hex_at_Cen, gal_at_Cen = fE.getCenters(galaxy.myHDU, galaxy.PLATEIFU,
                                           dataInd)

    # print("Masking " + str(round(float(sum(sum(maskMat)) * 100) /
    #                              (maskMat.shape[0] * maskMat.shape[1]), 2)) + ' percent of the data matrix; ~40 percent is great data')

    aspectRatio = 17.0 / 13
    height = 19
    fig = plt.figure(figsize=(height * aspectRatio, height))
    fig.subplots_adjust(hspace=0.25)
    # plt.figure()
    plt.suptitle(plotTitle, fontsize=fontsize + 5, fontweight='bold')

    axes1 = plt.subplot(2, 2, 1)
    opticalImage(EADir, galaxy, dataInd, axes1)
    # dOP.plotHexagon(axes1, plate_IFU)

    axes2 = plt.subplot(2, 2, 2)
    spatiallyResolvedPlot(galaxy, "", newFileName, dataInd, slice, hex_at_Cen,
                          gal_at_Cen, vmax, vmin, axes2)

    plotAxisCrossSections(galaxy, slice, hex_at_Cen, gal_at_Cen, axes2)

    # fig.tight_layout()
    try:
        # plt.show()
        # print(jello)
        print("saving to " + os.path.join(nFP, newFileName + 'quad.png'))
        plt.savefig(os.path.join(nFP, newFileName + 'quad.png'))
    except AttributeError:
        print("Error generating plots. Plot not saved :: " +
              os.path.join(nFP, newFileName + '.png'))
    #print(jello)
    plt.close()
Exemplo n.º 5
0
def plotReSpectra(EADir, galaxy, DAPtype, plotType, dataInd, dataCube,
                  waveVec):
    print("plotReSpectra(" + galaxy.PLATEIFU + ")")
    nFP = dF.assure_path_exists(
        os.path.join(EADir, DAPtype, 'PLOTS', 'DAP', galaxy.PLATEIFU,
                     'ReSpectra'))
    # unitsY = hdu[0].header['BUNIT']
    unitsX = '$\\lambda$ (Ang)'
    # unitsY = '$' + unitsY + '$'
    # unitsX = '$' + unitsX + '$'

    hex_at_Cen, gal_at_Cen = fE.getCenters(galaxy.myHDU, galaxy.PLATEIFU,
                                           dataInd)

    refPnt = [hex_at_Cen[1], hex_at_Cen[0]]

    radii_buckets = [(0, 1), (1, 2), (2, 3)]

    normed = True
    eps = True

    if normed:
        unitsY = '$f_{\\lambda}$ / $f_{5500 nm}$'
    else:
        unitsY = '$f_{\\lambda}$ ' + \
        ' (' + '$10^{-17}$' + 'erg/s/cm' + '$^{2}$' + '/Ang)'

    ReSpectraValues, dictRadiiSpaxNum = createRadiiRangesBuckets(
        waveVec,
        dataCube,
        radii_buckets,
        refPnt,
        galaxy.Re,
        normWavelength=5500 if normed else None)

    # write_csv(nFP, galaxy.PLATEIFU, waveVec, radii_buckets, ReSpectraValues)

    # plotSideBySideSpectra(galaxy.PLATEIFU, radii_buckets, waveVec, ReSpectraValues, dictRadiiSpaxNum,
    #                    unitsX, unitsY, EADir, nFP, normed, eps)
    plotSharingAxesSpectra(galaxy.PLATEIFU, radii_buckets, waveVec,
                           ReSpectraValues, dictRadiiSpaxNum, unitsX, unitsY,
                           EADir, nFP, normed, eps)
Exemplo n.º 6
0
def createWedgeSpectra(dataCube, radii, refPnt, Re, hdu, plate_IFU, dataInd,
                       center):
    ReSpectra = [np.zeros(dataCube.shape[0]) for i in range(len(radii) * 4)]
    spaxCounts = np.zeros(len(radii) * 4)
    dictWedgeSpaxNum = {}

    hex_at_Cen, gal_at_Cen = fE.getCenters(hdu, plate_IFU, dataInd)
    axisCoordMaj, mMaj, bMaj = pT.getAxisLineProperties(
        plate_IFU, 'major', center, gal_at_Cen, hex_at_Cen)
    axisCoordMin, mMin, bMin = pT.getAxisLineProperties(
        plate_IFU, 'minor', center, gal_at_Cen, hex_at_Cen)

    wedgeLabelMat = createWedgeLabelMat(dataCube[0].shape, radii, Re, refPnt,
                                        mMaj, bMaj, mMin, bMin)

    # plt.figure()
    # plt.imshow(wedgeLabelMat, origin='lower', interpolation='nearest')
    # plt.colorbar()
    # plt.show()
    # print(jello)

    for y in range(wedgeLabelMat.shape[0]):
        for x in range(wedgeLabelMat.shape[1]):
            for mod in range(1, 5):
                if wedgeLabelMat[y, x] % 5 == mod:
                    currDist = mF.calculateDistance(x, y, refPnt[0], refPnt[1])
                    for r in range(len(radii)):
                        if currDist <= radii[r] * Re:
                            index = mod + r * 5 - 1
                            if index > 4:
                                index -= 1
                            if index > 9:
                                index -= 1
                            ReSpectra[index] = ReSpectra[index] + \
                                dataCube[:, y, x]

    return ReSpectra, dictWedgeSpaxNum
Exemplo n.º 7
0
def createWedgeSpectra(dataCube, radii, refPnt, Re, hdu, plate_IFU, dataInd, center):
    ReSpectra = [np.zeros(dataCube.shape[0]) for i in range(len(radii) * 4)]
    spaxCounts = np.zeros(len(radii) * 4)
    dictWedgeSpaxNum = {}

    hex_at_Cen, gal_at_Cen = fE.getCenters(hdu, plate_IFU, dataInd)
    axisCoordMaj, mMaj, bMaj = pT.getAxisLineProperties(
        plate_IFU, 'major', center, gal_at_Cen, hex_at_Cen)
    axisCoordMin, mMin, bMin = pT.getAxisLineProperties(
        plate_IFU, 'minor', center, gal_at_Cen, hex_at_Cen)

    wedgeLabelMat = createWedgeLabelMat(
        dataCube[0].shape, radii, Re, refPnt, mMaj, bMaj, mMin, bMin)

    # plt.figure()
    # plt.imshow(wedgeLabelMat, origin='lower', interpolation='nearest')
    # plt.colorbar()
    # plt.show()
    # print(jello)

    for y in range(wedgeLabelMat.shape[0]):
        for x in range(wedgeLabelMat.shape[1]):
            for mod in range(1, 5):
                if wedgeLabelMat[y, x] % 5 == mod:
                    currDist = mF.calculateDistance(x, y, refPnt[0], refPnt[1])
                    for r in range(len(radii)):
                        if currDist <= radii[r] * Re:
                            index = mod + r * 5 - 1
                            if index > 4:
                                index -= 1
                            if index > 9:
                                index -= 1
                            ReSpectra[index] = ReSpectra[index] + \
                                dataCube[:, y, x]

    return ReSpectra, dictWedgeSpaxNum
Exemplo n.º 8
0
def plotQuadPlot(EADir, galaxy, nFP, dataInd, slice, newFileName, plotTitle, vmax=None, vmin=None):

    hex_at_Cen, gal_at_Cen = fE.getCenters(
        galaxy.myHDU, galaxy.PLATEIFU, dataInd)

    # print("Masking " + str(round(float(sum(sum(maskMat)) * 100) /
    #                              (maskMat.shape[0] * maskMat.shape[1]), 2)) + ' percent of the data matrix; ~40 percent is great data')

    aspectRatio = 17.0 / 13
    height = 19
    fig = plt.figure(figsize=(height * aspectRatio, height))
    fig.subplots_adjust(hspace=0.25)
    # plt.figure()
    plt.suptitle(plotTitle, fontsize=fontsize + 5, fontweight='bold')

    axes1 = plt.subplot(2, 2, 1)
    opticalImage(EADir, galaxy, dataInd, axes1)
    # dOP.plotHexagon(axes1, plate_IFU)

    axes2 = plt.subplot(2, 2, 2)
    spatiallyResolvedPlot(galaxy, "", newFileName, dataInd,
                          slice, hex_at_Cen, gal_at_Cen, vmax, vmin, axes2)

    simple = 'No'
    if simple == 'No':
        plotAxisCrossSections(galaxy, slice, hex_at_Cen, gal_at_Cen, axes2)

    # fig.tight_layout()
    try:
        #plt.show()
        #print(jello)
        plt.savefig(os.path.join(nFP, newFileName + '.png'))
    except AttributeError:
        print("Error generating plots. Plot not saved :: "+ os.path.join(nFP, newFileName + '.png'))
    #print(jello)
    plt.close()
Exemplo n.º 9
0
    def plot(self, EADir, galaxy, plotType):

        if plotType == 'sfh':
            plotSFH(EADir, galaxy)
        else:
            if plotType == 'flux_elines':
                if not galaxy.myFilename.startswith(plotType):
                    print("No plots of type (" + plotType +
                          ") to make for the file " + galaxy.myFilename)
                    return
            if plotType == 'indices.cs':
                if not galaxy.myFilename.startswith(plotType[:7]):
                    print("No plots of type (" + plotType +
                          ") to make for the file " + galaxy.myFilename)
                    return

            galaxy.setCenterType('HEX')
            galaxy.pullRe(EADir, 'MPL-4')

            NAXIS3 = fE.getNAXIS3(galaxy.myHDU)

            titleHdr = fE.getTitleHeaderPrefix(galaxy.myHDU)

            dataInd = 0

            dictPlotTitles_Index, dictPlotTitles_Error, dictPlotTitles_Pair = self.createDictionaries(
                galaxy, NAXIS3, titleHdr, dataInd)

            PIPE3D_Dir = os.path.join(EADir, "MPL-4", "PLOTS", "PIPE3D")

            if plotType == 'requested':
                requestedWithin = [['velocity', 'stellar population'], [
                    'Ha'], ['Hd'], ['Halpha']]

                dictPlotTitles_Index, dictPlotTitles_Error, dictPlotTitles_Pair = self.removeNonRequested(
                    dictPlotTitles_Index, dictPlotTitles_Error, dictPlotTitles_Pair, requestedWithin)

                nFP = dF.assure_path_exists(os.path.join(
                    PIPE3D_Dir, plotType, galaxy.PLATEIFU))
                nFPraw = ''
            else:
                nFP = dF.assure_path_exists(os.path.join(
                    PIPE3D_Dir, galaxy.PLATEIFU, plotType))
                nFPraw = dF.assure_path_exists(os.path.join(
                    PIPE3D_Dir, galaxy.PLATEIFU, plotType, 'RAW'))

            if not bool(dictPlotTitles_Index):
                print("No plots of type (" + plotType +
                      ") to make for the file " + galaxy.myFilename)
                return
            elif nFPraw != '':
                hex_at_Cen, gal_at_Cen = fE.getCenters(
                    galaxy.myHDU, galaxy.PLATEIFU, dataInd)
                for key in dictPlotTitles_Index.keys():
                    if key in dictPlotTitles_Error.values():
                        continue
                    dataMat, maskMat, newFileName, plotTitle, units = self.prepData(
                        dictPlotTitles_Index, key, galaxy, dataInd, NAXIS3)
                    if dataMat is None:
                        continue
                    aspectRatio = 16.0 / 13
                    height = 10
                    fig = plt.figure(figsize=(aspectRatio * height, height))
                    plt.suptitle(galaxy.PLATEIFU + " :: " + newFileName)
                    axes = plt.gca()
                    slice = self.createSlice(dataMat, maskMat, units)
                    pF.spatiallyResolvedPlot(galaxy,
                                             plotType,
                                             newFileName,
                                             dataInd,
                                             slice,
                                             hex_at_Cen,
                                             gal_at_Cen,
                                             None,
                                             None,
                                             axes)
                    # fig.tight_layout()
                    # plt.show()
                    # print(jello)
                    plt.savefig(os.path.join(nFPraw,newFileName + '.png'))
                    # print(jello)
                    plt.close()

            if bool(dictPlotTitles_Error):
                for key in dictPlotTitles_Error.keys():
                    dataMat, maskMat, newFileName, plotTitle, units = self.prepData(
                        dictPlotTitles_Index, key, galaxy, dataInd, NAXIS3)
                    if dataMat is None:
                        continue
                    keyOfError = dictPlotTitles_Error[key]
                    errMat = galaxy.myHDU[dataInd].data[dictPlotTitles_Index[keyOfError]]
                    slice = self.createSlice(dataMat, maskMat, units)
                    slice.setError(errMat)
                    pF.plotQuadPlot(EADir,
                                    galaxy,
                                    nFP,
                                    dataInd,
                                    slice,
                                    newFileName,
                                    plotTitle,
                                    vmax=None,
                                    vmin=None)

            if bool(dictPlotTitles_Pair):
                for key in dictPlotTitles_Pair.keys():
                    dataMat1, maskMat1, newFileName1, plotTitle1, units1 = self.prepData(
                        dictPlotTitles_Index, key, galaxy, dataInd, NAXIS3)
                    dataMat2, maskMat2, newFileName2, plotTitle2, units2 = self.prepData(
                        dictPlotTitles_Index, dictPlotTitles_Pair[key], galaxy, dataInd, NAXIS3)
                    if dataMat1 is None or dataMat2 is None:
                        continue
                    slice1 = self.createSlice(dataMat1, maskMat1, units1)
                    slice2 = self.createSlice(dataMat2, maskMat2, units2)
                    pF.plotComparisonPlots(galaxy,
                                           dataInd,
                                           nFP,
                                           EADir,
                                           plotType,
                                           newFileName1,
                                           newFileName2,
                                           slice1,
                                           slice2,
                                           hex_at_Cen,
                                           gal_at_Cen
                                           )
Exemplo n.º 10
0
    def plot(self, EADir, galaxy, plotType):
        

        if plotType == 'sfh' and self.DAPtype == 'MPL-4':
            plotSFH(EADir, galaxy)
        else:
            if not self.are_there_plots_to_make(galaxy.myFilename, plotType):
                return
            # print(galaxy.myFilename)
            # print(plotType)

            PIPE3D_Dir = os.path.join(EADir, self.DAPtype, "PLOTS", "PIPE3D")
            # print("PIPE3D_Dir=" + str(PIPE3D_Dir))
            
            galaxy.setCenterType('HEX')
            
            galaxy.pullRe(EADir, self.DAPtype)
            # print("Re=" + str(galaxy.Re))
            
            NAXIS3 = fE.getNAXIS3(galaxy.myHDU)
            # print("NAXIS3=" + str(NAXIS3))
            
            titleHdr = fE.getTitleHeaderPrefix(galaxy.myHDU)
            # print("titleHdr=" + str(titleHdr))

            dataInd = 0
            # print("dataInd=" + str(dataInd))

            plotsToMake = self.createDictionaries(galaxy,
                                                  NAXIS3,
                                                  titleHdr,
                                                  dataInd)
            numberOfNormalPlotsToMake = sum([1 for p in plotsToMake.keys() if 'index' in plotsToMake[p]])
            numberOfErrorPlotsToMake = sum([1 for p in plotsToMake.keys() if 'error' in plotsToMake[p]])
            numberOfPairPlotsToMake = sum([1 for p in plotsToMake.keys() if 'pair' in plotsToMake[p]])

            print(
                "normalPlots=" + str(numberOfNormalPlotsToMake),
                "errorPlots=" + str(numberOfErrorPlotsToMake),
                "pairPlots=" + str(numberOfPairPlotsToMake)
            )
            
            if plotType == 'requested' or plotType == 'requested2':
                # if requested plots then remove unecessary plot titles and change directory
                requestedWithin = [
                    ['velocity', 'stellar population'],
                    ['Ha'],
                    ['Hd'],
                    ['Halpha']
                ]
                plotsToMake = self.removeNonRequested( plotsToMake, requestedWithin )

                numberOfNormalPlotsToMake = sum([1 for p in plotsToMake.keys() if 'index' in plotsToMake[p]])
                numberOfErrorPlotsToMake = sum([1 for p in plotsToMake.keys() if 'error' in plotsToMake[p]])
                numberOfPairPlotsToMake = sum([1 for p in plotsToMake.keys() if 'pair' in plotsToMake[p]])

                print(
                    "normalPlots=" + str(numberOfNormalPlotsToMake),
                    "errorPlots=" + str(numberOfErrorPlotsToMake),
                    "pairPlots=" + str(numberOfPairPlotsToMake)
                )



            if numberOfNormalPlotsToMake == 0:
                print("No plots of type (" + plotType +
                       ") to make for the file " + galaxy.myFilename)
                return
            
            nFP, nFPraw = self.create_directories(plotType, PIPE3D_Dir, galaxy.PLATEIFU)

            hex_at_Cen, gal_at_Cen = fE.getCenters(
                    galaxy.myHDU, galaxy.PLATEIFU, dataInd)

            for rawPlotTitle, plotInfo in plotsToMake.items():
                dataMat, maskMat, newFileName, plotTitle, units = self.prepData(
                    plotInfo['index'],
                    rawPlotTitle,
                    galaxy,
                    dataInd,
                    NAXIS3
                )
                if dataMat is None:
                    return
                slice = self.createSlice(dataMat, maskMat, units)

                if nFPraw != '':
                    try:
                        self.plotRaw(galaxy,
                                     newFileName,
                                     dataInd,
                                     plotType,
                                     slice,
                                     hex_at_Cen,
                                     gal_at_Cen,
                                     nFPraw)
                    except Exception as e:
                        print(e)
                        plt.close()
                        continue
                
                if numberOfNormalPlotsToMake < 20:
                    pF.plotDuoPlot(EADir,
                                   galaxy,
                                   nFP,
                                   dataInd,
                                   slice,
                                   newFileName,
                                   plotTitle,
                                   plotType,
                                   vmax=None,
                                   vmin=None)


                if 'error' in plotInfo.keys():
                    errorPlotTitle = plotInfo['error']
                    errMat = galaxy.myHDU[dataInd].data[plotsToMake[errorPlotTitle]['index']]
                    slice.setError(errMat)
                    try:
                        pF.plotQuadPlot(EADir,
                                        galaxy,
                                        nFP,
                                        dataInd,
                                        slice,
                                        newFileName,
                                        plotTitle,
                                        vmax=None,
                                        vmin=None)
                    except Exception as e:
                        plt.close()
                        print(e)
                        if numberOfNormalPlotsToMake >= 20:
                            pF.plotDuoPlot(EADir,
                                           galaxy,
                                           nFP,
                                           dataInd,
                                           slice,
                                           newFileName,
                                           plotTitle,
                                           vmax=None,
                                           vmin=None)

                if 'pair' in plotInfo.keys():
                    dataMat2, maskMat2, newFileName2, plotTitle2, units2 = self.prepData(
                        plotInfo['index'], plotsToMake[plotInfo['pair']]['index'], galaxy, dataInd, NAXIS3)

                    if dataMat2 is None:
                        return
                    
                    slice2 = self.createSlice(dataMat2, maskMat2, units2)
                    pF.plotComparisonPlots(galaxy,
                                           dataInd,
                                           nFP,
                                           EADir,
                                           plotType,
                                           newFileName,
                                           newFileName2,
                                           slice,
                                           slice2,
                                           hex_at_Cen,
                                           gal_at_Cen)


            return