parts = [11, 12, 13, 14, 15] # parts = [0,1,2,3,4,5] # parts = [16,17,18,19,20] sim_ns = [4, 8, 16, 32, 64, 128] for p in parts: for sim_n in sim_ns: corr_path = f'{scorpy.DATADIR}/dbins/cxi/qcors/sim/{sim_n}/sim{sim_n}-alpha-p{p}-qcor.dbin' padf_path = f'{scorpy.DATADIR}/dbins/cxi/padfs/sim/{sim_n}/sim{sim_n}-alpha-p{p}-padf.dbin' print(f'!!!!#######{p=}, {sim_n=}') print(f'!!!!#######') print(f'!!!!#######') corr = scorpy.CorrelationVol(path=corr_path) padf = scorpy.PadfVol(nr=nr, npsi=npsi, rmax=rmax, nl=nl, wavelength=wavelength) padf.fill_from_corr(corr, theta0=False, verbose=99, tag=f'{part}_{sim_n}') padf.save(padf_path) print(f'!!!!#######') print(f'!!!!#######') # parts = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] # sim_ns = [256]
method = 'scat_pol' r = scorpy.utils.convert_q2r(qmax, clen, wavelength * 1e10) runs = [ 108, 113, 109, 125, 110, 123, 118, 112, 119, 120, 102, 104, 105, 103, 121, 126 ] #### SCORPY CORRELATION for run in runs: print(f'######Run {run}') pk = scorpy.PeakData(f'{scorpy.DATADIR}/cxi/run{run}_peaks.txt', qmax=qmax) corr = scorpy.CorrelationVol(nq=nq, npsi=npsi, qmax=qmax, cos_sample=False) corr.fill_from_peakdata(pk, method=method) corr.save(f'{scorpy.DATADIR}/dbins/cxi/qcors/{run}/run{run}-qcor.dbin') ### Seeded Half runs for seed in range(20): print(f'Run: {run}') print(f'Seed: {seed}.') frames = pk.split_frames() np.random.seed(seed) np.random.shuffle(frames) frames_a = frames[:int(len(frames) / 2)] frames_b = frames[int(len(frames) / 2):] corra = scorpy.CorrelationVol(nq, npsi, qmax, cos_sample=False)
#approx 40 mins for 100x100, 20 mins for 50x100, 7hrs for 2000x50 nbatches = 2000 nframes = 50 method = 'scat_sph' integrated = True corr2dfname = 'ortho-intenr-qmax15-2d-qcor.dbin' ######3D CORR if run_3d: cif = scorpy.CifData(path=f'{scorpy.DATADIR}/xtal/{ciffname}', qmax=qmax) corr3d = scorpy.CorrelationVol(qmax=qmax, nq=nq, npsi=npsi, cos_sample=cos_sample, inc_self_corr=inc_self_corr) corr3d.fill_from_cif(cif, verbose=2, method='scat_sph') corr3d.save(f'{scorpy.DATADIR}/dbins/{corr3dfname}') ######2D CORR if run_2d: corr2d = scorpy.CorrelationVol(nq=nq, npsi=npsi, qmax=qmax, cos_sample=cos_sample, inc_self_corr=inc_self_corr)
mask_corr_config.write(f'input = {scorpy.DATADIR}cxi/mask/mask_im.dbin\n') mask_corr_config.write(f'outpath = {scorpy.DATADIR}dbins/cxi/padfcorr/\n') mask_corr_config.write(f'wavelength = {wavelength}\n') mask_corr_config.write(f'pixel_width = {1/res}\n') mask_corr_config.write(f'detector_z = {clen}\n') mask_corr_config.write(f'nq = {nq}\n') mask_corr_config.write( f'nth = {npsi*2}\n' ) # padfcorr give theta from 0-360, so double ntheta so cut in half later mask_corr_config.write(f'tag = padfcorr_mask\n') mask_corr_config.write(f'qmax = {qmax*1e9}\n') mask_corr_config.close() os.system( f'{scorpy.PADFCORRDIR}padfcorr {scorpy.DATADIR}dbins/cxi/padfcorr/padfcorr_mask_config.txt' ) padfcorrvol = np.fromfile( f'{scorpy.DATADIR}dbins/cxi/padfcorr/padfcorr_mask_correlation.dbin') padfcorrvol = padfcorrvol.reshape((nq, nq, 2 * npsi)) corr = scorpy.CorrelationVol(nq, npsi, qmax, cos_sample=False) corr.vol = padfcorrvol[:, :, :npsi] corr.save(f'{scorpy.DATADIR}dbins/cxi/mask_qcor.dbin') # corr = scorpy.CorrelationVol(path=f'{scorpy.DATADIR}/cxi/mask/mask_qcor.dbin') corr.plot_q1q2(xlabel='$\\Delta\\Psi [rad]$', ylabel='$q$ [$\u212b^{-1}$]') plt.show()
# npixforthispeak = len(np.where(corr2d.vol[loc]>0)[0]) # corr2d_inte.vol[int(inds[0]), int(inds[1]), int(inds[2])] = s # s, loc = corr3d.integrate_region(point[0], point[1], point[2], inte_rq, inte_rq, inte_rt) # npixforthispeak = len(np.where(corr3d.vol[loc]>0)[0]) # corr3d_inte.vol[int(inds[0]), int(inds[1]), int(inds[2])] = s # corr3d_inte.save(f'{scorpy.DATADIR}/dbins/intenr/intenr-qmax0264-3d-inte-qcor.dbin') # corr2d_inte.save(f'{scorpy.DATADIR}/dbins/intenr/intenr-qmax0264-2d-inte-qcor.dbin') corr2d_inte = scorpy.CorrelationVol(path=f'{scorpy.DATADIR}/dbins/intenr/intenr-qmax0264-2d-inte-qcor.dbin') corr2d_inte.qpsi_correction() corr3d_inte = scorpy.CorrelationVol(path=f'{scorpy.DATADIR}/dbins/intenr/intenr-qmax0264-3d-inte-qcor.dbin') # corr2d_inte = scorpy.CorrelationVol(path=f'{scorpy.DATADIR}/dbins/inten1/inten1-qmax0264-2d-inte-qcor.dbin') # corr2d_inte.qpsi_correction() # corr3d_inte = scorpy.CorrelationVol(path=f'{scorpy.DATADIR}/dbins/inten1/inten1-qmax0264-3d-inte-qcor.dbin') loc = np.unique(np.where(corr3d_inte.vol >0)[0]) print(loc)
import scorpy import numpy as np import matplotlib.pyplot as plt plt.close('all') v1 = scorpy.CorrelationVol( 50, 90, 2, ) v1.vol = np.random.random(v1.vol.shape) v1.plot_q1q2() v1.save(scorpy.DATADIR / 'test.dbin') v2 = scorpy.CorrelationVol(path=scorpy.DATADIR / 'test.dbin') v2.plot_q1q2() plt.show()
# corr2.fill_from_cif(cif, method=method) # corr1.plot_q1q2() # corr2.plot_q1q2() method = 'scat_sph' geom = scorpy.ExpGeom(f'{scorpy.DATADIR}/geoms/plot-test.geom') pk = scorpy.PeakData(f'{scorpy.DATADIR}/patternsim/plot-test.h5', geo=geom, qmax=1) pk.plot_peaks() corr1 = scorpy.CorrelationVol(100, 180, 1, cos_sample=False, inc_self_corr=True) corr1.fill_from_peakdata(pk, method=method) corr2 = scorpy.CorrelationVol(100, 180, 1, cos_sample=False, inc_self_corr=False) corr2.fill_from_peakdata(pk, method=method) corr1.plot_q1q2() corr2.plot_q1q2() plt.show()
# print('Padfcorr') # os.system(f'{scorpy.PADFCORRDIR}padfcorr /tmp/padfcorr_tmp_config.txt') # tmppadfcorrvol = np.fromfile(f'/tmp/padfcorr_tmp_frame_correlation.dbin') # tmppadfcorrvol = tmppadfcorrvol.reshape((nq, nq, 2*npsi)) # pc_corr = scorpy.CorrelationVol(nq, npsi, qmax, cos_sample=False) # pc_corr.vol = tmppadfcorrvol[:,:, :npsi] # pc_corr.plot_sumax(0, log=True) # sc_corr.plot_sumax(0, log=True) # pc_corr.plot_q1q2( log=True) # sc_corr.plot_q1q2( log=True) pc_corr = scorpy.CorrelationVol( path=f'{scorpy.DATADIR}/dbins/cxi/run118_padfcorr_qcor.dbin') sc_corr = scorpy.CorrelationVol( path=f'{scorpy.DATADIR}/dbins/cxi/run118_qcor.dbin') pc_corr.plot_q1q2(log=True, title='Run 118 - PADFCORR - log10', xlabel='$\\Delta \\Psi$', ylabel='$q_1=q_2$') sc_corr.plot_q1q2(log=True, title='Run 118 - SCORPY - log10', xlabel='$\\Delta \\Psi$', ylabel='$q_1=q_2$') # pc_corr.plot_q1q2() # sc_corr.plot_q1q2() # pc_corr.plot_sumax(0, log=True)