Skip to content

Commit

Permalink
Optionally convert bytes into strings in plot_empirical
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstolker committed Mar 19, 2021
1 parent 968c878 commit 09bf314
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 16 additions & 4 deletions species/analysis/empirical.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def spectral_type(self,
for i, item in enumerate(h5_file[f'spectra/{self.spec_library}']):
# Read spectrum spectral type from library
dset = h5_file[f'spectra/{self.spec_library}/{item}']
item_sptype = dset.attrs['sptype'].decode('utf-8')

if isinstance(dset.attrs['sptype'], str):
item_sptype = dset.attrs['sptype']
else:
# Use decode for backward compatibility
item_sptype = dset.attrs['sptype'].decode('utf-8')

if item_sptype == 'None':
continue
Expand Down Expand Up @@ -163,6 +168,7 @@ def spectral_type(self,
'use a broader range as argument of \'wavel_range\'.')

spectrum = spectrum[indices, ]

empty_message = len(print_message)*' '
print(f'\r{empty_message}', end='')

Expand Down Expand Up @@ -257,9 +263,15 @@ def spectral_type(self,

print('Best-fitting spectra:')

for i in range(10):
print(f' - G = {gk_select[i]:.2e} -> {name_select[i]}, {spt_select[i]}, '
f'A_V = {av_select[i]:.2f}, RV = {rv_select[i]:.0f} km/s')
if len(gk_select) < 10:
for i in range(len(gk_select)):
print(f' {i+1:2d}. G = {gk_select[i]:.2e} -> {name_select[i]}, {spt_select[i]}, '
f'A_V = {av_select[i]:.2f}, RV = {rv_select[i]:.0f} km/s')

else:
for i in range(10):
print(f' {i+1:2d}. G = {gk_select[i]:.2e} -> {name_select[i]}, {spt_select[i]}, '
f'A_V = {av_select[i]:.2f}, RV = {rv_select[i]:.0f} km/s')

species_db = database.Database()

Expand Down
10 changes: 9 additions & 1 deletion species/plot/plot_empirical.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def plot_statistic(tag: str,

for i, item in enumerate(sptypes):
for j in range(10):
if not isinstance(item, str):
item = item.decode('utf-8')

if item == f'M{j}':
sptype_num[i] = float(j)

Expand Down Expand Up @@ -257,7 +260,12 @@ def plot_empirical_spectra(tag: str,
obj_res = read_obj.get_spectrum()[spec_name][3]

for i in range(n_spectra):
spectrum = np.asarray(h5_file[f'spectra/{spec_library}/{names[i]}'])
if isinstance(names[i], str):
name_item = names[i]
else:
name_item = names[i].decode('utf-8')

spectrum = np.asarray(h5_file[f'spectra/{spec_library}/{name_item}'])

ism_ext = dust_util.ism_extinction(av_ext[i], 3.1, spectrum[:, 0])
ext_scaling = 10.**(-0.4*ism_ext)
Expand Down

0 comments on commit 09bf314

Please sign in to comment.