PageRenderTime 53ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/xspecextraction.py

https://bitbucket.org/ahoffer/acceptii
Python | 70 lines | 57 code | 2 blank | 11 comment | 9 complexity | 0bcc42b3469f07789a727038d57d28b4 MD5 | raw file
  1. #extract fit from Xspec fit
  2. import math,os,matplotlib
  3. f=open('E:\\Science\\Xray\\2320\\repro\\xspec_tx_fit_2320.log','r') #xspec output
  4. count=0
  5. anncount=0
  6. obsid = '2320'
  7. asec_pix = 0.492 # "/pix
  8. kpc_asec = 3.098 # kpc/"
  9. tx = []
  10. fe = []
  11. z = []
  12. stat = []
  13. dof = []
  14. ann = []
  15. ann_num = []
  16. while True:
  17. line = f.readline()
  18. if len(line)==0:
  19. print("EOF")
  20. break
  21. #if "Spectral Data File" in line:
  22. # line=line.split(' ')
  23. # ann_name = line[3]
  24. # ann_name=ann_name.strip('.pi')
  25. # ann.append(ann_name)
  26. # ann_num.append(anncount)
  27. # anncount=anncount+1
  28. if "#Hey" in line:
  29. line=line.strip('#Hey\n')
  30. line=line.split(' ')
  31. if "tx" in line:
  32. tx.append(float(line[2]))
  33. if "fe" in line:
  34. fe.append(float(line[2]))
  35. if "z" in line:
  36. z.append(float(line[2]))
  37. if "stat" in line:
  38. stat.append(float(line[2]))
  39. if "dof" in line:
  40. dof.append(float(line[2]))
  41. count+=1
  42. redchi=np.divide(stat,dof) #reduced chisq
  43. while anncount <= len(tx)-1:
  44. regname = 'E:\\Science\\Xray\\2320\\repro\\annulus'+str(anncount)+'.reg'
  45. freq = open(regname,'r')
  46. line_reg = freq.readline()
  47. line_reg = line_reg.strip("annulus()\n")
  48. line_reg = line_reg.split(',')
  49. #ann.append([float(line_reg[2]),float(line_reg[3])])
  50. ann.append(float(line_reg[2]))
  51. anncount+=1
  52. ann = np.multiply(ann,asec_pix)
  53. ann = np.multiply(ann,kpc_asec)
  54. #temperature profile
  55. temp = subplot(111)
  56. temp.plot(ann,tx,'o')
  57. temp.set_ylim(0,10)
  58. temp.set_xlabel("R [kpc]")
  59. temp.set_ylabel("Temperature [keV]")
  60. temp.set_title("Temperature Profile")
  61. savefig('E:\\Scripts\\temp_'+obsid+'.pdf',transparent=True)
  62. #metallicity profile
  63. met=subplot(211)
  64. met.plot(ann,fe,'o')
  65. met.set_xlabel("R [kpc]")
  66. met.set_ylabel("Metallicity [Z/Z_sun]")
  67. met.set_title("Metallicity Profile")
  68. savefig('E:\\Scripts\\met_'+obsid+'.pdf',transparent=True)