dhubax

Plot RAD_ALL profiles

Mar 3rd, 2021 (edited)
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.49 KB | None | 0 0
  1. # # Reading example of RAD_ALL file.
  2. from astropy.io import fits
  3.  
  4. gal = 'NGC2916'
  5. t = fits.open(f'{gal}.p_e.RAD_ALL.fits.gz')
  6.  
  7. ### HEADER
  8. # SIMPLE  =                    T / Created with PDL (http://pdl.perl.org)        
  9. # BITPIX  =                  -64                                                  
  10. # NAXIS   =                    3                                                  
  11. # NAXIS1  =                   24                                                  
  12. # NAXIS2  =                    6                                                  
  13. # NAXIS3  =                   27                                                  
  14. # BUNIT   = 'Data Value'                                                          
  15. # DESC_23 = 'Lambda  '                                                            
  16. # Y_0     = 'R_Re    '                                                            
  17. # DESC_2  = 'Sigma_Mass_gas'                                                      
  18. # DESC_9  = 'OH_O3N2 '                                                            
  19. # DESC_8  = 'OH_t2   '                                                            
  20. # DESC_26 = 'NO_N2S2 '                                                            
  21. # Y_2     = 'stddev  '                                                            
  22. # DESC_12 = 'disp_ssp'                                                            
  23. # DESC_0  = 'Sigma_Mass_stars'                                                    
  24. # DESC_25 = 'NO_ONS  '                                                            
  25. # DESC_5  = 'ZH_MW   '                                                            
  26. # DESC_1  = 'Sigma_SFR'                                                          
  27. # DESC_13 = 'disp_Ha '                                                            
  28. # Y_5     = 'max     '                                                            
  29. # Y_3     = 'median  '                                                            
  30. # DESC_22 = 'Sigma_Mass_gas_rad'                                                  
  31. # DESC_10 = 'Av_gas  '                                                            
  32. # DESC_15 = 'vel_ssp '                                                            
  33. # DESC_21 = 'Sigma_SFR_ssp'                                                      
  34. # DESC_16 = 'SK_ssp  '                                                            
  35. # DESC_3  = 'Sigma_Mass_gas_ssp'                                                  
  36. # DESC_20 = 'ML      '                                                            
  37. # DESC_11 = 'Av_ssp  '                                                            
  38. # DESC_19 = 'KIN_Ha  '                                                            
  39. # Y_1     = 'mean    '                                                            
  40. # DESC_17 = 'SK_Ha   '                                                            
  41. # DESC_18 = 'KIN_ssp '                                                            
  42. # DESC_7  = 'Age_MW  '                                                            
  43. # DESC_4  = 'ZH_LW   '                                                            
  44. # DESC_14 = 'vel_Ha  '                                                            
  45. # DESC_24 = 'OH_ONS  '                                                            
  46. # DESC_6  = 'Age_LW  '                                                            
  47. # Y_4     = 'min     '                                                            
  48.  
  49. # t[0].data.shape
  50. # (27, 6, 24)
  51. # 27 parameters, R + 5 statistics (mean, stddev, median, min, max), 24 radial bins
  52. RAD_ALL__psr = t[0].data  # __psr are the dimensions of the vector, i.e., parameters, statistics, radii
  53.  
  54.  
  55. # 1st example, the mean (index = 1) Sigma_Mass_stars (index = 0) radial profile is:
  56. Sigma_stars = RAD_ALL__psr[0, 1, :]
  57.  
  58. # 2nd example, the median (index = 3) stellar metalicity mass weighted (index = 5) radial profile is:
  59. ZH_MW = RAD_ALL__psr[5, 3, :]
  60.  
  61. # I prefer to work with names instead indices, so you can create you translation dictionary using the header:
  62.  
  63. h = t[0].header
  64. par_dict = {t[0].header[f'DESC_{i}'].strip(): i for i in range(h['NAXIS1'])}
  65. stats_dict = {t[0].header[f'Y_{i}'].strip(): i for i in range(h['NAXIS2'])}
  66.  
  67. # par_dict
  68. # {'Sigma_Mass_stars': 0,
  69. #  'Sigma_SFR': 1,
  70. #  'Sigma_Mass_gas': 2,
  71. #  'Sigma_Mass_gas_ssp': 3,
  72. #  'ZH_LW': 4,
  73. #  'ZH_MW': 5,
  74. #  'Age_LW': 6,
  75. #  'Age_MW': 7,
  76. #  'OH_t2': 8,
  77. #  'OH_O3N2': 9,
  78. #  'Av_gas': 10,
  79. #  'Av_ssp': 11,
  80. #  'disp_ssp': 12,
  81. #  'disp_Ha': 13,
  82. #  'vel_Ha': 14,
  83. #  'vel_ssp': 15,
  84. #  'SK_ssp': 16,
  85. #  'SK_Ha': 17,
  86. #  'KIN_ssp': 18,
  87. #  'KIN_Ha': 19,
  88. #  'ML': 20,
  89. #  'Sigma_SFR_ssp': 21,
  90. #  'Sigma_Mass_gas_rad': 22,
  91. #  'Lambda': 23}
  92.  
  93. # stats_dict
  94. # {'R_Re': 0, 'mean': 1, 'stddev': 2, 'median': 3, 'min': 4, 'max': 5}
  95.  
  96. # Repeting the above examples using the dictionaries
  97.  
  98. # 3rd example, the mean Sigma_Mass_stars radial profile:
  99. Sigma_stars = RAD_ALL__psr[:, stats_dict['mean'], par_dict['Sigma_Mass_stars']]
  100.  
  101. # 4th example, the median ZH_MW radial profile:
  102. ZH_MW = RAD_ALL__psr[:, stats_dict['median'], par_dict['ZH_MW']]
  103.  
  104. from matplotlib import pyplot as plt
  105.  
  106. #plotting everything
  107. for _par, _ind in par_dict.items():
  108.     r = RAD_ALL__psr[_ind, stats_dict['R_Re'], :]
  109.     f = plt.figure()
  110.     plt.title(gal)
  111.     plt.xlabel('R [Re]')
  112.     plt.ylabel(_par)
  113.     for _stat in ['mean', 'stddev', 'median', 'min', 'max']:
  114.         plt.plot(r, RAD_ALL__rsp[_ind, stats_dict[_stat], :], label=_stat)
  115.     plt.legend()
  116.     plt.savefig(f'{gal}-{_par}.png')
  117.     plt.close(f)
Add Comment
Please, Sign In to add comment