#! /usr/bin/python
# coding: latin-1

import string, os, math
from html_elements import *
Content = []
Rows=0

def gnuplot_imaging(Gnuplot,Picture_abs,Table_abs,i,Tau,DIT,SN_DIT):
	Gnuplot_write = open(Gnuplot, 'w')
	Gnuplot_write.write("set output '"+Picture_abs+"'\n")
	Gnuplot_write.write("set term png\n")
	Gnuplot_write.write("set style data lines\n")
	Gnuplot_write.write("set xlabel 'exposure time [sec]'\n")
	Gnuplot_write.write("set ylabel 'SNR'\n")
	Temp=math.sqrt((i + 1.5*Tau/20.)/DIT)*SN_DIT
	Gnuplot_write.write("set yrange[*:%s]\n" % Temp)
	Gnuplot_write.write("plot '" + Table_abs + "' using ($1):($2) notitle")
	#Gnuplot_write.write("title 'LUCI-ETC SNR'\n")
	Gnuplot_write.close()
	String="gnuplot "+Gnuplot
	os.system(String)

def gnuplot_spectrum(Gnuplot,Picture_abs,Table_abs,Wavelength_start,Wavelength_end,Wavelength_step,Pixel,Pixel_shift):
	Gnuplot_write = open(Gnuplot, 'w')
	Gnuplot_write.write("set output '"+Picture_abs+"'\n")
	Gnuplot_write.write("set term png\n")
	Gnuplot_write.write("set style data lines\n")
	Gnuplot_write.write("set xlabel 'Pixel'\n")
	Gnuplot_write.write("set x2label 'wavelength [micron]'\n")
	Gnuplot_write.write("set ylabel 'SNR (total exposure time)'\n")
	Gnuplot_write.write("set x2tics\n")
	Gnuplot_write.write("set x2tics 0,"+str(Wavelength_step)+"\n")
	Gnuplot_write.write("set x2range["+str(Wavelength_start)+":"+str(Wavelength_end)+"]\n")
	Gnuplot_write.write("set xtics nomirror\n")
	Gnuplot_write.write("set xrange[%s:%s]\n" % (-Pixel_shift,Pixel + Pixel_shift))
	Gnuplot_write.write("set yrange[0:*]\n")
	Gnuplot_write.write("plot '" + Table_abs + "' using ($3):($2) notitle\n")
	Gnuplot_write.close()
	String="gnuplot "+Gnuplot
	os.system(String)

def mathplotlib_imaging(Picture_abs,Table_abs,Header):
	import numpy as np
	import matplotlib
	matplotlib.use('Agg')
	import matplotlib.pyplot as plt
	
	Data = np.genfromtxt(Table_abs, names = "x, y", skip_header=Header)
	fig = plt.figure()
	ax = fig.add_subplot(111)
	ax.plot(Data['x'], Data['y'], color='r')
	plt.xlabel('exposure time [sec]')
	plt.ylabel('SNR')
	fig.savefig(Picture_abs)

def mathplotlib_spetrum(Picture_abs,Table_abs,Wavelength_start,Wavelength_end,Wavelength_step,Pixel,Pixel_shift,Header):
	import numpy as np
	import matplotlib
	matplotlib.use('Agg')
	import matplotlib.pyplot as plt
	Data = np.genfromtxt(Table_abs, names="x2, y, x1", skip_header=Header, usecols=(0,1,2))
	fig, ax1 = plt.subplots()
	ax1.plot(Data['x1'], Data['y'], color='r')
	plt.xlim((-Pixel_shift,Pixel + Pixel_shift))
	ax1.set_xlabel('Pixel')
	plt.ylabel('SNR (total exposure time)')
	
	ax2 = ax1.twiny()
	ax2.plot(Data['x2'], Data['y'], color='r')
	ax2.set_xlim((Wavelength_start,Wavelength_end))
	ax2.set_xlabel('wavelength [micron]')
	fig.savefig(Picture_abs)
	
def header_fill(Filename,Header):
	with open(Filename,"r") as Temp:
		Data = Temp.readlines()
	for i in range(len(Data)+1,Header):
		with open(Filename,"a") as Temp:
			Temp.write("\n")
	


def output_header(Web, Title, Error,Output):
	if Web < 2:
		#------------------------------------web output-------------------------------------
		Rows=0
		header(Title, Output["css"])
		body()
		headline(Title, '1')
		headline("Based on a Gauss-function", '5')
		hline('100%', "left", 4)
