// Spectra Profile // Analyze Rainbow Optics diffraction grating spectra. // The spectra is horziontal and to the right side of the zero mode // The Spectrum Vertical Offset is for adjusting a few pixels slant horziontal (in my case 3 pixels clockwise slant.) // This default path is C:\Spectra\ // This ImageJ macro was development with ImageJ 1.43u // Max profile length is 590 pixels. // // // Clear and dark skies, // David Haworth // http://www.stargazing.net/david versionNum = 3.4; userSelect = false ; // true for image that is opened, false for automatically opening an image // First Menu Defaults objectName = "vega08062010-01405s"; path = "C:\\Spectra\\"; fileName = "vega08062010-01405s.fit"; xCentroid = 1100; yCentroid = 751; selectionXwidth = 525; plotStartpixel= 162; selectionHeight = 6; selectionHeightOffset = 2; showHalpha = true; showHbeta = true; showHgamma = true; showHdelta = true; showHepsilon = false; showHzeta = false; showO_III = false; showTelluricBands= true; showTelluric6276= false; showTelluric6310= false; showTelluric6887 = false; showTelluric6924 = false; showTelluric7633= true; showTelluric7684= true; showRedshiftElements = false; nedRedshift = 0; changeAnalysis = false; saveCalibratedSpectrumTable = true; showProcessSpectrum = true; showSpectrumSurfacePlot = true; fixWindowLocation = true; changeCalValues = false; // First Menu Defaults End // Second Menu Defaults Change Spectrum Calibration Values gratingFilter ="RO200"; gratingDisToCCD = 0.01832719265135; pixelSize = 0.0000068; useLinearCal = false; specAdjustB = -2.5982; specAdjustHa = 357; specAdjustHg = 18.3653;// 18.3653 specAdjustDelta =136; //136 notCalImage = true; imageBias = 225.680; pixelPositionTelluric7658Band = 416;//416 pixelPositionHalpha = 357; pixelPositionHbeta = 263 ; pixelPositionHgamma = 234; pixelPositionHdelta = 221; angstromsDiffTelluric7658Band = 0; angstromsDiffHalpha = 0; angstromsDiffHbeta = 0; angstromsDiffHgamma = 0; angstromsDiffHdelta = 0; bgXOffSet=50; bgYOffSet=-10; bgWidth=90; bgHeight=20; // Second Menu Defaults End // Other variables bgX=0; bgY=0; bgCount=0; bgMean=0; bgMin=0; bgMax=0; bgStd=0; bgHist=0; // Other constants angstroms = 10000000000; gratingRes = 0.000005; imageZoom = 1; Telluric7658Band = 7658; h_alpha = 6563; h_beta = 4861; h_gamma = 4341; h_delta = 4102; h_epsilon = 3970; h_zeta = 3889; o_III = 5007; requires("1.43u"); run("Appearance...", " open antialiased menu=14"); // Open images at 100% dateTime = dateTimeStr(); run("Input/Output...", "jpeg=98 gif=-1 file=.xls copy"); if(userSelect == true) { run("Measure"); xCentroid = getResult("X"); yCentroid = getResult("Y"); } // Show First Menu Dialog.create("Spectrum Calibration V"+versionNum+" Macro"); if(userSelect == false) { Dialog.addMessage("Defaut Values are for "+objectName); Dialog.addString("Object_Name", objectName,18); Dialog.addString("Directory_Path_for_the_Below_Image_File", path,18); Dialog.addString("Image_Fit_File", fileName,18); } else { Dialog.addString("Object_Name", objectName,18);} Dialog.addNumber("Zero_Mode_X_Centroid", xCentroid); Dialog.addNumber("Zero_Mode_Y_Centroid", yCentroid); Dialog.addNumber("X_Centroid_to_End_of_Spectrum_Width_Max_590", selectionXwidth); Dialog.addNumber("Spectrum_Plot_Start", plotStartpixel); Dialog.addNumber("Spectrum_Selection_Height", selectionHeight); Dialog.addNumber("Spectrum_Selection_Vertical_Offset", selectionHeightOffset); Dialog.addCheckbox("Show_H-alpha_Emission_Line", showHalpha); Dialog.addCheckbox("Show_H-beta_Emission_Line", showHbeta); Dialog.addCheckbox("Show_H-gamma_Emission_Line", showHgamma); Dialog.addCheckbox("Show_H-delta_Emission_Line", showHdelta); Dialog.addCheckbox("Show_H-epsilon_Emission_Line", showHepsilon); Dialog.addCheckbox("Show_H-zeta_Emission_Line", showHzeta); Dialog.addCheckbox("Show_O[III]_Emission_Line", showO_III); Dialog.addCheckbox("Show_Telluric_Bands", showTelluricBands); Dialog.addCheckbox("Show_Emission_Lines_with_Redshift", showRedshiftElements); Dialog.addNumber("Redshift", nedRedshift); Dialog.addCheckbox("Change_Analysis", changeAnalysis); Dialog.addCheckbox("Change_Spectrum_Calibration_Values", changeCalValues); Dialog.show(); // End of Show First Menu // Get First Menu Values objectName = Dialog.getString(); if(userSelect == false) { path = Dialog.getString(); fileName = Dialog.getString(); } xCentroid = Dialog.getNumber(); yCentroid = Dialog.getNumber(); selectionXwidth = Dialog.getNumber(); plotStartpixel = Dialog.getNumber(); selectionHeight = Dialog.getNumber(); selectionHeightOffset = Dialog.getNumber(); showHalpha = Dialog.getCheckbox(); showHbeta = Dialog.getCheckbox(); showHgamma = Dialog.getCheckbox(); showHdelta = Dialog.getCheckbox(); showHepsilon = Dialog.getCheckbox(); showHzeta = Dialog.getCheckbox(); showO_III = Dialog.getCheckbox(); showTelluricBands = Dialog.getCheckbox(); showRedshiftElements = Dialog.getCheckbox(); nedRedshift = Dialog.getNumber(); changeAnalysis = Dialog.getCheckbox(); changeCalValues = Dialog.getCheckbox(); // End of Get First Menu Values // Second Menu if(changeAnalysis == true){ // Show Second Menu Dialog.create("Change Analysis Config."); Dialog.addCheckbox("Save_Spectrum_Table", saveCalibratedSpectrumTable); Dialog.addCheckbox("Show_Process_Spectrum", showProcessSpectrum); Dialog.addCheckbox("Show_Spectrum_Surface_Plot", showSpectrumSurfacePlot); Dialog.addCheckbox("Fixed_Windows_Locations", fixWindowLocation); Dialog.show(); // Show Second Menu // Get Second Menu Values saveCalibratedSpectrumTable = Dialog.getCheckbox(); showProcessSpectrum = Dialog.getCheckbox(); showSpectrumSurfacePlot = Dialog.getCheckbox(); fixWindowLocation = Dialog.getCheckbox(); } // End of Get Second Menu // Third Menu if(changeCalValues == true){ // Show Third Menu Dialog.create("Change Spectrum Calibration Values"); Dialog.addChoice("Grating_Filter", newArray("RO200", "SA100"), gratingFilter); Dialog.addNumber("Grating_Distance_to_CCD_in_mm", gratingDisToCCD*1000); Dialog.addNumber("CCD_Pixel_Size_in_Microns", pixelSize*1000000); Dialog.addMessage("Linear Calibration Values"); Dialog.addNumber("Telluric_7658_Band_Pixel_Location", pixelPositionTelluric7658Band); Dialog.addNumber("H-alpha_Pixel_Location", pixelPositionHalpha); Dialog.addNumber("H-beta_Pixel_Location", pixelPositionHbeta); Dialog.addNumber("H-gamma_Pixel_Location", pixelPositionHgamma); Dialog.addNumber("H-delta_Pixel_Location", pixelPositionHdelta); // Dialog.addMessage("Frist Try Linear Calibration Values"); // Dialog.addCheckbox("Linear_Calibration", useLinearCal); // Dialog.addNumber("Angrstoms_to_Adjust_at_H-alpha", specAdjustB); // Dialog.addNumber("H-alpha_Pixel", specAdjustHa); // Dialog.addNumber("Angstroms_to_Adjust_at_H-delta", specAdjustHg); // Dialog.addNumber("Number_of_Pixels_Between_H-a_and_to_H-d", specAdjustDelta); Dialog.addCheckbox("Subtract_Bias", notCalImage); Dialog.addNumber("Image_Bias", imageBias); Dialog.addMessage("Background Selection for Signal to Noise Ratio"); Dialog.addNumber("X_Offset_from_Zero_Mode_X_Centroid", bgXOffSet); Dialog.addNumber("Y_Offset_from_Zero_Mode_Y_Centroid", bgYOffSet); Dialog.addNumber("Selection_Width", bgWidth); Dialog.addNumber("Selection_Height", bgHeight); Dialog.show(); // Show Third Menu // Get Third Menu Values gratingFilter = Dialog.getChoice(); gratingDisToCCD = Dialog.getNumber()/1000; pixelSize = Dialog.getNumber()/1000000; pixelPositionTelluric7658Band = Dialog.getNumber(); pixelPositionHalpha = Dialog.getNumber(); pixelPositionHbeta = Dialog.getNumber(); pixelPositionHgamma = Dialog.getNumber(); pixelPositionHdelta = Dialog.getNumber(); // useLinearCal = Dialog.getCheckbox(); // specAdjustB = Dialog.getNumber(); // specAdjustHa = Dialog.getNumber(); // specAdjustHg = Dialog.getNumber(); // specAdjustDelta =Dialog.getNumber(); notCalImage = Dialog.getCheckbox(); imageBias =Dialog.getNumber(); bgXOffSet=Dialog.getNumber(); bgYOffSet=Dialog.getNumber(); bgWidth=Dialog.getNumber(); bgHeight=Dialog.getNumber(); } // End of Third Menu if(useLinearCal == false){ specAdjustB = 0; specAdjustHa = 0; specAdjustHg = 0; specAdjustDelta =1; } // Add File.separator to path if missing if(endsWith(path, File.separator)== false) path=path+File.separator; analyzeDir = path+objectName+"_"+dateTime+File.separator; File.makeDirectory(analyzeDir); fileNameSave = objectName+"_"+dateTime; pathFileNameSave = analyzeDir+fileNameSave; selectionX = xCentroid; selectionY = yCentroid; if(gratingFilter == "SA100") gratingRes = gratingRes*2; angstromsMin = sin(atan(pixelSize*(plotStartpixel)/gratingDisToCCD))*gratingRes*angstroms; angstromsMax = sin(atan(pixelSize*(selectionXwidth)/gratingDisToCCD))*gratingRes*angstroms; // Close Log and Profile window if (isOpen("Log")) { selectWindow("Log"); run("Close");} if (isOpen("Profile")) {selectWindow("Profile"); run("Close");} if (isOpen("Results")) {selectWindow("Results"); run("Close");} if(userSelect == false) { // Open file, adjust black point to min-10 and white point min+60 open(path+fileName); run("Flip Vertically"); } run("Set... ", "zoom=50"); // Fix background selection imageZoom = getZoom; centroidPixelValue= getPixel(xCentroid, yCentroid); if(bitDepth()!=32) run("32-bit"); if((getWidth-xCentroid) < selectionXwidth) selectionXwidth = (getWidth-xCentroid); saveAs("FITS", pathFileNameSave); run("Set Measurements...", " min centroid center redirect=None decimal=4"); run("Measure"); getRawStatistics(count, mean, min, max, std, hist); run("Brightness/Contrast..."); setMinAndMax(min-10, min+60); // Selection and get profile selectWindow(fileNameSave+".fits"); makeRectangle(xCentroid-10, yCentroid-10, 20, 20); run("Measure"); xCentroidMeas = getResult("X"); yCentroidMeas = getResult("Y"); // Background Measurements bgX=selectionX+bgXOffSet; bgY=selectionY+bgYOffSet; specTitle3 = getTitle; makeRectangle(bgX, bgY, bgWidth, bgHeight); getRawStatistics(bgCount, bgMean, bgMin, bgMax, bgStd, bgHist); run("Brightness/Contrast..."); setMinAndMax(bgMin-10, bgMin+60); // Remove image bias from background mean, minimum and maximum. if(notCalImage == true) { bgMean = bgMean - imageBias; bgMin = bgMin - imageBias; bgMax = bgMax - imageBias; } run("Capture Image"); saveAs("Tiff", pathFileNameSave+"BgSelection.tif"); bgXCrop=selectionX-30; bgHeightCrop=bgHeight; bgYCrop=selectionY-bgHeight*2; bgWidthCrop=selectionXwidth+30; makeRectangle(bgXCrop*imageZoom, bgYCrop*imageZoom, bgWidthCrop*imageZoom, bgHeightCrop*4*imageZoom); run("Crop"); saveAs("Jpeg", pathFileNameSave+"BgSelectionCrop.jpg"); if(fixWindowLocation == true) setLocation(700,700); selectWindow(specTitle3); // Spectrums Measurements makeRectangle(selectionX, selectionY-(selectionHeight/2)+selectionHeightOffset, selectionXwidth, selectionHeight); profile = getProfile(); // Plot spectrum profile starting at about 3,000 angstroms maxProfileSize = selectionXwidth-plotStartpixel; if(maxProfileSize>433) { maxProfileSize=433; angstromsMax = ((sin(atan(pixelSize*(plotStartpixel+maxProfileSize)/gratingDisToCCD))*gratingRes*angstroms)+specAdjustB)+((specAdjustHa-maxProfileSize)*specAdjustHg/specAdjustDelta); } makeRectangle(selectionX+plotStartpixel, selectionY-(selectionHeight/2)+selectionHeightOffset, maxProfileSize, selectionHeight); profile = getProfile(); xValues = getProfile(); profileDelta = getProfile(); xValuesSimpleCal = getProfile(); for (i=0; i profile[i]) spec_min = profile[i] ; spec_max =profile[0]; for (i=0; i xValues[i]) h_alphaHeightPixel = i+heightIndexAdjust; if (h_betaAtRedshft > xValues[i]) h_betaHeightPixel = i+heightIndexAdjust; if (h_gammaAtRedshft > xValues[i]) h_gammaHeightPixel = i+heightIndexAdjust; if (h_deltaAtRedshft > xValues[i]) h_deltaHeightPixel = i+heightIndexAdjust; if (h_epsilonAtRedshft > xValues[i]) h_epsilonHeightPixel = i+heightIndexAdjust; if (h_zetaAtRedshft > xValues[i]) h_zetaHeightPixel = i+heightIndexAdjust; if (o_IIIAtRedshft > xValues[i]) o_IIIHeightPixel = i+heightIndexAdjust; if (6276 > xValues[i]) telluric6276HeightPixel = i+heightIndexAdjust; if (6310 > xValues[i]) telluric6310HeightPixel = i+heightIndexAdjust; if (6887 > xValues[i]) telluric6887HeightPixel = i+heightIndexAdjust; if (6924 > xValues[i]) telluric6924HeightPixel = i+heightIndexAdjust; if (7633 > xValues[i]) telluric7633HeightPixel = i+heightIndexAdjust; if (7684 > xValues[i]) telluric7684HeightPixel = i+heightIndexAdjust; } // Create plot dots Plot.create(objectName, "Angstroms", "Intensity"); Plot.setLimits(angstromsMin, angstromsMax, plotMin, plotMax); Plot.setLineWidth(1); // Create Halpha, Hbeta, Hgamma and O[III] labels on spectrum profile Plot.setColor("blue"); setJustification("left"); if(showRedshiftElements==false) nedRedshift=0; if(!(nedRedshift==0)) Plot.addText("Elements at Redshift = "+nedRedshift, 0.01, 0.05); if(showHalpha== true) { xposition = (h_alphaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); h_alphaHeight = profile[h_alphaHeightPixel]; Plot.addText(" Halpha", xposition, 0.94); Plot.add("line", newArray(h_alphaAtRedshft, h_alphaAtRedshft), newArray(plotMin, h_alphaHeight)); } if(showHbeta== true) { xposition = (h_betaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hbeta", xposition, 1); Plot.add("line", newArray(h_betaAtRedshft, h_betaAtRedshft), newArray(plotMin, profile[h_betaHeightPixel])); } if(showHgamma== true) { xposition = (h_gammaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hgamma", xposition, 1); Plot.add("line", newArray(h_gammaAtRedshft, h_gammaAtRedshft), newArray(plotMin, profile[h_gammaHeightPixel])); } if(showHdelta== true) { xposition = (h_deltaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hdelta", xposition, 1); Plot.add("line", newArray(h_deltaAtRedshft, h_deltaAtRedshft), newArray(plotMin, profile[h_deltaHeightPixel])); } if(showHepsilon== true) { xposition = (h_epsilonAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hepsilon", xposition, 0.94); Plot.add("line", newArray(h_epsilonAtRedshft, h_epsilonAtRedshft), newArray(plotMin, profile[h_epsilonHeightPixel])); } if(showHzeta== true) { xposition = (h_zetaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hzeta", xposition, 1); Plot.add("line", newArray(h_zetaAtRedshft, h_zetaAtRedshft), newArray(plotMin, profile[h_zetaHeightPixel])); } if(showO_III== true) { xposition = ( o_IIIAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" O [III]", xposition, 0.94); Plot.add("line", newArray(o_IIIAtRedshft, o_IIIAtRedshft), newArray(plotMin, profile[o_IIIHeightPixel])); } // Telluric lines if(showTelluricBands== true) { if(showTelluric6276== true) { xposition = ( 6276- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(6276, 6276), newArray(plotMin, profile[telluric6276HeightPixel])); } if(showTelluric6310== true) { xposition = ( 6310- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric O2", xposition, 0.94); Plot.add("line", newArray(6310, 6310), newArray(plotMin, profile[telluric6310HeightPixel])); } if(showTelluric6887== true) { xposition = ( 6887- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(6887, 6887), newArray(plotMin, profile[telluric6887HeightPixel])); } if(showTelluric6924== true) { xposition = ( 6924- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric O2", xposition, 0.94); Plot.add("line", newArray(6924, 6924), newArray(plotMin, profile[telluric6924HeightPixel])); } if(showTelluric7633== true) { xposition = ( 7633- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(7633, 7633), newArray(plotMin, profile[telluric7633HeightPixel])); } if(showTelluric7684== true) { xposition = ( 7684- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(7684, 7684), newArray(plotMin, profile[telluric7684HeightPixel])); } } Plot.setColor("black"); Plot.add("dots", xValues, profile); Plot.show(); if(fixWindowLocation == true) setLocation(50,30); run("Capture Image"); saveAs("Jpeg", pathFileNameSave+"PlotDots.jpg"); saveAs("Tiff", pathFileNameSave+"PlotDots.tif"); run("Invert"); saveAs("Jpeg", pathFileNameSave+"PlotInvDots.jpg"); saveAs("Tiff", pathFileNameSave+"PlotInvDots.tif"); windowHeight = getHeight() +50; windowWidth = getWidth(); run("Canvas Size...", "width="+windowWidth+" height="+windowHeight+" position=Bottom-Center zero"); saveAs("Tiff", pathFileNameSave+"PlotInvBlackTopDots.tif"); run("Close"); // End of plot dots // Create plot lines Plot.create(objectName, "Angstroms", "Intensity"); Plot.setLimits(angstromsMin, angstromsMax, plotMin, plotMax); Plot.setLineWidth(1); // Create Halpha, Hbeta, Hgamma and O[III] labels on spectrum profile Plot.setColor("blue"); setJustification("left"); if(showRedshiftElements==false) nedRedshift=0; if(!(nedRedshift==0)) Plot.addText("Elements at Redshift = "+nedRedshift, 0.01, 0.05); if(showHalpha== true) { xposition = (h_alphaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); h_alphaHeight = profile[h_alphaHeightPixel]; Plot.addText(" Halpha", xposition, 0.94); Plot.add("line", newArray(h_alphaAtRedshft, h_alphaAtRedshft), newArray(plotMin, h_alphaHeight)); } if(showHbeta== true) { xposition = (h_betaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hbeta", xposition, 1); Plot.add("line", newArray(h_betaAtRedshft, h_betaAtRedshft), newArray(plotMin, profile[h_betaHeightPixel])); } if(showHgamma== true) { xposition = (h_gammaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hgamma", xposition, 1); Plot.add("line", newArray(h_gammaAtRedshft, h_gammaAtRedshft), newArray(plotMin, profile[h_gammaHeightPixel])); } if(showHdelta== true) { xposition = (h_deltaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hdelta", xposition, 1); Plot.add("line", newArray(h_deltaAtRedshft, h_deltaAtRedshft), newArray(plotMin, profile[h_deltaHeightPixel])); } if(showHepsilon== true) { xposition = (h_epsilonAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hepsilon", xposition, 0.94); Plot.add("line", newArray(h_epsilonAtRedshft, h_epsilonAtRedshft), newArray(plotMin, profile[h_epsilonHeightPixel])); } if(showHzeta== true) { xposition = (h_zetaAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Hzeta", xposition, 1); Plot.add("line", newArray(h_zetaAtRedshft, h_zetaAtRedshft), newArray(plotMin, profile[h_zetaHeightPixel])); } if(showO_III== true) { xposition = ( o_IIIAtRedshft- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" O [III]", xposition, 0.94); Plot.add("line", newArray(o_IIIAtRedshft, o_IIIAtRedshft), newArray(plotMin, profile[o_IIIHeightPixel])); } // Telluric lines if(showTelluricBands== true) { if(showTelluric6276== true) { xposition = ( 6276- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(6276, 6276), newArray(plotMin, profile[telluric6276HeightPixel])); } if(showTelluric6310== true) { xposition = ( 6310- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric O2", xposition, 0.94); Plot.add("line", newArray(6310, 6310), newArray(plotMin, profile[telluric6310HeightPixel])); } if(showTelluric6887== true) { xposition = ( 6887- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(6887, 6887), newArray(plotMin, profile[telluric6887HeightPixel])); } if(showTelluric6924== true) { xposition = ( 6924- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric O2", xposition, 0.94); Plot.add("line", newArray(6924, 6924), newArray(plotMin, profile[telluric6924HeightPixel])); } if(showTelluric7633== true) { xposition = ( 7633- angstromsMin)/(angstromsMax-angstromsMin); // Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(7633, 7633), newArray(plotMin, profile[telluric7633HeightPixel])); } if(showTelluric7684== true) { xposition = ( 7684- angstromsMin)/(angstromsMax-angstromsMin); Plot.addText(" Telluric Band", xposition, 1); Plot.add("line", newArray(7684, 7684), newArray(plotMin, profile[telluric7684HeightPixel])); } } Plot.setColor("black"); Plot.add("lines", xValues, profile); Plot.show(); if(fixWindowLocation == true) setLocation(50,70); run("Capture Image"); saveAs("Jpeg", pathFileNameSave+"Plot.jpg"); saveAs("Tiff", pathFileNameSave+"Plot.tif"); run("Invert"); saveAs("Jpeg", pathFileNameSave+"PlotInv.jpg"); saveAs("Tiff", pathFileNameSave+"PlotInv.tif"); windowHeight = getHeight() +50; windowWidth = getWidth(); run("Canvas Size...", "width="+windowWidth+" height="+windowHeight+" position=Bottom-Center zero"); saveAs("Tiff", pathFileNameSave+"PlotInvBlackTop.tif"); run("Close"); // End of plot lines // Create spectrum tables if(saveCalibratedSpectrumTable ==true) spec_max = createSpecTables (profile, plotStartpixel, pixelSize, gratingDisToCCD, gratingRes, angstroms, specAdjustB, specAdjustHa, specAdjustHg, specAdjustDelta, pathFileNameSave, profileDelta); if(showProcessSpectrum==true) specBandTitle = spectrumBands (profile, spec_max, spec_min, pathFileNameSave, fileNameSave); // Create spectrum bands at 1X and 3X if(showSpectrumSurfacePlot==true) plotSpectrum (fileNameSave); // Create 3-D surface plot of spectrum cropImageWithSelection (pathFileNameSave, fileNameSave); // Draw selection, crop image and save it cropImage (pathFileNameSave, fileNameSave, specBandTitle); // Crop image and save it saveInfo (pathFileNameSave, fileNameSave); // Save analysis setup info in Log exit; // ********************************************************************************************************************************* // Create date_time string function dateTimeStr(){ getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec); minStr = toString(minute); if(lengthOf(minStr)==1) minStr= "0"+minStr; hourStr = toString(hour); if(lengthOf(hourStr)==1) hourStr= "0"+hourStr; dayStr = toString(dayOfMonth); if(lengthOf(dayStr)==1) dayStr= "0"+dayStr; month+=1; // bug in month monthStr = toString(month); if(lengthOf(monthStr)==1) monthStr = "0"+monthStr; yearStr = toString(year); temp = yearStr+monthStr+dayStr+"_"+hourStr+minStr; return temp; } // ********************************************************************************************************************************* // Create spectrum tables function createSpecTables (profile, plotStartpixel, pixelSize, gratingDisToCCD, gratingRes, angstroms, specAdjustB, specAdjustHa, specAdjustHg, specAdjustDelta, pathFileNameSave, profileDelta) { // Display zero mode profile values in "Log" window spec_min =profile[0]; for (i=plotStartpixel; i profile[i]) spec_min = profile[i] ; spec_max =profile[0]; for (i=plotStartpixel; i profile[i]) spec_min = profile[i] ; spec_max =profile[plotStartpixel]; for (i=plotStartpixel; i (profile.length-1)) x1 = profile.length-1; else x1 = (x/3)+1; setPixel(x, y, profile8bit[x/3]); setPixel((x+1), y, (profile8bit[x/3]+(profile8bit[x1]-profile8bit[x/3])/3)); setPixel((x+2), y, (profile8bit[x/3]+(profile8bit[x1]-profile8bit[x/3])*2/3)); } } selectWindow("Spectrum3X"); setMinAndMax(0, 255); run("8-bit"); saveAs("Jpeg", pathFileNameSave+"Band3X.jpg"); saveAs("Tiff", pathFileNameSave+"Band3X.tif"); if(fixWindowLocation == true) setLocation(110,0); return specBandTitle; } // ********************************************************************************************************************************* // Create 3-D surface plot of spectrum function plotSpectrum (fileNameSave) { if (isOpen("Surface Plot")) {selectWindow("Surface Plot"); run("Close");} selectWindow(fileNameSave+".fits"); makeRectangle(selectionX+plotStartpixel, selectionY-(selectionHeight/2)+selectionHeightOffset, maxProfileSize, selectionHeight); run("Measure"); getRawStatistics(count, mean, min, max, std, hist); run("Brightness/Contrast..."); setMinAndMax(min-10, max); selectWindow(fileNameSave+".fits"); run("Surface Plot...", "polygon=100 shade draw_axis fill one smooth"); if(fixWindowLocation == true) setLocation(50,300); run("Capture Image"); saveAs("Jpeg", pathFileNameSave+"Surface.jpg"); saveAs("Tiff", pathFileNameSave+"Surface.tif"); run("Close"); } // ********************************************************************************************************************************* // Draw selection, crop image and save it function cropImageWithSelection (pathFileNameSave, fileNameSave) { selectWindow(fileNameSave+".fits"); run("Select None"); run("Duplicate...", "title=copy.fits"); setColor(65535); drawRect(selectionX+plotStartpixel-1, selectionY-(selectionHeight/2)+selectionHeightOffset-1, maxProfileSize+2, selectionHeight+2); run("Select None"); makeRectangle(selectionX-20, selectionY-20, selectionXwidth+40, selectionHeight+40); setPixel(xCentroid, yCentroid, 0); run("Crop"); if(fixWindowLocation == true) setLocation(700,600); saveAs("FITS", pathFileNameSave+"CropWithSelection"); run("Capture Image"); saveAs("Jpeg", pathFileNameSave+"CropWithSelection.jpg"); saveAs("Tiff", pathFileNameSave+"CropWithSelection.tif"); run("Close"); } // ********************************************************************************************************************************* // Crop image and save it function cropImage (pathFileNameSave, fileNameSave, specBandTitle) { selectWindow(fileNameSave+".fits"); run("Select None"); makeRectangle(selectionX-20, selectionY-10, selectionXwidth+40, selectionHeight+60); run("Crop"); saveAs("FITS", pathFileNameSave+"Crop"); specTitle2 = getTitle; run("Capture Image"); saveAs("Jpeg", pathFileNameSave+"Crop.jpg"); saveAs("Tiff", pathFileNameSave+"Crop.tif"); specTitle = getTitle; selectWindow(specBandTitle); run("Select All"); run("Copy"); run("Close"); setPasteMode("Transparent-zero"); selectWindow(specTitle); run("Paste"); makeRectangle(0, 0, getWidth, getHeight-10); run("Crop"); saveAs("Jpeg", pathFileNameSave+"SpecMerge.jpg"); saveAs("Tiff", pathFileNameSave+"SpecMerge.tif"); if(fixWindowLocation == true) setLocation(700,500); selectWindow(specTitle2); run("Close"); } // ********************************************************************************************************************************* // Save analysis setup info in Log function saveInfo (pathFileNameSave, fileNameSave) { print("Spectra Profile Macro Version:", versionNum); print("Object Name:", objectName); print("Source File Name: ", fileName); print("Save Files Directory Path:", analyzeDir); print("Save File Name: "+ fileNameSave+".fits"); print("Image Zoom on Opened Image:", imageZoom); // print(fileNameSave+"CropWithSelection.fits Image Width: "+ getWidth +" Pixels"); // print(fileNameSave+"CropWithSelection.fits Image Width: "+ getHeight +" Pixels"); print(" "); print("Zero Mode X Centroid Entered: "+ xCentroid+" Pixels"); print("Zero Mode Y Centroid Entered: "+ yCentroid+" Pixels"); print("Pixel Value at Centroid: "+ centroidPixelValue+" ADU"); // print(" "); // print("Zero Mode Spectrum Selection X: "+ selectionX+" pixels"); // print("Zero Mode Spectrum Selection Y: "+ selectionY-(selectionHeight/2)+selectionHeightOffset+" Pixels"); print("Zero Mode Spectrum Width: "+ selectionXwidth +" Pixels"); print(" "); print("Spectrum Selection Vertical Height: "+ selectionHeight+" Pixels"); print("Spectrum Selection Vertical Offset: "+ selectionHeightOffset+" Pixels"); print(" "); print("Spectrum Plot Selection X: "+ selectionX+plotStartpixel+" Pixels"); print("Spectrum Plot Selection Y: "+ selectionY-(selectionHeight/2)+selectionHeightOffset+" Pixels"); print("Spectrum Plot Selection Width: "+ selectionXwidth-plotStartpixel+" Pixels"); print("Spectrum Plot Selection Start: "+ plotStartpixel+" pixels"); print(" "); print("Spectrum Plot Selection Start: ", angstromsMin, "Angstroms"); print("Spectrum Plot Selection End: ", angstromsMax, "Angstroms"); print("Spectrum Plot Selection Range: ", angstromsMax-angstromsMin, "Angstroms"); print("Spectrum Plot Average: ", (angstromsMax-angstromsMin)/(selectionXwidth-plotStartpixel), "Angstroms/Pixel"); print(" "); print("Spectrum Plot Maximum: "+ spec_min+" ADU"); print("Spectrum Plot Minimum: "+ spec_max+" ADU"); print(" "); print("Grating Distance to CCD: "+ gratingDisToCCD*1000+" mm"); print("CCD Pixel Size: "+ pixelSize*1000000+" microns"); print(" "); // if(useLinearCal == true) print("Linear Calibration On"); else print("Linear Calibration Off"); // print("Spectrum Offset", specAdjustB); // print("H-alpha Pixel", specAdjustHa); // print("Number of A to Adjust at_H-gamma", specAdjustHg); // print("Number of Pixels to H-gamma", specAdjustDelta); // print(" "); print("Calibration H-delta Offset from X Centroid:", pixelPositionHdelta, "Pixels"); print("Calibration H-delta Offset from Plot Start:", limitHdelta, "Pixels"); print("H-delta Intensity:"); print("Pixel:",pixelPositionHdelta-1+":", profile[pixelPositionHdelta-plotStartpixel-1], "ADU"); print("Pixel:",pixelPositionHdelta+":" , profile[pixelPositionHdelta-plotStartpixel], "ADU"); print("Pixel:",pixelPositionHdelta+1+":", profile[pixelPositionHdelta-plotStartpixel+1], "ADU"); if((profile[pixelPositionHdelta-plotStartpixel] < profile[pixelPositionHdelta-plotStartpixel-1]) && (profile[pixelPositionHdelta-plotStartpixel] < profile[pixelPositionHdelta-plotStartpixel+1])) print("H-delta Intensity is at Minimum"); else print("H-delta Intensity is not at Minimum"); print(" "); print("Calibration H-gamma Offset from X Centroid:", pixelPositionHgamma, "Pixels"); print("Calibration H-gamma Offset from Plot Start:", limitHgamma, "Pixels"); print("H-gamma Intensity:"); print("Pixel:",pixelPositionHgamma-1+":", profile[pixelPositionHgamma-plotStartpixel-1], "ADU"); print("Pixel:",pixelPositionHgamma+":" , profile[pixelPositionHgamma-plotStartpixel], "ADU"); print("Pixel:",pixelPositionHgamma+1+":", profile[pixelPositionHgamma-plotStartpixel+1], "ADU"); if((profile[pixelPositionHgamma-plotStartpixel] < profile[pixelPositionHgamma-plotStartpixel-1]) && (profile[pixelPositionHgamma-plotStartpixel] < profile[pixelPositionHgamma-plotStartpixel+1])) print("H-gamma Intensity is at Minimum"); else print("H-gamma Intensity is not at Minimum"); print(" "); print("Calibration H-beta Offset from X Centroid:", pixelPositionHbeta, "Pixels"); print("Calibration H-beta Offset from Plot Start:" , limitHbeta, "Pixels"); print("H-beta Intensity:"); print("Pixel:",pixelPositionHbeta-1+":", profile[pixelPositionHbeta-plotStartpixel-1], "ADU"); print("Pixel:",pixelPositionHbeta+":" , profile[pixelPositionHbeta-plotStartpixel], "ADU"); print("Pixel:",pixelPositionHbeta+1+":", profile[pixelPositionHbeta-plotStartpixel+1], "ADU"); if((profile[pixelPositionHbeta-plotStartpixel] < profile[pixelPositionHbeta-plotStartpixel-1]) && (profile[pixelPositionHbeta-plotStartpixel] < profile[pixelPositionHbeta-plotStartpixel+1])) print("H-beta Intensity is at Minimum"); else print("H-beta Intensity is not at Minimum"); print(" "); print("Calibration H-alpha Offset from X Centroid:", pixelPositionHalpha, "Pixels"); print("Calibration H-alpha Offset from Plot Start:", limitHalpha, "Pixels"); print("H-alpha Intensity:"); print("Pixel:",pixelPositionHalpha-2+":", profile[pixelPositionHalpha-plotStartpixel-2], "ADU"); print("Pixel:",pixelPositionHalpha-1+":", profile[pixelPositionHalpha-plotStartpixel-1], "ADU"); print("Pixel:",pixelPositionHalpha+":" , profile[pixelPositionHalpha-plotStartpixel], "ADU"); print("Pixel:",pixelPositionHalpha+1+":", profile[pixelPositionHalpha-plotStartpixel+1], "ADU"); print("Pixel:",pixelPositionHalpha+2+":", profile[pixelPositionHalpha-plotStartpixel+2], "ADU"); if( (profile[pixelPositionHalpha-plotStartpixel] < profile[pixelPositionHalpha-plotStartpixel-2]) && (profile[pixelPositionHalpha-plotStartpixel] < profile[pixelPositionHalpha-plotStartpixel-1]) && (profile[pixelPositionHalpha-plotStartpixel] < profile[pixelPositionHalpha-plotStartpixel+1]) && (profile[pixelPositionHalpha-plotStartpixel] < profile[pixelPositionHalpha-plotStartpixel+2])) print("H-alpha Intensity is at Minimum"); else print("H-alpha Intensity is not at Minimum"); print(" "); print("Calibration Telluric 7658 Band Offset from X Centroid:", pixelPositionTelluric7658Band, "Pixels"); print("Calibration Telluric 7658 Band Offset from Plot Start:", limitHTelluric7658Band, "Pixels"); print("Telluric 7658 Band Intensity:"); print("Pixel:",pixelPositionTelluric7658Band-2+":", profile[pixelPositionTelluric7658Band-plotStartpixel-2], "ADU"); print("Pixel:",pixelPositionTelluric7658Band-1+":", profile[pixelPositionTelluric7658Band-plotStartpixel-1], "ADU"); print("Pixel:",pixelPositionTelluric7658Band+":", profile[pixelPositionTelluric7658Band-plotStartpixel], "ADU"); print("Pixel:",pixelPositionTelluric7658Band+1+":", profile[pixelPositionTelluric7658Band-plotStartpixel+1], "ADU"); print("Pixel:",pixelPositionTelluric7658Band+2+":", profile[pixelPositionTelluric7658Band-plotStartpixel+2], "ADU"); print(" "); print("Calibration H-delta Difference:", angstromsDiffHdelta, "Angstroms"); print("Calibration H-gamma Difference:", angstromsDiffHgamma, "Angstroms"); print("Calibration H-beta Difference:", angstromsDiffHbeta, "Angstroms"); print("Calibration H-alpha Difference:", angstromsDiffHalpha, "Angstroms"); print("Calibration T-elluric 7658 Band Difference:", angstromsDiffTelluric7658Band, "Angstroms"); print(" "); // print("Non linear spectrum adjustment, H-alpha angstroms offset: "+ specAdjustB+" Angstroms"); // print("Non linear spectrum adjustment, H-alpha pixel position "+ specAdjustHa+" Pixels"); // print("Non linear spectrum adjustment, H-delta angstroms offset: "+ specAdjustHg+" Angstroms"); // print("Non linear spectrum adjustment, H-delta to Halpha a pixel offset: "+ specAdjustDelta+" Pixels"); // print(" "); print("Redshift z:"+ nedRedshift); print("H-zeta ("+h_zeta+" Angstroms) at "+nedRedshift+" Redshift: "+ h_zetaAtRedshft + " Angstroms"); print("H-epsilon ("+h_epsilon+" Angstroms) at "+nedRedshift+" Redshift: "+ h_epsilonAtRedshft + " Angstroms"); print("H-delta ("+h_delta+" Angstroms) at "+nedRedshift+" Redshift: "+ h_deltaAtRedshft + " Angstroms"); print("H-gamma ("+h_gamma+" Angstroms) at "+nedRedshift+" Redshift: "+ h_gammaAtRedshft + " Angstroms"); print("H-beta ("+ h_beta+" Angstroms) at "+nedRedshift+" Redshift: "+ h_betaAtRedshft + " Angstroms"); print("O[III] ("+o_III+" Angstroms) at "+nedRedshift+" Redshift: "+ o_IIIAtRedshft + " Angstroms"); print("H-alpha ("+h_alpha+" Angstroms) at "+nedRedshift+" Redshift: "+ h_alphaAtRedshft + " Angstroms"); print(" "); print("Background Selection Top Left X, Y: "+ bgX+", "+bgY, "Pixels"); print("Background Selection Width: "+ bgWidth, "Pixels"); print("Background Selection Height: "+ bgHeight, "Pixels"); print("BackgroundSelection Bottom Right X, Y: "+ (bgX+bgWidth)+", "+bgY+(bgHeight), "Pixels"); print(" "); if (notCalImage == true){ print("Image is Not Dark Calibrated"); print("Fixed Bias Offset:", imageBias, "ADU"); } else { print("Dark Calibrated Image"); } print(" "); print("Background Count: "+ bgCount, "Pixels"); print("Background Mean: "+ bgMean, "ADU"); print("Background Minimum: "+ bgMin, "ADU"); print("Background Maximum: "+ bgMax, "ADU"); print("Background Standard Deviation: "+ bgStd, "ADU"); print("Background Mean/Standard Deviation: "+ bgMean/bgStd); print(" "); print("Spectrum Minimum: "+ spec_min, "ADU"); print("Spectrum Maximum: "+ spec_max, "ADU"); print("Spectrum to Noise Ratio = (Spectrum Maximum Signal - Background Mean)/(Background Standard Deviation)"); print("Spectrum to Noise Ratio: "+ (spec_max-bgMean)/bgStd); print(" "); if (saveCalibratedSpectrumTable== true) print("Save Calibrated Spectrum Table"); if (showProcessSpectrum == true) print("Show Process Spectrum"); if (showSpectrumSurfacePlot == true)print("Show Spectrum Surface Plot"); if (showRedshiftElements == true)print("Show Redshft Elements"); print(" "); print(objectName,"Log End"); selectWindow("Log"); saveAs("Text", pathFileNameSave+"Log.txt"); // run("Close"); } // Macro End ******************************************************************************************************************