mwvgroup / csp-cmfgen

A comparison spectral SNe models against CSP data
https://mwvgroup.github.io/nir-comparison/
0 stars 0 forks source link

band name mappings #1

Closed ojwg closed 5 years ago

ojwg commented 5 years ago

In the following code:

import sncosmo

sources = [Chandra()]

for i in range(0, 1):
    # select 14 names of SN from the 3rd CSP data release
    name = csp.master_table[i*10]['SN']
    data_formatted = csp.get_input_for_id(name)
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_u')] = 'cspu'
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_B')] = 'cspb'
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_V0')] = 'cspv3014'
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_g')] = 'cspg'
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_i')] = 'cspi'
    data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_r')] = 'cspr'

    for source in sources:
    # create a model
        model = sncosmo.Model(source=source)
        model.set(z=data_formatted.meta['redshift'])
        result, fitted_model = sncosmo.fit_lc(
            data_formatted, model,
            ['t0', 'x0'])  # parameters of model to vary
        # bounds={'z': (0.3, 0.7)})  # bounds on parameters (if any)
        print("SN: ", name, " MODEL: ", source.name)
        print("   param_names:", result.param_names)
        print("   parameters:", result.parameters)
        print("   chisq:", result.chisq)
        print("   ndof:", result.ndof)
        print("   errors", result.errors)
        print("   covariance", result.covariance)
        # Plot results
        fig = sncosmo.plot_lc(data_formatted, model=fitted_model, errors=result.errors, model_label=source.name)
        fig.show()

I need to map the band names, for example: data_formatted['band'][np.where(data_formatted['band'] == '91bg_proj_csp_u')] = 'cspu'

else the plots will have band names like <Bandpass at 0x183ea94c88>

djperrefort commented 5 years ago

After playing around with this I realized the name only shows up for a band if you name it before registering it. If the name is only specified during registration sncosmo appears to ignore it.

The csp module was originally borrowed from some code that was still under development. However, that code has since been formalized and published to pip. Instead of mantaining two versions of the same code, I suggest we just use the published version. The interface is basically the same, with minor differences in one or two function names. Full documentation is available here.

djperrefort commented 5 years ago

Addressed by PR #2