#		body()
	else:
		#--------------------------------monitor output-------------------------------------
		print
		print
		print Title
	if Error == 0:
		Table_write=open(Output['abs']+"table.csv",'w')
		Table_write.write(Title+"\n")
		Table_write.write("\n")
		Table_write.close()


def output_summary(Web, Source, Object_choice, Filter_mag, Object_brightness_choice, Detector, Hawaii_conditions, Filter_choice, Camera_choice, Slit_width, Dispersion_choice, Water_vapor, Airmass, Background_choice, Sky_brightness, Strehl, Seeing, Central_wavelength, Lpmm, SN, DIT, Tau, Scale, Mode, Error,Output):
	
	if Web < 2:
		#------------------------------------web output-------------------------------------
		Rows=0
		headline_left("headline_object", "Object characteristics")
		headline_right("headline_hardware", "Hardware characteristics")
		par("object_left")
		print "Source geometry:"
		newline()
		print "Source type:"
		newline()
		if Object_choice[0] == 'b' or Object_choice[0] == 't':
			print "Source magnitude (%s-filter):" % Filter_mag
			newline()
		if Object_choice[0] == "b":
			print "Temperature:"
			newline()
		if Object_choice[0] <> 'b' and Object_choice[0] <> 't':
			print "Line wavelength:"
			newline()
			print "Line flux:"
			newline()
			print "Line width:"
			newline()
		coda_par()
		par("object_right")
		emph(Source)
		newline()
		if Object_choice[0] == "t":
			emph("Template spectrum, ")
			emph(Object_choice[1])
			if Object_choice[1].find('galaxy') <> -1:
				emph(", z= ")
				emph(Object_choice[2])
			newline()
		if Object_choice[0] == "b":
			emph("Blackbody")
			newline()
		if Object_choice[0] == "b" or Object_choice[0] == 't':
			emph(str(Object_brightness_choice)+" mag")
			newline()
		if Object_choice[0] == "b":
			emph(Object_choice[1]+" K")
			newline()
		if Object_choice[0] <> 'b' and Object_choice[0] <> 't':
			emph("Single line")
			newline()
			emph(Object_choice[0]+' micron')
			newline()
			emph(Object_choice[1]+' erg/s/cm&sup2')
			newline()
			emph(Object_choice[2]+' &Aring')
			newline()
		par("hardware_left")
		print "LUCI No.:"
		newline()
		if Error == 0:
			print "Detector full well:"
			newline()
			print "Detector Readout Noise:"
			newline()
		print "Filter:"
		newline()
		print "Camera:"
		newline()
		if (Mode%2)==0:
			print "Slit width:"
			newline()
			print "Central Wavelength of the grating unit:"
			newline()
			print "Number of lines per milimeter:"
			newline()	
			print "Dispersion:"
			newline()	
		print "Plate scale:"
		newline()

		coda_par()
		par("hardware_right")
		emph(Detector)
		newline()
		if Error == 0:
			emph("%.0f e-" % (Hawaii_conditions['Fullwell_%d' % int(Detector)]))
			newline()
			emph("%.0f e- rms" % (Hawaii_conditions['RON_%d' % int(Detector)]))
			newline()
		emph(Filter_choice)
		newline()
		emph(Camera_choice)
		newline()
		if (Mode%2)==0:
			emph(str(Slit_width)+' arcsec')
			newline()
			emph(str(Central_wavelength)+' micron')
			newline()
			emph(str(Lpmm)+' l/mm')
			newline()
			String = "%4.2f" % (Dispersion_choice*10000.)
			emph(String+'  &Aring/pixel')
			#print  "%4.2f &Aring/pixel" % (Dispersion_choice*10000.)
			newline()
		emph(str(Scale)+' arcsec/pixel')
		newline()
			
		coda_par()
		par("clear")		
		coda_par()
		
		hline('80%', "center", 2)
		
		headline_left("headline_atmosphere","Atmospheric conditions")
		headline_right("headline_exposure","Parameters of exposure")
		par("atmosphere_left")
		print "Water vapor:"
		newline()
		print "Airmass:"
		newline()
		if Background_choice=="0":
			print "Sky brightness:"
			newline()
		elif Sky_brightness==-27:
			print "Sky background:"
			newline()
		elif Sky_brightness==-17:
			print "Sky background:"
			newline()
		print "Seeing:"
		newline()
		if Strehl<>'-1':
			print "Strehl:"
			newline()
		coda_par()
		
		par("atmosphere_right")
		emph(str(Water_vapor)+' mm')
		newline()
		emph(str(Airmass))
		newline()
		if Background_choice=="0":
			emph(str(Sky_brightness)+' mag')
			newline()
		elif Sky_brightness==-27:
			emph("File")
			newline()
		elif Sky_brightness==-17:
			emph("Theoretical")
			newline()
		emph(str(Seeing)+" arcsec")
		newline()
		if Strehl<>'-1':
			emph(str(Strehl))
			newline()
		coda_par()
		
		par("exposure_left")
		print "DIT: "
		newline()
		if (Mode==1) or (Mode==3):
			print "SNR:"
			newline()
		else:
			print "Total exposure time:"
			newline()
		coda_par()
		par("exposure_right")
		emph(str(DIT)+' sec')
		newline()
		if (Mode==1) or (Mode==3):
			try:
				String = "%.1f" % SN
			except:
				String = SN
			emph(String)
			newline()
		else:
			emph(str(Tau)+" sec")
			newline()
		coda_par()
		par("clear")
		coda_par()


	else:
		#---------------------Monitor output-------------------------------
		
		print "Source geometry:", Source
		if Object_choice[0] =="t":
			print "Source type: Template spectrum,",Object_choice[1]
			if "galaxy" in Object_choice[1]:
				print "Redshift: ",Object_choice[2]
		if Object_choice[0] =="b":
			print "Source type: Blackbody, ", Object_choice[1],"K"
		if Object_choice[0] <> 'b' and Object_choice[0] <> 't':
			if Error == 0:
				print "Single line"
				print "Line_wavelength:", Object_choice[0],"micron"
				print "Line_flux:", Object_choice[1],"erg/s/cm^2"
				print "Line_width:", Object_choice[2],"A"
			else:
				if Object_choice[1] == "-1":
					print Object_choice[0]
		else:
			print "Source magnitude (%s-filter): %.2f mag" % (Filter_mag, Object_brightness_choice)
		print "LUCI No.:", Detector
		print "Filter of LUCI:", Filter_choice
		print "Camera:", Camera_choice
		if (Mode % 2) == 0:
			print "Slit width:", Slit_width,"arcsec"
			print "Central Wavelength of the grating unit:", Central_wavelength,"micron"
			print "Number of lines per milimeter:", Lpmm,"l/mm"
			print "Plate scale:", Scale,"arcsec/pixel"
		print "Water vapour:", Water_vapor,"mm"
		print "Airmass:", Airmass
		if Background_choice =="0":
			print "Sky brightness:", Sky_brightness,"mag"
		elif Sky_brightness==-27:
			print "Sky background: File"
		elif Sky_brightness==-17:
			print "Sky background: Theoretical"
		if Strehl<>'-1':
			print "Strehl:", Strehl
		print "Seeing:", Seeing,"arcsec"
		print "DIT:", DIT
		if Mode==1 or Mode==3:
			try:
				print "SNR: %.2f\n" % SN
			except:
				print "SNR: %s\n" % SN
		else:
			try:
				print "Total exposure time: %.2f\n" % Tau
			except:
				print "Total exposure time: %s\n" % Tau
			

	#---------------------File output-----------------------------------
	if Error == 0:
		Table_write=open(Output['abs']+'table.csv','a')
		Table_write.write("Source geometry: "+Source+"\n")
		if Object_choice[0] =="t":
			Table_write.write("Source type: Template spectrum, "+Object_choice[1]+"\n")
		if Object_choice[0] =="b":
			Table_write.write("Blackbody"+"\n")
			Table_write.write("Blackbody Temperature: "+Object_choice[1]+" K\n")
		if Object_choice[0] <> 'b' and Object_choice[0] <> 't':
			Table_write.write("Single line"+"\n")
			Table_write.write("Line_wavelength: "+Object_choice[0]+" micron\n")
			Table_write.write("Line_flux: "+Object_choice[1]+" erg/s/cm^2\n")
			Table_write.write("Line_width: "+Object_choice[2]+" A")
		else:
			Table_write.write("Source magnitude (%s-filter): %.2f mag\n" % (Filter_mag, Object_brightness_choice))
		Table_write.write("LUCI No.: %s\n" % Detector)
		Table_write.write("Filter used in LUCI: "+Filter_choice+"\n")
		Table_write.write("Camera: "+Camera_choice+"\n")
		if (Mode % 2) == 0:
			Table_write.write("Slit width: %s arcsec\n" % Slit_width)
			Table_write.write("Central Wavelength of the grating unit: %.2f micron\n" % Central_wavelength)
			Table_write.write("Number of lines per milimeter: %s l/mm\n"  % Lpmm)
			Table_write.write("Plate scale: %.2f arcsec/pixel\n" % Scale)
		Table_write.write("Water vapor: %.1f mm\n" % Water_vapor)
		Table_write.write("Airmass: %.2f\n" % Airmass)
		if Background_choice =="0":
			Table_write.write("Sky brightness: %.1f mag\n" % Sky_brightness)
		elif Sky_brightness==-27:
			Table_write.write("Sky background: File\n")
		elif Sky_brightness==-17:
			Table_write.write("Sky background: Theoretical\n")
		if Strehl<>'-1':
			Table_write.write("Strehl: %.2f\n" % Strehl)
		Table_write.write("Seeing: %.2f arcsec\n" % Seeing)
		Table_write.write("DIT: %.2e sec\n" % DIT)
		if (Mode==1) or (Mode==3):
			Table_write.write("SNR: %.2f\n\n" % SN)
		else:
			Table_write.write("Total exposure time: %.2e sec\n\n" % Tau)
		Table_write.close()

