486dx2-66 Postado Agosto 1, 2016 Denunciar Share Postado Agosto 1, 2016 (editado) Pessoal, há tempo venho me enrolando quando preciso ler um arquivo como esse que está abaixo (spec.dat). Qual seria a melhor maneira de ler os dados desse arquivo separadamente e,então, contruir tabelas e histogramas ? Por exemplo: Ler os elementos da coluna x_j(%) e age_j(yr). Ler o valor de [N_base] ## Some input info Base.M05SFull [arq_base] 57 [N_base] 0 [N_YAV_components = # of components with extra extinction!] 0 [i_FitPowerLaw (1/0 = Yes/No)] ## (Re)Sampling Parameters 11610.00 [l_ini (A)] 24500.00 [l_fin (A)] ## Normalization info 12230.00 [l_norm (A) - for base] 12200.00 [llow_norm (A) - window for f_obs] 12260.00 [lupp_norm (A) - window for f_obs] 3.120000E-17 [fobs_norm (in input units)] # j x_j(%) Mini_j(%) Mcor_j(%) age_j(yr) Z_j (L/M)_j YAV? Mstars component_j a/Fe... SSP_chi2r SSP_adev(%) SSP_AV SSP_x(%) 1 1.4781 3.6233E-01 5.2752E-01 1.000000E+07 0.00040 1.779E-04 0 0.9094 m05.z0.0004A_0. 0.0000 1.7210E+03 38.7910 5.0000 130.7247 2 0.0031 7.5960E-04 1.0559E-03 3.000000E+07 0.00040 1.791E-04 0 0.8683 m05.z0.0004A_0. 0.0000 6.2722E+02 22.6184 5.0000 123.1968 3 0.0012 3.4120E-04 4.6125E-04 5.000000E+07 0.00040 1.503E-04 0 0.8444 m05.z0.0004A_0. 0.0000 5.7873E+02 21.5826 5.0000 122.4820 4 0.0000 0.0000E+00 0.0000E+00 1.000000E+08 0.00040 1.235E-04 0 0.8073 m05.z0.0004A_0. 0.0000 5.1668E+02 20.1777 5.0000 121.4757 5 0.0304 1.3696E-02 1.6948E-02 2.000000E+08 0.00040 9.689E-05 0 0.7729 m05.z0.0004A_0. 0.0000 5.1557E+02 20.1942 5.0000 121.4867 6 13.4567 4.1353E+00 4.8065E+00 5.000000E+08 0.00040 1.419E-04 0 0.7260 m05.z0.0004A_0. 0.0000 1.4574E+02 9.4474 3.0902 103.2744 7 4.4286 1.7307E+00 1.9639E+00 7.000000E+08 0.00040 1.116E-04 0 0.7088 m05.z0.0004A_0. 0.0000 1.6090E+02 11.1368 5.0000 88.9404 8 3.9027 2.1085E+00 2.3292E+00 1.000000E+09 0.00040 8.071E-05 0 0.6900 m05.z0.0004A_1. 0.0000 9.5583E+01 8.9517 5.0000 94.3401 9 0.7589 7.5818E-01 8.0028E-01 2.000000E+09 0.00040 4.365E-05 0 0.6593 m05.z0.0004A_2. 0.0000 6.6007E+01 6.4125 5.0000 103.0134 10 5.4062 2.7183E+01 2.5872E+01 1.300000E+10 0.04000 8.672E-06 0 0.5945 m05.z0.04A_13.0 0.0000 6.3328E+01 7.2153 5.0000 101.1410 11 0.0000 0.0000E+00 0.0000E+00 1.000000E+00 0.00000 9.952E+00 0 1.0000 BB_700 0.0000 4.3247E+03 44.0822 0.0000 0.5478 12 9.8411 4.2904E-04 6.8688E-04 1.000000E+00 0.00000 1.000E+00 0 1.0000 Power_150 0.0000 1.1203E+02 7.9543 0.0000 87.0399 ## Synthesis Results - Average & Chains ## # j x_j: min, <> & last-chain-values for 1 ... 12 chains 1 1.4781 2.3577 2.4191 2.1424 2.3087 2.2562 2.3316 2.1499 2.1073 2.3995 2.3102 2.3386 2.2189 2.3029 2 0.0031 0.2126 0.3424 0.0425 0.3953 0.1954 0.0000 0.1363 0.0000 0.0577 0.1445 0.4121 0.1843 0.8749 3 0.0012 0.1785 0.0000 0.0000 0.0690 0.1942 0.0105 0.1394 0.0129 0.2873 0.4481 0.0000 0.2058 0.0000 # AV, chi2 & Mass for <> & i_chain = 1 ... 12 solutions AV 0.9529 0.9180 0.9256 0.9333 0.9127 0.9175 0.9327 0.9154 0.9142 0.9273 0.9372 0.9260 0.9219 0.9309 chi2 8.0773E+00 8.0951E+00 8.0903E+00 8.0895E+00 8.0988E+00 8.0904E+00 8.0906E+00 8.0913E+00 8.0908E+00 8.0916E+00 8.0880E+00 8.0917E+00 8.0912E+00 8.0919E+00 Mass 5.7755E-13 5.1633E-13 5.3867E-13 5.2781E-13 5.1839E-13 5.4180E-13 5.2434E-13 5.1936E-13 5.3047E-13 5.1270E-13 5.2630E-13 4.9951E-13 5.2338E-13 5.2286E-13 0.00 [v0_min (km/s) before EX0s...] 150.00 [vd_min (km/s) before EX0s...] ## Synthetic spectrum (Best Model) ##l_obs f_obs f_syn wei 2579 [Nl_obs] 11610.00 0.94817 1.02827 116.669 11615.00 0.96295 1.02735 116.669 11620.00 1.03489 1.02735 116.669 11625.00 1.09356 1.02753 116.669 11630.00 1.13951 1.02773 116.669 11635.00 1.11024 1.02797 116.669 Obrigado Editado Agosto 1, 2016 por 486dx2-66 Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 ArteEN Postado Agosto 7, 2016 Denunciar Share Postado Agosto 7, 2016 Em 01/08/2016 at 19:32, 486dx2-66 disse: ## Some input info Base.M05SFull [arq_base] 57 [N_base] 0 [N_YAV_components = # of components with extra extinction!] 0 [i_FitPowerLaw (1/0 = Yes/No)] ## (Re)Sampling Parameters 11610.00 [l_ini (A)] 24500.00 [l_fin (A)] ## Normalization info 12230.00 [l_norm (A) - for base] 12200.00 [llow_norm (A) - window for f_obs] 12260.00 [lupp_norm (A) - window for f_obs] 3.120000E-17 [fobs_norm (in input units)] # j x_j(%) Mini_j(%) Mcor_j(%) age_j(yr) Z_j (L/M)_j YAV? Mstars component_j a/Fe... SSP_chi2r SSP_adev(%) SSP_AV SSP_x(%) 1 1.4781 3.6233E-01 5.2752E-01 1.000000E+07 0.00040 1.779E-04 0 0.9094 m05.z0.0004A_0. 0.0000 1.7210E+03 38.7910 5.0000 130.7247 2 0.0031 7.5960E-04 1.0559E-03 3.000000E+07 0.00040 1.791E-04 0 0.8683 m05.z0.0004A_0. 0.0000 6.2722E+02 22.6184 5.0000 123.1968 3 0.0012 3.4120E-04 4.6125E-04 5.000000E+07 0.00040 1.503E-04 0 0.8444 m05.z0.0004A_0. 0.0000 5.7873E+02 21.5826 5.0000 122.4820 4 0.0000 0.0000E+00 0.0000E+00 1.000000E+08 0.00040 1.235E-04 0 0.8073 m05.z0.0004A_0. 0.0000 5.1668E+02 20.1777 5.0000 121.4757 5 0.0304 1.3696E-02 1.6948E-02 2.000000E+08 0.00040 9.689E-05 0 0.7729 m05.z0.0004A_0. 0.0000 5.1557E+02 20.1942 5.0000 121.4867 6 13.4567 4.1353E+00 4.8065E+00 5.000000E+08 0.00040 1.419E-04 0 0.7260 m05.z0.0004A_0. 0.0000 1.4574E+02 9.4474 3.0902 103.2744 7 4.4286 1.7307E+00 1.9639E+00 7.000000E+08 0.00040 1.116E-04 0 0.7088 m05.z0.0004A_0. 0.0000 1.6090E+02 11.1368 5.0000 88.9404 8 3.9027 2.1085E+00 2.3292E+00 1.000000E+09 0.00040 8.071E-05 0 0.6900 m05.z0.0004A_1. 0.0000 9.5583E+01 8.9517 5.0000 94.3401 9 0.7589 7.5818E-01 8.0028E-01 2.000000E+09 0.00040 4.365E-05 0 0.6593 m05.z0.0004A_2. 0.0000 6.6007E+01 6.4125 5.0000 103.0134 10 5.4062 2.7183E+01 2.5872E+01 1.300000E+10 0.04000 8.672E-06 0 0.5945 m05.z0.04A_13.0 0.0000 6.3328E+01 7.2153 5.0000 101.1410 11 0.0000 0.0000E+00 0.0000E+00 1.000000E+00 0.00000 9.952E+00 0 1.0000 BB_700 0.0000 4.3247E+03 44.0822 0.0000 0.5478 12 9.8411 4.2904E-04 6.8688E-04 1.000000E+00 0.00000 1.000E+00 0 1.0000 Power_150 0.0000 1.1203E+02 7.9543 0.0000 87.0399 ## Synthesis Results - Average & Chains ## # j x_j: min, <> & last-chain-values for 1 ... 12 chains 1 1.4781 2.3577 2.4191 2.1424 2.3087 2.2562 2.3316 2.1499 2.1073 2.3995 2.3102 2.3386 2.2189 2.3029 2 0.0031 0.2126 0.3424 0.0425 0.3953 0.1954 0.0000 0.1363 0.0000 0.0577 0.1445 0.4121 0.1843 0.8749 3 0.0012 0.1785 0.0000 0.0000 0.0690 0.1942 0.0105 0.1394 0.0129 0.2873 0.4481 0.0000 0.2058 0.0000 # AV, chi2 & Mass for <> & i_chain = 1 ... 12 solutions AV 0.9529 0.9180 0.9256 0.9333 0.9127 0.9175 0.9327 0.9154 0.9142 0.9273 0.9372 0.9260 0.9219 0.9309 chi2 8.0773E+00 8.0951E+00 8.0903E+00 8.0895E+00 8.0988E+00 8.0904E+00 8.0906E+00 8.0913E+00 8.0908E+00 8.0916E+00 8.0880E+00 8.0917E+00 8.0912E+00 8.0919E+00 Mass 5.7755E-13 5.1633E-13 5.3867E-13 5.2781E-13 5.1839E-13 5.4180E-13 5.2434E-13 5.1936E-13 5.3047E-13 5.1270E-13 5.2630E-13 4.9951E-13 5.2338E-13 5.2286E-13 0.00 [v0_min (km/s) before EX0s...] 150.00 [vd_min (km/s) before EX0s...] ## Synthetic spectrum (Best Model) ##l_obs f_obs f_syn wei 2579 [Nl_obs] 11610.00 0.94817 1.02827 116.669 11615.00 0.96295 1.02735 116.669 11620.00 1.03489 1.02735 116.669 11625.00 1.09356 1.02753 116.669 11630.00 1.13951 1.02773 116.669 11635.00 1.11024 1.02797 116.669 A citação a cima é o conteúdo do arquivo, certo? Então com open você consegue fazer a abertura do arquivo, e supondo que a codificação não de problemas Tambem supondo que todos os arquivos que você vai ler tenham um padrão Com todas as suposições confirmadas, você deve usar open.readline ate chegar em uma determinada linha, você confirma esta linha com in. ex: if x_j(%) in linha As linhas subsequentes tem a informação que você quer, continue com open.readline, faça linha.split que vai dividir a linha em uma lista de strings, e escolha o index. ex: lista[1] Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
486dx2-66
Pessoal, há tempo venho me enrolando quando preciso ler um arquivo como esse que está abaixo (spec.dat).
Qual seria a melhor maneira de ler os dados desse arquivo separadamente e,então, contruir tabelas e histogramas ?
Por exemplo:
Ler os elementos da coluna x_j(%) e age_j(yr).
Ler o valor de [N_base]
## Some input info
Base.M05SFull [arq_base]
57 [N_base]
0 [N_YAV_components = # of components with extra extinction!]
0 [i_FitPowerLaw (1/0 = Yes/No)]
## (Re)Sampling Parameters
11610.00 [l_ini (A)]
24500.00 [l_fin (A)]
## Normalization info
12230.00 [l_norm (A) - for base]
12200.00 [llow_norm (A) - window for f_obs]
12260.00 [lupp_norm (A) - window for f_obs]
3.120000E-17 [fobs_norm (in input units)]
# j x_j(%) Mini_j(%) Mcor_j(%) age_j(yr) Z_j (L/M)_j YAV? Mstars component_j a/Fe... SSP_chi2r SSP_adev(%) SSP_AV SSP_x(%)
1 1.4781 3.6233E-01 5.2752E-01 1.000000E+07 0.00040 1.779E-04 0 0.9094 m05.z0.0004A_0. 0.0000 1.7210E+03 38.7910 5.0000 130.7247
2 0.0031 7.5960E-04 1.0559E-03 3.000000E+07 0.00040 1.791E-04 0 0.8683 m05.z0.0004A_0. 0.0000 6.2722E+02 22.6184 5.0000 123.1968
3 0.0012 3.4120E-04 4.6125E-04 5.000000E+07 0.00040 1.503E-04 0 0.8444 m05.z0.0004A_0. 0.0000 5.7873E+02 21.5826 5.0000 122.4820
4 0.0000 0.0000E+00 0.0000E+00 1.000000E+08 0.00040 1.235E-04 0 0.8073 m05.z0.0004A_0. 0.0000 5.1668E+02 20.1777 5.0000 121.4757
5 0.0304 1.3696E-02 1.6948E-02 2.000000E+08 0.00040 9.689E-05 0 0.7729 m05.z0.0004A_0. 0.0000 5.1557E+02 20.1942 5.0000 121.4867
6 13.4567 4.1353E+00 4.8065E+00 5.000000E+08 0.00040 1.419E-04 0 0.7260 m05.z0.0004A_0. 0.0000 1.4574E+02 9.4474 3.0902 103.2744
7 4.4286 1.7307E+00 1.9639E+00 7.000000E+08 0.00040 1.116E-04 0 0.7088 m05.z0.0004A_0. 0.0000 1.6090E+02 11.1368 5.0000 88.9404
8 3.9027 2.1085E+00 2.3292E+00 1.000000E+09 0.00040 8.071E-05 0 0.6900 m05.z0.0004A_1. 0.0000 9.5583E+01 8.9517 5.0000 94.3401
9 0.7589 7.5818E-01 8.0028E-01 2.000000E+09 0.00040 4.365E-05 0 0.6593 m05.z0.0004A_2. 0.0000 6.6007E+01 6.4125 5.0000 103.0134
10 5.4062 2.7183E+01 2.5872E+01 1.300000E+10 0.04000 8.672E-06 0 0.5945 m05.z0.04A_13.0 0.0000 6.3328E+01 7.2153 5.0000 101.1410
11 0.0000 0.0000E+00 0.0000E+00 1.000000E+00 0.00000 9.952E+00 0 1.0000 BB_700 0.0000 4.3247E+03 44.0822 0.0000 0.5478
12 9.8411 4.2904E-04 6.8688E-04 1.000000E+00 0.00000 1.000E+00 0 1.0000 Power_150 0.0000 1.1203E+02 7.9543 0.0000 87.0399
## Synthesis Results - Average & Chains ##
# j x_j: min, <> & last-chain-values for 1 ... 12 chains
1 1.4781 2.3577 2.4191 2.1424 2.3087 2.2562 2.3316 2.1499 2.1073 2.3995 2.3102 2.3386 2.2189 2.3029
2 0.0031 0.2126 0.3424 0.0425 0.3953 0.1954 0.0000 0.1363 0.0000 0.0577 0.1445 0.4121 0.1843 0.8749
3 0.0012 0.1785 0.0000 0.0000 0.0690 0.1942 0.0105 0.1394 0.0129 0.2873 0.4481 0.0000 0.2058 0.0000
# AV, chi2 & Mass for <> & i_chain = 1 ... 12 solutions
AV 0.9529 0.9180 0.9256 0.9333 0.9127 0.9175 0.9327 0.9154 0.9142 0.9273 0.9372 0.9260 0.9219 0.9309
chi2 8.0773E+00 8.0951E+00 8.0903E+00 8.0895E+00 8.0988E+00 8.0904E+00 8.0906E+00 8.0913E+00 8.0908E+00 8.0916E+00 8.0880E+00 8.0917E+00 8.0912E+00 8.0919E+00
Mass 5.7755E-13 5.1633E-13 5.3867E-13 5.2781E-13 5.1839E-13 5.4180E-13 5.2434E-13 5.1936E-13 5.3047E-13 5.1270E-13 5.2630E-13 4.9951E-13 5.2338E-13 5.2286E-13
0.00 [v0_min (km/s) before EX0s...]
150.00 [vd_min (km/s) before EX0s...]
## Synthetic spectrum (Best Model) ##l_obs f_obs f_syn wei
2579 [Nl_obs]
11610.00 0.94817 1.02827 116.669
11615.00 0.96295 1.02735 116.669
11620.00 1.03489 1.02735 116.669
11625.00 1.09356 1.02753 116.669
11630.00 1.13951 1.02773 116.669
11635.00 1.11024 1.02797 116.669
Obrigado
Editado por 486dx2-66Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.