def get_centroid(evt_file: str, reg_file: str, fmt: str, **kwargs) -> Union[PointPhys, PointCel]: """ Return the centroid of a region :param img_file: Path to the events file :param reg_file: Path to the region file in CIAO/PHYS format :param fmt: Should be either of "phys" or "cel" to return the coordinates in physical detector or WCS, respectively ... :raises ValueError: Raised when an invalid format is specified ... :rtype: PointPhys or PointCel """ if fmt not in ('phys', 'cel'): raise ValueError("fmt must be one of phys or cel") dmstat.punlearn() dmstat(f"{evt_file}[sky=region({reg_file})][cols sky]") vals = [float(x) for x in dmstat.out_mean.split(",")] if fmt == 'phys': return PointPhys(*vals) else: dmcoords.punlear() dmcoords(evt_file, option="sky", x=vals[0], y=vals[1], celfmt="deg") return PointCel(dmcoords.ra, dmcoords.dec)
def getPixelCoords(dataPath, evt2, posArray, asol1): #sPos, mPos, bPos): outArray = [] for position in posArray: rt.dmcoords(evt2, asolfile=asol1, ra=position[0], dec=position[1], option='cel', verbose=1) pix = [rt.dmcoords.x, rt.dmcoords.y] print(" pix " + str(pix[0]) + ", " + str(pix[1])) outArray.append(pix) return outArray ''' rt.dmcoords(evt2, asolfile=asol1, ra=sPos[0], dec=sPos[1], option='cel', verbose=1) sPix = [rt.dmcoords.x, rt.dmcoords.y] print( " sgrA pix "+str(sPix[0])+", "+str(sPix[1])) rt.dmcoords(evt2, asolfile=asol1, ra=mPos[0], dec=mPos[1], option='cel', verbose=1) mPix = [rt.dmcoords.x, rt.dmcoords.y] print( " magnetar pix "+str(mPix[0])+", "+str(mPix[1])) rt.dmcoords(evt2, asolfile=asol1, ra=bPos[0], dec=bPos[1], option='cel', verbose=1) bPix = [rt.dmcoords.x, rt.dmcoords.y] print( " bkg pix "+str(bPix[0])+", "+str(bPix[1])) ''' return sPix, mPix, bPix
def get_bin_size(reg_file): dmcoords.punlearn() dmcoords(infile=region_file, option="logical", logicalx=1, logicaly=1) x = dmcoords.x dmcoords.punlearn() dmcoords(infile=region_file, option="logical", logicalx=2, logicaly=1) x2 = dmcoords.x return np.abs(x - x2)
def get_RaDec(evt_file, cen_x, cen_y): dmcoords.punlearn() if evt_file.split('.')[-1] == 'img' or evt_file.split('.')[-1] == 'fits': dmcoords.infile = evt_file else: dmcoords.infile = evt_file + '.fits' # OBSID+'_broad_thresh.img' dmcoords.option = 'sky' dmcoords.x = cen_x dmcoords.y = cen_y dmcoords() cen_ra = dmcoords.ra cen_dec = dmcoords.dec return cen_ra, cen_dec
def get_ra_dec_of_max(img_file: str, reg_file: str, **kwargs) -> PointCel: """ Return maxima's ra and dec in decimal degrees :param img_file: Path to the events/image file :param reg_file: Path to the region file with CIAO/PHYS format that covers the desired region ... :rtype: PointCel """ dmstat.punlearn() dmstat(f"{img_file}[sky=region({reg_file})]") vals = [float(x) for x in dmstat.out_max_loc.split(",")] dmcoords.punlearn() dmcoords(img_file, option="sky", x=vals[0], y=vals[1], celfmt="deg") return PointCel(dmcoords.ra, dmcoords.dec)
def xray_pix2sky( inFile, x, y, asol='none'): ra = [] dec = [] ciao.dmcoords.punlearn() for i in xrange(len(x)): dm = ciao.dmcoords( infile=inFile, asol=asol, \ x=x[i], y=y[i], opt='sky', celfmt='deg') ra.append( np.float(ciao.dmcoords.ra)) dec.append( np.float(ciao.dmcoords.dec)) return np.array(ra), np.array(dec)
def calculate_offsets(x_xcen, x_ycen, r_xcen, r_ycen, region_file, binsize): # dmcoords(infile=region_file,option='sky',x=r_xcen,y=r_ycen) dmcoords(infile=region_file, option="cel", celfmt="hms", ra=r_xcen, dec=r_ycen) # print(x_xcen.mean(),x_ycen.mean()) # print(dmcoords.logicalx,dmcoords.logicaly) x = x_xcen - dmcoords.logicalx y = x_ycen - dmcoords.logicaly nan_indices = np.logical_and(np.isnan(x_xcen), np.isnan(x_ycen)) x = x[~nan_indices] y = y[~nan_indices] offsets = np.sqrt(np.add(x ** 2, y ** 2)) plt.hist(offsets * binsize * 0.492) plt.show() return offsets.mean(), offsets.std(), offsets
dec = sys.argv[4] if len(sys.argv) > 5: energy = float( sys.argv[5] ) / 1000. else: energy = def_en if len(sys.argv) > 6: frac = float( sys.argv[6] ) else: frac = def_frac dmcoords.punlearn() dmcoords.infile = evt dmcoords.asolfile = asol dmcoords.ra = ra dmcoords.dec = dec dmcoords.celfmt = "deg" dmcoords.opt = "cel" dmcoords() theta = dmcoords.theta phi = dmcoords.phi calquiz(telescope="CHANDRA", product="REEF") reef=calquiz.outfile pdata=psf.psfInit(reef) e=psf.psfSize(pdata,energy,theta,phi,frac) print("{0}".format(e)) psf.psfClose(pdata)