def output_imaging(Web, Source, Detector, Hawaii_conditions, Photons_object_tau, Photons_sky_tau, Center_pixel_tau, SN, SN_center_tau, DIT, SN_DIT, Tau, Mode, N_pix, Seeing, Debug, Photons_cali,Output):
	
	if Web < 2:
# --------------------------- web output ---------------------	
		Table_web = Output["web"] + "table.csv"
		Table_abs = Output["abs"] + "table.csv"
		Picture_web = Output["web"] + "plot.png"
		Picture_abs = Output["abs"] + "plot.png"
		Gnuplot = Output["abs"] + "plot.plt"
		Output["help_web"] = Output["help_web"] + "index.html"
		hline("80%","center",2)
		headline("Calculated values", "2")
		par("five")
		coda_par()
		
		par("output_left")
		if (Mode==1) or (Mode==3):
			print "Exposure time:"
		else:
			print "SNR:"
		newline()
		print "Total object flux:"
		newline()
		print "Total sky flux:"
		newline()
		print "Electrons from object+sky inside the central pixel:"
		newline()
		print "Electrons from object+sky inside the central pixel per DIT:"
		newline()
		print "Sky background:"
		if Debug == 2:
			newline()
			print "Total flux from the object:"
		coda_par()
		
		par("output_right")
		########### Exposure time or SNR ###################################
		if (Mode==1) or (Mode==3):
			Temp = "%.2f" % Tau
			emph(Temp+' sec')
		else:
			Temp = "%.2f" % SN
			emph(Temp)
		newline()
		############ total object flux #####################################
		Temp = "%.2f" % Photons_object_tau
		if Source == "Point source":
			emph(Temp+' e-')
		else:
			emph(Temp+' e-/pixel')
		newline()
		############ total sky flux ########################################
		Temp = Photons_sky_tau*N_pix
		if Source == "Point source":
			emph('%0.2f e-' % Temp)
		else:
			emph('%0.2f e-/pixel' % Temp)
		newline()
		#### Electrons from object+sky inside the central pixel ############
		Temp1 = Center_pixel_tau + Photons_sky_tau
		Temp = "%.2f e-" % (Temp1)
		emph(Temp)
		newline()
		#### Electrons from object+sky inside the central pixel per DIT ####
		Temp = 'Fullwell_%s' % Detector
		Temp = Hawaii_conditions[Temp]
		Temp4 = 'Linearity_start_%s' % Detector
		Temp2 = Hawaii_conditions[Temp4]
		Temp4 = 'Linearity_end_%s' % Detector
		Temp3 = Hawaii_conditions[Temp4]
		Temp1 = ((Center_pixel_tau + Photons_sky_tau) / Tau * DIT)
		if Temp1 > Temp:
			Temp1 = "%.2f e-/DIT" % ((Center_pixel_tau + Photons_sky_tau) / Tau * DIT)
			Temp = "%s <font color=red>!! saturated !!</font>" % (Temp1)
		elif Temp1 > Temp*Temp3 or Temp1 < Temp*Temp2:
			Temp1 = "%.2f e-/DIT" % ((Center_pixel_tau + Photons_sky_tau) / Tau * DIT)
			Temp = "%s <font color=red>!! Linearity is not within 5%% !!</font>" % (Temp1)
		else:
			Temp1 = "%.2f e-/DIT" % ((Center_pixel_tau + Photons_sky_tau) / Tau * DIT)
			Temp = Temp1
		emph(Temp)
		newline()
		########### Sky background #########################################
		Temp = "%.2f e-/pix/DIT" % (Photons_sky_tau/Tau*DIT)
		emph(Temp)
		if Debug == 2:
			newline()
			Temp = "%.2f e-/sec" % (Photons_cali)
			emph(Temp)
		coda_par()
		par("clear")
		coda_par()
		
	else:
