Skip to content

Commit

Permalink
Merge pull request USNavalResearchLaboratory#87 from MJWeberg/main
Browse files Browse the repository at this point in the history
Added fit width convenience array
  • Loading branch information
MJWeberg authored Mar 5, 2024
2 parents 3ee8b49 + 9c237cf commit acb6b34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions eispac/core/eisfitresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ def create_fit_dict(n_pxls, n_steps, n_wave, n_gauss, n_poly, data_units='unknow
# 'err_peak': np.zeros((n_pxls, n_steps, n_gauss)),
# 'centroid': np.zeros((n_pxls, n_steps, n_gauss)),
# 'err_centroid': np.zeros((n_pxls, n_steps, n_gauss)),
# 'width': np.zeros((n_pxls, n_steps, n_gauss)),
# 'err_width': np.zeros((n_pxls, n_steps, n_gauss)),
'width': np.zeros((n_pxls, n_steps, n_gauss)),
'err_width': np.zeros((n_pxls, n_steps, n_gauss)),
# 'background': np.zeros((n_pxls, n_steps, n_poly)),
# 'err_background': np.zeros((n_pxls, n_steps, n_poly)),
'params': np.zeros((n_pxls, n_steps, n_param)),
Expand Down
4 changes: 4 additions & 0 deletions eispac/core/fit_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def fit_with_mpfit(wave_cube, inten_cube, errs_cube, template, parinfo,
fit_dict['perror'][ii,jj,:] = out.perror
fit_dict['int'][ii,jj,:] = l_inten
fit_dict['err_int'][ii,jj,:] = e_inten
fit_dict['width'][ii,jj,:] = fwdths
fit_dict['err_width'][ii,jj,:] = ewdths
else:
print(' ! fit did not converge!')
fit_dict['status'][ii,jj] = out.status
Expand Down Expand Up @@ -412,6 +414,8 @@ def fit_spectra(inten, template, parinfo=None, wave=None, errs=None, min_points=
fit_res.fit['perror'][:,jj,:] = pool_out[jj]['perror'][:,0,:]
fit_res.fit['int'][:,jj,:] = pool_out[jj]['int'][:,0,:]
fit_res.fit['err_int'][:,jj,:] = pool_out[jj]['err_int'][:,0,:]
fit_res.fit['width'][:,jj,:] = pool_out[jj]['width'][:,0,:]
fit_res.fit['err_width'][:,jj,:] = pool_out[jj]['err_width'][:,0,:]

# Calculate the Doppler velocity for each line
# TODO: revisit error estimation
Expand Down
15 changes: 11 additions & 4 deletions eispac/core/read_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ def read_template(filename):
Object containing the fit template
"""
# Note: this is just a convience function to avoid breaking the old API
# Please see the code in the class method
# Please see the code in the class method.
# (coped below for referencce on 2024-03-05)
return EISFitTemplate.read_template(filename)

# # TODO: Add loading custom template from a .toml file

# # NOTE: return None here rather than allow h5py to handle
# # exception so that spectral fitting pipeline can error
# # more gracefully
Expand Down Expand Up @@ -69,6 +68,14 @@ def read_template(filename):
# val = np.char.decode(val) # convert bytes to unicode
# parameter[key] = val
# parinfo.append(parameter)

# # Fix the datatypes of important keys
# template['n_gauss'] = int(template.get('n_gauss', 1))
# template['n_poly'] = int(template.get('n_poly', 1))
# template['wmin'] = float(template.get('wmin', 100))
# template['wmax'] = float(template.get('wmax', 1000))
# template['component'] = int(template.get('component', 1))
# template['line_ids'] = template['line_ids'].astype('<U24')
# elif file_type.lower() == '.toml':
# # Load a custom template stored in a TOML file
# with open(filename, 'rb') as f_temp:
Expand All @@ -80,4 +87,4 @@ def read_template(filename):
# parinfo = toml_dict.get('parinfo', None)
# # note: this parinfo will be an alternative dict of lists

# return EISFitTemplate(filename, template, parinfo)
# return cls(filename, template, parinfo)

0 comments on commit acb6b34

Please sign in to comment.