def VminusdIvar(Islicedata, Vslicedata, dispersion, alpha, f, B, col): """NAME: VminusdIvar PURPOSE: Returns noise of data INPUTS: Islicedata - The array of information for stokes I at a horizontal slice Vslicedata - The array of information for stokes V at a horizontal slice (is divided by I) dispersion - The number of angstroms/wavelength pixel alpha - Constant alpha returned by function Alpha above f - The value of the filling factor B - The value of the LOS B field n iron core region col - The col of the full disk image, from 0 to 2047 OUTPUTS: sigma - The noise to be plugged into the Generalized Posterior EXAMPLE: """ Iflux=np.array(v9s.LoadedDataSpectrum(Islicedata=Islicedata, slicedata=Islicedata, xpos=col)) #loads in array of stokes I intensities over wavelength for a spatial pixel Vflux=np.array(v9s.LoadedDataSpectrum(Islicedata=Islicedata, slicedata=Vslicedata, xpos=col)) #loads in array of stokes V intensities over wavelength for a spatial pixel Vcontinuum=Vflux[97:115] #picks out the wavelengths at which there is continuum Icontinuum=Iflux[97:115] #picks out the wavelengths at which there is continuum deriv=np.gradient(Icontinuum)/dispersion #the wavelength derivative of Intensity, calculated by chain rule: dI/dpixel * dpixel/dAngstrom dIvar=np.var(deriv) #variance of the derivative Vvar=np.var(Vcontinuum) #variance in V cov=np.cov((Vcontinuum,deriv))[0][1] #the covariance is a matrix, the terms on the opposite diagonal are the cross terms #var=Vvar+(alpha*f*B)**2.*dIvar-2.*(alpha*f*B)*cov #based on Var(X+Y)=Var(X)+Var(Y)-2*Cov(X,Y) - for Var(dI) the constants come out twice var=Vvar #simplest case sigma=np.sqrt(var) #noise/st. dev. is sqrt(variance) return sigma #in Asensios Sec. 3.1 on the left side middle paragraph: "variance of terms inside the parentheses"
def A1A2A3(Islicedata, Vslicedata, f, B, col, dispersion, alpha, ironloc): """NAME: A1A2A3 PURPOSE: Returns A1, A2, A3, N defined on page 3 of Asensios INPUTS: Islicedata - The array of information for stokes I at a horizontal slice Vslicedata - The array of information for stokes V at a horizontal slice (is divided by I) col - The col of the full disk image, from 0 to 2047 f - The value of the filling factor B - The value of the LOS B field dispersion - The number of angstroms/wavelength pixel alpha - Constant alpha returned by function Alpha above ironloc - Index of iron absorption core OUTPUTS: A1 - A1 is the sum of squared stokes V values in iron core region A2 - A2 is the sum of stokes V * derivative of I in iron core region A3 - A3 is the sum derivative of I squared in iron core region N - N is the number of wavelength pixels around the core region included EXAMPLE: """ Iflux=np.array(v9s.LoadedDataSpectrum(Islicedata=Islicedata, slicedata=Islicedata, xpos=col)) #loads in array of stokes I intensities over wavelength for a spatial pixel Vflux=np.array(v9s.LoadedDataSpectrum(Islicedata=Islicedata, slicedata=Vslicedata, xpos=col)) #loads in array of stokes V intensities over wavelength for a spatial pixel ironloc=np.int(ironloc) #the iron absorption core loc for the single pixel core=np.arange(ironloc-2, ironloc+3,1) #the indices of the region of the absorption line in the spectrum Icore=Iflux[core] #selects out the region of iron absorption in the spectrum Vcore=Vflux[core] #selects out the region of iron absorption in the spectrum gradI=np.gradient(Icore)/dispersion #dI/dlambda sigma=VminusdIvar(Islicedata=Islicedata,Vslicedata=Vslicedata,dispersion=dispersion,alpha=alpha,f=f,B=B,col=col) #calculate noise value A1=np.ndarray.sum(Vcore**2.)/(2.*sigma**2.) #as defined on page 3 of Asensios Ramos A2=np.ndarray.sum(Vcore*gradI)/(2.*sigma**2.) #as defined on page 3 of Asensios Ramos, but I keep alpha outside it A3=np.ndarray.sum(gradI**2.)/(2.*sigma**2.) #as defined on page 3 of Asensios Ramos, but I keep alpha outside it N=len(core) #number of wavelength pixels included in summation return A1, A2, A3, N
def PixelIndices(slicedata, array, row, col, line='Iron'): """NAME: PixelIndices PURPOSE: Assigns the value to the element of the array of index locations for a pixel. INPUTS: slicedata - The array of intensities for a horizontal slice of the sun. array - The array which will hold the index information. row - The row which is being operated upon. col - The column which is being operated upon. line - The absorption line to look at: Calcium or Oxygen OUTPUTS: N/A - Only reassigns the value of the array element. EXAMPLE: In [6]: datapath='k4v9s160517t213238_oid114635206372132_cleaned' disk=fits.getdata('/Users/jhamer/Research/Output/k4v9s160517t213238/FullDiskPlots /k4v9s160517t213238_oid114635206372132_cleanedI80fulldisk.fits') stokesslice=v9s.SingleStokes(datapath, 'I', slicenumber=400) indexmap=np.zeros((len(disk), len(disk))) CL.PixelIndices(stokesslice, indexmap, 400, 700) polyminloc=CL.PolyMinLoc(flux, xs) In [7]: indexmap[400][700] Out[7]: 61.789999999999999 """ flux = v9s.LoadedDataSpectrum(Islicedata=slicedata, slicedata=slicedata, xpos=col) if line == 'Iron': xs = IronCoreRegion(flux) elif line == 'Oxygen1': xs = Oxygen1CoreRegion(flux) elif line == 'Oxygen2': xs = Oxygen2CoreRegion(flux) loc = PolyMinLoc(flux, xs) array[row][col] = loc