# -------------------------- monitor output --------------------
		Table_abs = "table.csv"
		Picture_abs = "plot.png"
		Gnuplot = "plot.plt"
		try:
			print "Total number of electrons from source: %.2e e-" % Photons_object_tau
		except:
			print "Total number of electrons from source: %s e-" % Photons_object_tau
		if Mode==1 or Mode==3:
			try:
				print "Exposure time: %.2e sec" % Tau
			except:
				print "Exposure time: %s sec" % Tau
		else:
			try:
				print "SNR: %.2e" % SN
			except:
				print "SNR: %s" % SN
		try:
			print "Electrons from object+sky inside the central pixel: %.2e e-" % (Center_pixel_tau + Photons_sky_tau)
			print "SNR for the central pixel: %.2e" % SN_center_tau
			print "Background: %.2e e-/pixel/sec" % (Photons_sky_tau/Tau)
		except:
			print "Electrons from object+sky inside the central pixel: %s e-" % (Center_pixel_tau + Photons_sky_tau)
			print "SNR for the central pixel: %s" % SN_center_tau
			print "Background: %s e-/pixel/sec" % (Photons_sky_tau/Tau)
		if Debug == 2:
			try:
				print "Total flux from the object: %.2e e-/sec" % (Photons_cali)
			except:
				print "Total flux from the object: %s e-/sec" % (Photons_cali)
