Commit 29ac5666 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

Baseline

parents
import sys
from itertools import islice
import mpi4py.MPI as MPI
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('Agg')
import scipy.io
#import xlrd
from scipy import ndimage
sys.path.append("/public/home/weichengliang/lnData/CSST_new_framwork/csstPSF_20210108")
import PSFConfig as myConfig
import PSFUtil as myUtil
NPSF = 900
##############################
##############################
##############################
def test_psfPlot(iccd, ipsf, psfPath):
plt.cla()
plt.close('all')
#psf质心位置检查,图像切片程序检查
fig = plt.figure(figsize=(4,16))
plt.subplots_adjust(wspace=0.1, hspace=0.1)
psfSet = []
psfSetX= []
for iwave in range(1, 5):
psfInfo = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=False)
psfSet.append(psfInfo)
psfInfo = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=True)
psfSetX.append(psfInfo)
ax = plt.subplot(4,1,iwave)
psfMat = psfSet[iwave-1]['psfMat']
pixsize = psfSet[iwave-1]['pixsize']*1e-3 #microns -> mm
print('psfMat-shape:', psfMat.shape)
npix = psfMat.shape[0]
pixCutEdge= int(npix/2-15)
plt.imshow((psfMat[pixCutEdge:npix-pixCutEdge, pixCutEdge:npix-pixCutEdge]), origin='lower')
plt.plot([npix/2-pixCutEdge, npix/2-pixCutEdge],[0, (npix/2-pixCutEdge)*2-1],'w--')
plt.plot([0, (npix/2-pixCutEdge)*2-1],[npix/2-pixCutEdge, npix/2-pixCutEdge],'w--')
imgX = psfSet[iwave-1]['image_x'] #in mm
imgY = psfSet[iwave-1]['image_y'] #in mm
#cenX = imgX +deltX
#cenY = imgY -deltY
deltX= psfSet[iwave-1]['centroid_x'] #in mm
deltY= psfSet[iwave-1]['centroid_y'] #in mm
cenPix_X = npix/2 + deltX/pixsize
cenPix_Y = npix/2 + deltY/pixsize
plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'rx', ms = 20)
deltX= psfSetX[iwave-1]['centroid_x'] #in mm
deltY= psfSetX[iwave-1]['centroid_y'] #in mm
cenPix_X = npix/2 + deltX/pixsize
cenPix_Y = npix/2 + deltY/pixsize
plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'bx', ms = 10, mew=2)
maxX = psfSet[iwave-1]['max_x']
maxY = psfSet[iwave-1]['max_y']
maxPix_X = npix/2 + maxX/pixsize
maxPix_Y = npix/2 + maxY/pixsize
plt.plot([maxPix_X-pixCutEdge],[maxPix_Y-pixCutEdge], 'r+', ms = 20)
img = psfMat/np.sum(psfMat)
y, x = ndimage.center_of_mass(img)
print(x, y)
print(cenPix_X, cenPix_Y)
plt.plot([x-pixCutEdge],[y-pixCutEdge], 'wx', ms = 5, mew=1)
plt.annotate('iccd={:}, iwave={:}, ipsf={:}'.format(iccd, iwave, ipsf), [0,(npix/2-pixCutEdge)*2-5], c='w', size=15)
plt.savefig('figs/psf_{:}_{:}.pdf'.format(iccd, ipsf))
print('psfSet has been loaded.')
print('Usage: psfSet[i][keys]')
print('psfSet.keys:', psfSet[0].keys())
##############################
##############################
##############################
if __name__=='__main__':
iccd = 2 #[1, 30]
iwave= 2 #[1, 4]
ipsf = 46 #[1, 100]
psfPath = '/data/simudata/CSSOSDataProductsSims/data/csstPSFdata/CSSOS_psf_20210108/CSST_psf_ciomp_2p5um_cycle3_ccr90'
iipsf = [1, 15, 30, 450, 465, 480, 870, 885, 900]
for iccd in range(1, 31):
for ipsf in iipsf:
test_psfPlot(iccd, ipsf, psfPath)
import sys
from itertools import islice
import mpi4py.MPI as MPI
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('Agg')
import scipy.io
#import xlrd
from scipy import ndimage
sys.path.append("/public/home/weichengliang/lnData/CSST_new_framwork/csstPSF_20210108")
import PSFConfig as myConfig
import PSFUtil as myUtil
NPSF = 900
##############################
##############################
##############################
def test_psfPlot(iccd, iwave, ipsf, psfPath, r50):
#psf质心位置检查,图像切片程序检查
plt.cla()
plt.close("all")
fig = plt.figure(figsize=(4,8))
plt.subplots_adjust(wspace=0.1, hspace=0.1)
#psfSet = []
#psfSetX= []
#for iwave in range(1, 5):
psfInfo = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=False)
#psfSet.append(psfInfo)
psfInfoX = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=True)
#psfSetX.append(psfInfo)
ax = plt.subplot(2,1,1)
psfMat = psfInfo['psfMat']
pixsize = psfInfo['pixsize']*1e-3 #microns -> mm
print('psfMat-shape:', psfMat.shape)
npix = psfMat.shape[0]
pixCutEdge= int(npix/2-15)
plt.imshow(np.log10(1e-6+psfMat[pixCutEdge:npix-pixCutEdge, pixCutEdge:npix-pixCutEdge]), origin='lower')
plt.plot([npix/2-pixCutEdge, npix/2-pixCutEdge],[0, (npix/2-pixCutEdge)*2-1],'w--')
plt.plot([0, (npix/2-pixCutEdge)*2-1],[npix/2-pixCutEdge, npix/2-pixCutEdge],'w--')
imgX = psfInfo['image_x'] #in mm
imgY = psfInfo['image_y'] #in mm
#cenX = imgX +deltX
#cenY = imgY -deltY
#deltX= psfSet[iwave-1]['centroid_x'] #in mm
#deltY= psfSet[iwave-1]['centroid_y'] #in mm
#cenPix_X = npix/2 + deltX/pixsize
#cenPix_Y = npix/2-1 + deltY/pixsize
#plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'rx', ms = 20)
deltX= psfInfoX['centroid_x'] #in mm
deltY= psfInfoX['centroid_y'] #in mm
cenPix_X = npix/2 + deltX/pixsize
cenPix_Y = npix/2 + deltY/pixsize
plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'bx', ms = 10, mew=2)
#maxX = psfSet[iwave-1]['max_x']
#maxY = psfSet[iwave-1]['max_y']
#maxPix_X = npix/2 + maxX/pixsize
#maxPix_Y = npix/2-1 + maxY/pixsize
#plt.plot([maxPix_X-pixCutEdge],[maxPix_Y-pixCutEdge], 'r+', ms = 20)
#img = psfMat/np.sum(psfMat)
#y, x = ndimage.center_of_mass(img)
#print(x, y)
#print(cenPix_X, cenPix_Y)
#plt.plot([x-pixCutEdge],[y-pixCutEdge], 'wx', ms = 5, mew=1)
plt.annotate('iccd={:}, iwave={:}, ipsf={:}'.format(iccd, iwave, ipsf), [0,(npix/2-pixCutEdge)*2-5], c='w', size=15)
ax = plt.subplot(2,1,2)
cenPix = [cenPix_X, cenPix_Y]
img = myUtil.psfTailor(psfMat, apSizeInArcsec=2*r50, psfSampleSizeInMicrons=2.5, cenPix=cenPix)
plt.imshow(np.log10(1e-6+img[pixCutEdge:npix-pixCutEdge, pixCutEdge:npix-pixCutEdge]), origin='lower')
plt.plot([npix/2-pixCutEdge, npix/2-pixCutEdge],[0, (npix/2-pixCutEdge)*2-1],'w--')
plt.plot([0, (npix/2-pixCutEdge)*2-1],[npix/2-pixCutEdge, npix/2-pixCutEdge],'w--')
plt.savefig('figs/psf_{:}_{:}_2r50_log.pdf'.format(iccd, ipsf))
#print('psfSet has been loaded.')
#print('Usage: psfSet[i][keys]')
#print('psfSet.keys:', psfSet[0].keys())
##############################
##############################
##############################
if __name__=='__main__':
iccd = 2 #[1, 30]
iwave= 2 #[1, 4]
ipsf = 46 #[1, 100]
psfPath = '/data/simudata/CSSOSDataProductsSims/data/csstPSFdata/CSSOS_psf_20210108/CSST_psf_ciomp_2p5um_cycle3'
REE50 = np.loadtxt('REE50_w{:}.txt'.format(iwave))
iipsf = [1, 15, 30, 450, 465, 480, 870, 885, 900]
for iccd in range(1, 31):
r50 = REE50[iccd-1]
print(r50)
for ipsf in iipsf:
test_psfPlot(iccd, iwave, ipsf, psfPath, r50)
import sys
from itertools import islice
import mpi4py.MPI as MPI
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('Agg')
import scipy.io
#import xlrd
from scipy import ndimage
sys.path.append("/public/home/weichengliang/lnData/CSST_new_framwork/csstPSF_20210108")
import PSFConfig as myConfig
import PSFUtil as myUtil
NPSF = 900
##############################
##############################
##############################
def test_psfPlot(iccd, ipsf, psfPath):
plt.cla()
plt.close('all')
#psf质心位置检查,图像切片程序检查
fig = plt.figure(figsize=(4,16))
plt.subplots_adjust(wspace=0.1, hspace=0.1)
psfSet = []
psfSetX= []
for iwave in range(1, 5):
psfInfo = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=False)
psfSet.append(psfInfo)
psfInfo = myConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True, PSFCentroidWgt=True)
psfSetX.append(psfInfo)
ax = plt.subplot(4,1,iwave)
psfMat = psfSetX[iwave-1]['psfMat']
pixsize = psfSet[iwave-1]['pixsize']*1e-3 #microns -> mm
print('psfMat-shape:', psfMat.shape)
npix = psfMat.shape[0]
pixCutEdge= int(npix/2-15)
plt.imshow((psfMat[pixCutEdge:npix-pixCutEdge, pixCutEdge:npix-pixCutEdge]), origin='lower')
plt.plot([npix/2-pixCutEdge, npix/2-pixCutEdge],[0, (npix/2-pixCutEdge)*2-1],'w--')
plt.plot([0, (npix/2-pixCutEdge)*2-1],[npix/2-pixCutEdge, npix/2-pixCutEdge],'w--')
imgX = psfSet[iwave-1]['image_x'] #in mm
imgY = psfSet[iwave-1]['image_y'] #in mm
#cenX = imgX +deltX
#cenY = imgY -deltY
deltX= psfSet[iwave-1]['centroid_x'] #in mm
deltY= psfSet[iwave-1]['centroid_y'] #in mm
cenPix_X = npix/2 + deltX/pixsize
cenPix_Y = npix/2 + deltY/pixsize
plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'rx', ms = 20)
deltX= psfSetX[iwave-1]['centroid_x'] #in mm
deltY= psfSetX[iwave-1]['centroid_y'] #in mm
cenPix_X = npix/2 + deltX/pixsize
cenPix_Y = npix/2 + deltY/pixsize
plt.plot([cenPix_X-pixCutEdge],[cenPix_Y-pixCutEdge], 'bx', ms = 10, mew=2)
maxX = psfSet[iwave-1]['max_x']
maxY = psfSet[iwave-1]['max_y']
maxPix_X = npix/2 + maxX/pixsize
maxPix_Y = npix/2 + maxY/pixsize
plt.plot([maxPix_X-pixCutEdge],[maxPix_Y-pixCutEdge], 'r+', ms = 20)
img = psfMat/np.sum(psfMat)
y, x = ndimage.center_of_mass(img)
print(x, y)
print(cenPix_X, cenPix_Y)
plt.plot([x-pixCutEdge],[y-pixCutEdge], 'wx', ms = 5, mew=1)
plt.annotate('iccd={:}, iwave={:}, ipsf={:}'.format(iccd, iwave, ipsf), [0,(npix/2-pixCutEdge)*2-5], c='w', size=15)
plt.savefig('figs/psf_{:}_{:}.pdf'.format(iccd, ipsf))
print('psfSet has been loaded.')
print('Usage: psfSet[i][keys]')
print('psfSet.keys:', psfSet[0].keys())
##############################
##############################
##############################
if __name__=='__main__':
iccd = 2 #[1, 30]
iwave= 2 #[1, 4]
ipsf = 46 #[1, 100]
psfPath = '/data/simudata/CSSOSDataProductsSims/data/csstPSFdata/CSSOS_psf_20210108/CSST_psf_ciomp_2p5um_cycle3_ccr90'
iipsf = [1, 15, 30, 450, 465, 480, 870, 885, 900]
for iccd in range(1, 31):
for ipsf in iipsf:
test_psfPlot(iccd, ipsf, psfPath)
长光psf采样说明:
10*10采样:
晓波:
1. 此次PSF采样采用理想像面,没有考虑加入光栅和滤光片的影响,PSF采样顺序按照约定好的CCD编号进行采样;
2. PSF采样对应的视场大小约为1.2平方度;
3. EXCEL表格中给出了每片CCD对应的PSF采样信息,field_X和field_Y对应物视场的视场角度,Image_x和Image_y对应此PSF质心在CCD上的坐标信息;
4. 每个PSF采样间距为5μm,采样数为180*180,因此PSF为边长900μm的正方形;
5. 每片CCD上都采10*10个PSF,采样顺序按照PPT图中所示的psf_1到psf_100依次进行采样。
班章:
1. EXCEL表格中给出了每片CCD对应的PSF采样信息,field_X和field_Y对应物视场的视场角度,centroid_x和centroid _y分别对应此PSF质心距离PSF采样图形几何中心的横向和纵向偏移量
2. centroid_x中负号表示质心向左偏移,正号表示质心向右偏移;centroid_y中负号表示质心向下偏移,正号表示质心向上偏移。单位是(mm)【wei, 全局坐标系,不是像素坐标系,需要注意+/-y的问题】
30*30采样:
from .PSFInterp import PSFInterp
\ No newline at end of file
#OPTS += -D
CC = gcc
OPTIMIZE = -fPIC -g -O3 #-Wall -wd981 #-wd1419 -wd810
#GSLI = -I/home/alex/opt/gsl/include
#GSLL = -L/home/alex/opt/gsl/lib -lgsl -lgslcblas
#FFTWI = -I/home/alex/opt/fftw/include
#FFTWL = -L/home/alex/opt/fftw/lib -lfftw3 -lfftw3f
#HDF5I = -I/home/alex/opt/hdf5/include
#HDF5L = -L/home/alex/opt/hdf5/lib -lhdf5_hl -lhdf5
#FITSI = -I/home/alex/opt/cfitsio/include
#FITSL = -L/home/alex/opt/cfitsio/lib -lcfitsio
#EXTRACFLAGS =
#EXTRACLIB =
CLINK=$(CC)
CFLAGS=$(OPTIMIZE) #$(EXTRACFLAGS) $(OPTS)
CLIB= -shared -lm #$(EXTRACLIB)
OBJS = PCA.o gasdev.o indexx.o nrutil.o svdcmp.o pythag.o ran1.o
EXEC = libPCA.so
all: $(EXEC)
$(EXEC): $(OBJS)
$(CLINK) $(CFLAGS) -o $@ $(OBJS) $(CLIB)
$(OBJS): nrutil.h Makefile
.PHONY : clean
clean:
rm -f *.o $(EXEC)
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "nrutil.h"
void PCA(float **star,int Nstar,int Mp,double **basef,double **coff);
void psfPCA(float *tstar, int tNstar, int tMp, double *tbasef, double *tcoff)
{
int i, j, k;
float **star;
double **basef;
double **coff;
fprintf(stdout, "libPCA.so: load libPCA for psf-Matrix-[%d, %d]\n", tNstar, tMp);
fflush(stdout);
star = matrix(0, tNstar-1, 0, tMp-1);
for(i=0; i<tNstar; i++)
for(j=0; j<tMp; j++)
{
k = j + i*tMp;
star[i][j] = tstar[k];
}
int Nstar, Mp;
Nstar = tNstar;
Mp = tMp;
basef= dmatrix(0, tNstar-1, 0, tMp-1);
coff = dmatrix(0, tNstar-1, 0, tNstar-1);
PCA(star, Nstar, Mp, basef, coff);
for(i=0; i<tNstar; i++)
for(j=0; j<tMp; j++)
{
k = j + i*tMp;
tbasef[k] = basef[i][j];
}
for(i=0; i<tNstar; i++)
for(j=0; j<tNstar; j++)
{
k = j + i*tNstar;
tcoff[k] = coff[i][j];
}
fprintf(stdout, "libPCA.so: psf-PCAs have been found!\n");
fflush(stdout);
}
void PCA(float **star,int Nstar,int Mp,double **basef,double **coff)
{
void svdcmp(double **a, int m, int n, double *w, double **v);
void indexx(int n, double arr[], int *indx);
double **a,**v,*w,*check;
int i,j,k,*indx;
if(Mp>=Nstar){
a=dmatrix(1,Mp,1,Nstar);
v=dmatrix(1,Nstar,1,Nstar);
w=dvector(1,Nstar);
indx=ivector(1,Nstar);
for(i=1;i<=Nstar;i++){for(j=1;j<=Mp;j++)a[j][i]=star[i-1][j-1];}
svdcmp(a,Mp,Nstar,w,v);
indexx(Nstar,w,indx);
for(j=1;j<=Nstar;j++){
k=indx[Nstar-j+1];
for(i=1;i<=Mp;i++)basef[j-1][i-1]=a[i][k];
}
for(i=1;i<=Nstar;i++){
for(j=1;j<=Nstar;j++){
k=indx[Nstar-j+1];
coff[i-1][j-1]= w[k]*v[i][k];
}
}
//for(j=1;j<=Nstar;j++){for(i=1;i<=Mp;i++)basef[j-1][i-1]=a[i][j];}
//for(i=1;i<=Nstar;i++){for(k=1;k<=Nstar;k++)coff[i-1][k-1]= w[k]*v[i][k];}
free_dmatrix(a,1,Mp,1,Nstar);
free_dmatrix(v,1,Nstar,1,Nstar);
free_dvector(w,1,Nstar);
free_ivector(indx,1,Nstar);
}
else{
a=dmatrix(1,Nstar,1,Mp);
v=dmatrix(1,Mp,1,Mp);
w=dvector(1,Mp);
indx=ivector(1,Mp);
for(i=1;i<=Nstar;i++){for(j=1;j<=Mp;j++)a[i][j]=star[i-1][j-1];}
svdcmp(a,Nstar,Mp,w,v);
indexx(Mp,w,indx);
for(j=1;j<=Mp;j++){
k=indx[Mp-j+1];
for(i=1;i<=Mp;i++)basef[j-1][i-1]=v[i][k];
}
for(i=1;i<=Nstar;i++){
for(j=1;j<=Mp;j++){
k=indx[Mp-j+1];
coff[i-1][j-1]= w[k]*a[i][k];
}
}
free_dmatrix(a,1,Nstar,1,Mp);
free_dmatrix(v,1,Mp,1,Mp);
free_dvector(w,1,Mp);
free_ivector(indx,1,Mp);
}
}
void PCA_err(float **err,int Nstar,int Mp,int nbf,double **basef,double **cofferr)
{
float gasdev(long *iseed);
long iseed=-1;
int nc=100,i,j,k,ns;
double sum,*mean,**coeffs,*start,*errt,det;
FILE *fp;
start=dvector(0,Mp);
mean=dvector(0,nbf);
coeffs=dmatrix(0,nc,0,nbf);
for(ns=0;ns<Nstar;ns++){
for(k=0;k<nbf;k++)mean[k]=0;
for(k=0;k<nc;k++){
for(j=0;j<Mp;j++)start[j]=gasdev(&iseed)*err[ns][j];
for(i=0;i<nbf;i++){
coeffs[k][i]=0;
for(j=0;j<Mp;j++)coeffs[k][i]+=start[j]*basef[i][j];
mean[i]+=coeffs[k][i];
}
}
for(k=0;k<nbf;k++)mean[k]/=nc;
for(i=0;i<nbf;i++){
sum=0;
for(k=0;k<nc;k++){
det=coeffs[k][i]-mean[i];
sum+=det*det;
}
cofferr[ns][i]=sqrt(sum/(nc-1.));
}
}
free_dvector(start,0,Mp);
free_dvector(mean,0,nbf);
free_dmatrix(coeffs,0,nc,0,nbf);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment