def plot(cmap_file): full_map = xBinnedMap(cmap_file) fig = full_map.plot(show=False) # fig.show_circles(RA, DEC, RAD/60., lw=1) fig.show_circles(RA_CORE, DEC_CORE, RAD_PSF / 60.0, lw=1, color="white") fig.show_circles(RA_JET, DEC_JET, RAD_PSF / 60.0, lw=1, color="white") fig.recenter(RA + 0.003, DEC, 1 / 60.0) fig.show_colorscale(stretch="linear", cmap="afmhot", vmin=80, vmax=1500) fig.add_label(0.1, 0.9, "XIPE 2 Ms", relative=True, size="xx-large", color="white", horizontalalignment="left") image = xFITSImage(IMAGE_FITS_PATH, build_cdf=False) fig2 = image.plot(show=False) fig2.recenter(RA + 0.003, DEC, 1 / 60.0) fig2.show_colorscale(stretch="log", cmap="afmhot", vmin=2, vmax=200) fig2.add_label( 0.1, 0.9, "Chandra 39.5 ks", relative=True, size="xx-large", color="white", horizontalalignment="left" ) fig.show_contour(IMAGE_FITS_PATH, levels=[6, 10, 20, 50, 100], colors="green", smooth=3)
def plot(save=False): logger.info('Plotting stuff...') pipeline.xpbin(evt_file_path, algorithm='CMAP', outfile=map_file_path) regions = pyregion.open(reg_file_path) full_map = xBinnedMap(map_file_path) fig_all = full_map.plot(show=False) for i, region in enumerate(regions): ra, dec, rad = region.coord_list #fig_all.show_circles(ra, dec, rad, lw=1) fig = full_map.plot(show=False, subplot=(1, 2, 1)) plt.subplots_adjust(hspace=0.001) fig.show_circles(ra, dec, rad, lw=1) mcube_file_path = get_mcube_file_path(i) mcube = xBinnedModulationCube(mcube_file_path) mcube.plot(show=False, analyze=False, xsubplot=1) scale_x = rad/numpy.cos(numpy.deg2rad(dec)) # This is to take into account the effect of the projection. scale_y = rad for j,fit in enumerate(mcube.fit_results): angle = fit.phase angle_error = fit.phase_error degree = fit.polarization_degree #nangles=20 #for t in range(nangles): # dx = scale_x*numpy.cos(numpy.pi*2.0*t/float(nangles))#angle) # dy = scale_y*numpy.sin(numpy.pi*2.0*t/float(nangles))#angle) # fig.show_arrows(ra, dec, dx, dy, color='w', alpha=1, width=1,head_width=0, head_length=0) # pass dx = scale_x*numpy.cos(angle) dy = scale_y*numpy.sin(angle) dx1 = scale_x*degree*numpy.cos(angle+angle_error) dy1 = scale_y*degree*numpy.sin(angle+angle_error) dx2 = scale_x*degree*numpy.cos(angle-angle_error) dy2 = scale_y*degree*numpy.sin(angle-angle_error) fig.show_arrows(ra, dec, dx, dy, color=xpColor(j), alpha=1, linestyle='dashed', width=0.2,head_width=0, head_length=0) fig.show_arrows(ra, dec, -dx, -dy, color=xpColor(j), alpha=1, linestyle='dashed', width=0.2,head_width=0, head_length=0) fig.show_arrows(ra, dec, dx1, dy1, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig.show_arrows(ra, dec, -dx1, -dy1, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig.show_arrows(ra, dec, dx2, dy2, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig.show_arrows(ra, dec, -dx2, -dy2, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, dx, dy, color=xpColor(j), alpha=1, linestyle='dashed', width=0.2,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, -dx, -dy, color=xpColor(j), alpha=1, linestyle='dashed', width=0.2,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, dx1, dy1, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, -dx1, -dy1, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, dx2, dy2, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) fig_all.show_arrows(ra, dec, -dx2, -dy2, color=xpColor(j), alpha=1, width=1,head_width=0, head_length=0) if save: fig.save(mcube_file_path.replace('.fits', '.png')) plt.clf() else: plt.show() pass fig_all.save(os.path.join(XIMPOL_DATA, 'tycho_reg_all.png'))
def analyze(): """Analyze the data. """ logger.info('Opening output file %s...' % ANALYSIS_FILE_PATH) analysis_file = open(ANALYSIS_FILE_PATH, 'w') _nevents=[] for i, (_min, _max) in enumerate(zip(PHASE_BINNING[:-1], PHASE_BINNING[1:])): _nevents.append(fits.open(_sel_file_path(i))['EVENTS'].header['NAXIS2']) logger.info("PHASE BIN %d [%.1f-%.1f] - EVENTS = %d" %(i,_min,_max,_nevents[i])) pass out_phase=numpy.min(_nevents) for i, (_min, _max) in enumerate(zip(PHASE_BINNING[:-1], PHASE_BINNING[1:])): _mcube = xBinnedModulationCube(_mcube_file_path(i)) _mcube.fit() _fit_results = _mcube.fit_results[0] _phase = 0.5*(_min + _max) _phase_err = 0.5*(_max - _min) _pol_deg = _fit_results.polarization_degree _pol_deg_err = _fit_results.polarization_degree_error _pol_angle = _fit_results.phase _pol_angle_err = _fit_results.phase_error if (_nevents[i]-out_phase)>0: _factor=(_nevents[i])/(_nevents[i]-out_phase) print '------->',_nevents[i],out_phase,_nevents[i]-out_phase,_factor _pol_deg*=_factor _pol_deg_err*=_factor else: _pol_deg=1e-6 _pol_deg_err=1e-6 pass if _pol_deg>1.0: _pol_deg=1.0 #_total_px=_pol_deg*numpy.cos(_pol_angle) #_total_py=_pol_deg*numpy.sin(_pol_angle) #_nebula_px=0.157*numpy.cos(numpy.radians(161.1)) #_nebula_py=0.157*numpy.sin(numpy.radians(161.1)) #_pulsar_px=_total_px-_nebula_px #_pulsar_py=_total_py-_nebula_py #_pol_angle=numpy.arctan2(_pulsar_py,_pulsar_px) #_pol_deg=numpy.sqrt(_pulsar_px*_pulsar_px+_pulsar_py*_pulsar_py) if False: _spec_fitter = PIPELINE.xpxspec(_pha1_file_path(i), plot=False) (_index, _index_err), (_norm, _norm_err) = _spec_fitter.fit_parameters() # The division by the phase interval is a workaround and we should # keep track of that in xpselect. _norm /= (_max - _min) _norm_err /= (_max - _min) else: _norm=0.0 _norm_err=0.0 _index=0.0 _index_err=0.0 pass _data = (_phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle, _pol_angle_err, _index, _index_err, _norm, _norm_err) _fmt = ('%.4e ' * len(_data)).strip() _fmt = '%s\n' % _fmt _line = _fmt % _data analysis_file.write(_line) ### Plot the cmap with the arrow... full_map = xBinnedMap(_cmap_file_path(i)) full_map.image.vmin=0 full_map.image.vmax=10000 fig_map = full_map.plot(show=False) fig_map.show_circles(RA, DEC, RAD_ANA/60.0, lw=1) _plot_arrows(ra=RA,dec=DEC,rad=RAD_ANA/60., angle=_phase,angle_error=_phase_err, degree=_pol_deg,fig=fig_map,color='b') fig_map_file=_cmap_file_path(i).replace('.fits','.png') print 'saving map in...',fig_map_file fig_map.save(fig_map_file) ### analysis_file.close()
from matplotlib import rc rc('text', usetex=True) file_map='casa_cmap.fits' evt_file_path='casa.fits' file_selected_path='casa_sel.fits' file_selected_cube_path='casa_sel_mcube.fits' outfile=None for i,a in enumerate(sys.argv): if '-rad' in a: rad = float(sys.argv[i+1]) elif '-dec' in a: dec = float(sys.argv[i+1]) elif '-ra' in a: ra = float(sys.argv[i+1]) elif '-o' in a: outfile = sys.argv[i+1] pass fig=xBinnedMap(file_map).plot(show=False,subplot=(1,2,1))#,figure=fig) fig.show_circles(ra,dec,rad,lw=1) rad*=60 evtSelect=xEventSelect(evt_file_path, ra=ra, dec=dec, rad=rad, outfile=file_selected_path, emax=None, emin=None, mc=False, mcsrcid=[], phasemax=None, phasemin=None, phimax=None, phimin=None, tmax=None, tmin=None) evtSelect.select() evtBin=xEventBinningMCUBE(file_selected_path, ebins=1, outfile=file_selected_cube_path, evfile=file_selected_path, emax=10.0,nypix=256, ebinfile=None, phasebins=50,ebinalg='LIN', xref=None,phibins=75,nxpix=256,tbins=100,proj='TAN',tstart=None,tbinalg='LIN',algorithm='MCUBE',mc=False,binsz=2.5,yref=None,tbinfile=None,emin=1.0,tstop=None) evtBin.bin_() binModulation = xBinnedModulationCube(file_selected_cube_path) binModulation.plot(show=False,xsubplot=1) for fit in binModulation.fit_results: print fit
from matplotlib import rc rc('text', usetex=True) file_map = 'casa_cmap.fits' evt_file_path = 'casa.fits' file_selected_path = 'casa_sel.fits' file_selected_cube_path = 'casa_sel_mcube.fits' outfile = None for i, a in enumerate(sys.argv): if '-rad' in a: rad = float(sys.argv[i + 1]) elif '-dec' in a: dec = float(sys.argv[i + 1]) elif '-ra' in a: ra = float(sys.argv[i + 1]) elif '-o' in a: outfile = sys.argv[i + 1] pass fig = xBinnedMap(file_map).plot(show=False, subplot=(1, 2, 1)) #,figure=fig) fig.show_circles(ra, dec, rad, lw=1) rad *= 60 evtSelect = xEventSelect(evt_file_path, ra=ra, dec=dec, rad=rad, outfile=file_selected_path, emax=None, emin=None, mc=False, mcsrcid=[], phasemax=None, phasemin=None, phimax=None, phimin=None,