# -------------------------- file output -----------------------
	if Debug != 2:
		with open(Output['abs']+"table.csv",'a') as Table_write:
			Temp =  "Total number of electrons from source: %.2f e-\n" % Photons_object_tau
			Table_write.write(Temp)
			if (Mode==1) or (Mode==3):
				Temp =  "Exposure time: %.2f sec\n" % Tau
			else:
				Temp = "SNR: %.2f\n" % SN
			Table_write.write(Temp)
			Temp =  "Electrons from object+sky inside the central pixel: %.2e e-\n" % (Center_pixel_tau + Photons_sky_tau)
			Table_write.write(Temp)
			Temp =  "SNR for the central pixel: %.2f\n" % SN_center_tau
			Table_write.write(Temp)
			Temp =  "Background: %.2f e-/pixel/sec\n" % (Photons_sky_tau/Tau)
			Table_write.write(Temp)
		header_fill(Output['abs']+"table.csv",int(Output["header"]))
		with open(Output['abs']+"table.csv",'a') as Table_write:
			Temp = "exposure time / sec\tSNR\n"
			Table_write.write(Temp)
			i = 0.25*Tau
			while i <= 1.75*Tau:
				#print i, SN[i]
				String="%.2e\t%.7f\n" % (i, math.sqrt(i/DIT)*SN_DIT)
				Table_write.write(String)
				i = i + 1.5*Tau/20.
		if Output["figure"] == "gnuplot":
			gnuplot_imaging(Output['abs']+"plot.plt",Output['abs']+"plot.png",Output['abs']+"table.csv",i,Tau,DIT,SN_DIT)
		elif Output["figure"] == "matplotlib":
			mathplotlib_imaging(Output['abs']+"plot.png",Output['abs']+"table.csv",int(Output['header']))
		
		if Web < 2:
			par("center")
			print "The SNR is calculated over %d pixels in the PSF area including  93.8 &#37 of the total flux." % (N_pix + 0.5)
			coda_par()
			headline ('Signal-To-Noise plot', "1")
			image(Picture_web)
			par("clear")
			coda_par()
			par("ascii")
			link(Table_web, "ASCII-file")
	#		coda_par()

def output_spectrum(Web, Detector, Hawaii_conditions, SN, Photons_object_dit, Photons_sky_dit, Dispersion_choice, N_pix, Central_wavelength, DIT, Tau, Photons_max_dit,Output):
	Wavelength_start = 0.0
	Wavelength_end = 0.0
	Pixel = Hawaii_conditions["Number_of_pixel_w_"+Detector]
	Wavelength_shift = float(Output["wavelength_shift"])
	Pixel_shift = Wavelength_shift / Dispersion_choice
	header_fill(Output['abs']+'table.csv',int(Output['header']))
	with open(Output['abs']+"table.csv",'a') as Table_write:
		Liste=SN.keys()
		Liste.sort()
		Photons_sky_max = 0.0
		Table_write.write("WL/micron\tSN\tPixel\n")
		for i in Liste:
			j =  int((string.atof(i)-Central_wavelength+Dispersion_choice*Pixel/2.)/Dispersion_choice+0.5)
			if j > (-1.)*Pixel_shift and j < Pixel + Pixel_shift:
				if Photons_sky_max < Photons_sky_dit[i] and j > 0 and j < Pixel:
					Photons_sky_max = Photons_sky_dit[i]
					Wavelength_sky_max = string.atof(i)
			String="%s\t%.4f\t%d\n" % (i, SN[i],j)
			Table_write.write(String)
			if j == Pixel / 2.:
				Photons_object_cw = Photons_object_dit[i]#/DIT*Tau
				Photons_sky_cw = Photons_sky_dit[i]#/DIT*Tau
				SN_cw = SN[i]
	Photons_max_dit = Photons_max_dit + Photons_sky_max
	Wavelength_start = (-1.)*Dispersion_choice*(Pixel_shift + Pixel / 2.)+Central_wavelength
	Wavelength_end = Dispersion_choice*(Pixel_shift + Pixel / 2.)+Central_wavelength
	Wavelength_step = (string.atof(Wavelength_end) - string.atof(Wavelength_start)) / 5.
	
	if Output["figure"] == "gnuplot":
		gnuplot_spectrum(Output['abs']+"plot.plt",Output['abs']+"plot.png",Output['abs']+"table.csv",Wavelength_start,Wavelength_end,Wavelength_step,Pixel,Pixel_shift)
	elif  Output["figure"] == "matplotlib":
		mathplotlib_spetrum(Output['abs']+"plot.png",Output['abs']+"table.csv",Wavelength_start,Wavelength_end,Wavelength_step,Pixel,Pixel_shift,int(Output['header']))
	
	if Web < 2:
		hline("80%","center",2)
		headline("Calculated values", "2")
		par("five")
		coda_par()
		par("output_left")
		print "Object signal at %4.2f micron:" % Central_wavelength
		newline()
		print "SNR at %4.2f micron:" % Central_wavelength
		newline()
		print "Maximum count rate from object + sky:"
		newline()
		print "Maximum sky level at %4.4f micron:" % Wavelength_sky_max
		coda_par()
		
		par("output_right")
		print "%3.2f e-/DIT" % (Photons_object_cw)
		newline()
		print "%3.2f" % (SN_cw)
		newline()
		print "%3.2f e-/DIT/pix" % (Photons_max_dit)
		newline()
		print "%3.2f e-/DIT/pix" % (Photons_sky_max)
		coda_par()
		
		par("center")
		Temp = 'Fullwell_%s' % Detector
		Temp = Hawaii_conditions[Temp]
		#Temp1 = (Photons_object_cw + Photons_sky_cw)
		Temp1 = Photons_max_dit
		if Temp1 > Temp:
			Temp = "<font color=red>!! saturated !!</font>"
			emph(Temp)
		coda_par()
		
		par("center")
		print "The SNR and the object signal is calculated for one pixel in dispersion direction and %d pixel in spatial direction." % (N_pix + 0.5)
		coda_par()
		headline ('Signal-To-Noise plot', "1")
		image(Output['web']+"plot.png")
		par("ascii")
		link(Output['web']+"table.csv", "ASCII-file")
	else:
		print "Object signal at %4.2f micron: %3.2f e-/DIT" % (Central_wavelength, Photons_object_cw)
		print "SNR at %4.2f micron: %3.2f" % (Central_wavelength, SN_cw)
		print "Maximum count rate from object + sky: %3.2f e-/DIT/pix" % (Photons_max_dit)
		print "Maximum sky level at %4.4f micron: %3.2f e-/DIT/pix" % (Wavelength_sky_max, Photons_sky_max)
		Temp = 'Fullwell_%s' % Detector
		Temp = Hawaii_conditions[Temp]
		Temp1 = Photons_max_dit
		if Temp1 > Temp:
			print "!! saturated !!"
		print "The SNR and the object signal is calculated for one pixel in dispersion direction and %d pixel in spatial direction." % (N_pix + 0.5)
