Giter Club home page Giter Club logo

ngsf's Introduction

Welcome to NGSF - Next Generation SuperFit in Python! ๐Ÿ’ซ ๐Ÿ’ฃ ๐Ÿ’ฅ

Superfit in python is a software for the spectral classification of Supernovae of all major types accompanied by a host galaxy. The following list of versions are the minumum requierments for its use.

Requierments

  • Python version: 3.7.1
  • numpy version: 1.21.2
  • scipy version: 1.7.1
  • matplotlib version: 3.0.2
  • astropy version: 3.1
  • Pandas version: 0.23.4
  • PyAstronomy version: 0.13.0

To run one object

The user must make sure to have a template bank to look at. The new template bank can be downloaded from WISeREP here.

The user must download the full superfit folder and place the bank inside it, also any spectra to be analyzed. The user only changes the parameters from the json file already within the folder, the following is an explanation of the parameters.

The parameters of the fit

The user must only change the parameters of the fit from the parameters.json file, the file looks like this (the template for this example is included in the git)

"object_to_fit" : "SN2021urb_2021-08-06_00-00-00_Keck1_LRIS_TNS.flm",

"use_exact_z": 1,
"z_exact": 0.127,


"z_range_begin": 0,
"z_range_end": 0.13,
"z_int": 0.01,


"resolution":10,

"temp_sn_tr"  : ["IIb-flash", "computed", "Ia 02es-like", "Ia-02cx like", "TDE He", "Ca-Ia",
                "Ia-CSM-(ambigious)", "II", "super_chandra", "SLSN-II", "IIn", "FBOT", "Ibn",
                "SLSN-IIn", "Ia 91T-like", "IIb", "TDE H", "SN - Imposter", "II-flash", "ILRT",
                "Ia 99aa-like", "Ic", "SLSN-I", "Ia-pec", "Ib", "Ia-CSM", "Ia-norm", "SLSN-Ib",
                "TDE H+He", "Ia 91bg-like", "Ca-Ib", "Ia-rapid", "Ic-BL", "Ic-pec", "SLSN-IIb"],

"temp_gal_tr" : ["E","S0","Sa","Sb","SB1","SB2","SB3","SB4","SB5","SB6","Sc"],

"lower_lam": 0,
"upper_lam": 0,

"error_spectrum" : "sg",
"saving_results_path" : "",

"show_plot" : 1,
"how_many_plots" : 1,

"mask_galaxy_lines":1,
"mask_telluric":0,

"minimum_overlap": 0.7,

"epoch_high": 0,
"epoch_low" : 0,

"Alam_high": 2,
"Alam_low": -2,
"Alam_interval":0.2

"object_to_fit" : the object to analyze, should be located within the superfit folder.

"use_exact_z": can be 1 (yes) or 0 (no). Determines wether the redshift will be an exact number or an array.

"z_exact" : exact redshift value that will be used if "use_exact_z" = 1

"z_range_begin","z_range_end","z_int": redshift values from which to build an array over which to look for the best fit.

"resolution": the resolution of the fit, the default is 10ร…, however, if the spectra is of lower quality then the fit will be performed automatically at 30ร….

"temp_gal_tr", "temp_sn_tr": template library folders over which to look in order to find the fit. It is recommended that the user uses the full library as is.

"lower_lam": Lower bound for wavelength over which to perform the fit "upper_lam": Upper bound for wavelength over which to perform the fit, if this is equal to "lower_lam" then the wavelength range will be chosen automatically as that of the object to fit ยฑ 300ร…

"error_spectrum" : refers to the type of routine used to perform the calculation of the error spectrum. The recommended one is sg Savitzky-Golay, there is also the option of linear estimation and the option included in which the user can use the error spectrum that comes with an object if he wants to, however, this is not recommended.

"saving_results_path": path in which to save the performed fits, the default one is the superfit folder.

"show_plot" : to show the plotted fit or no, the default being 1, to show. "how_many_plots": number of plots to show if the user wants to show, if the "show" is zero then "n" has no effect.

"mask_galaxy_lines" : Either 1 or 0, masks the galaxy lines for both the template bank and the object of interest. For this option to work the redshift must be one defined values and not at array of values, meaning "z_int" must be equal to zero and "z_start" must be the redshift of choice. "mask_telluric": Either 1 or 0, masks the flux within the wavelength range from 7594 to 7680 in the observer's frame.

"minimum_overlap": minimum percentage overlap between the template and the object of interest. Recommendation is for this to stay near 0.7

"epoch_high": Upper bound epoch for phase truncation. If this equals the "epoch_low" parameter then there is not phase truncation. "epoch_low": Lower bound epoch for phase truncation.

"Alam_high": High value for the extinction law constant "Alam_low": Lower value for the extinction law constant "Alam_interval": size of interval

To Run

Once the parameters have been updated in the parameters.json file the user simply needs to run the script from the run.py file.

It is important to note that the file of the object to be analyzed should be within the superfit folder.

Further details about the code

New template bank

The improved Superfit template bank contains major subclasses such as: calcium rich supernovae, type II flashers, TDEs, SLSN-I and II, among others, separated in different folders for more accurate classification. The default option for binning in 10A. The user must make sure to have this template bank or some alternative template bank of his own in order to run pySF, and please be mindful that pySF is only as good as the template bank it uses.

The user has the option to create a bank with masked lines, meaning to mask host galaxy lines that could be in the templates, this option is default to False. If the user is interested in seeing which lines are being masked he can access the mask_lines_bank function within the Header_binnings.py file.

It is important to note that when you open the folder of the bank there are two main subfolders, one named "original_resolution" and one named "binnings". The "original_resolution" folder contains the raw spectra from the bank, with the wavelengths in observed frame. In the "binnings" folder we have the binned and redshift-corrected spectra from the "original_resolution" folder, and so the fits are done using the "binnings" folder. Within the object subfolders inside the "original_resolution" folder we will find the wiserep files containing the metadata for each object (name,redshift, observational date, etc.) we use this metadata during the fit, and so we keep the folder.

Main NGSF Function

In the sf_class.py file we find the main function which looks like this:

all_parameter_space(self.int_obj,Parameters.redshift,Parameters.extconstant,Parameters.templates_sn_trunc,
                    Parameters.templates_gal_trunc, Parameters.lam, Parameters.resolution,Parameters.iterations,
                    kind=Parameters.kind, original= self.binned_name, save=self.results_name, show=show,
                    minimum_overlap=Parameters.minimum_overlap)

The inputs of the function are called from the Parameters class within the params.py file, and are as follow:

  • self.int_obj: interpolated object to fit
  • redshift: Can be an array or an individual number. These are the redshift values over which to optimize.
  • extconstant: Array of values over which to optimize for the extinction constant. The user does not change this.
  • templates_sn_trunc: Truncated library of supernovae, aka: which SN types to look at when optimizing.
  • templates_gal_trunc: Truncated library of host galaxies, aka: which HG types to look at when optimizing.
  • lam: Lambda array over which to perform the fit. The default is from 3000 A to 10500 A.
  • resolution: Resolution at which to bin and perform the fit. The default is 10 A.
  • kind: Corresponds to the type of error spectrum the user prefers, the options are SG:Savitsky Golay, linear: for obtaining the error of the spectrum by making linear fit every 10 points, and included: if the user wants to use the error that comes with the object itself. The default is sg
  • save: Name of results file
  • minimum_overlap: Corresponds to minimum percentage overlap between the template and the object of interest

Results

The results are: an astropy table that is saved as a csv file, and the best fit plots saved as pdf files (they both save to the superfit folder or to the specified saving_results_path)

The output graphs look like this

Output

The plot shows the input object in red, the SN and Host Galaxy combined templates in green. The legend shows the SN type, HG type and percentage contribution from the SN template to the fit. On top of the plot the redshift value is indicated.

ngsf's People

Contributors

guynir42 avatar mcoughlin avatar oyaron avatar samanthagoldwasser25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ngsf's Issues

Close Figures

When you make the plot can you add plt.close() afterwards. It spams my computer with warnings about memory errors.

Interp Crash

Ran this ascii file ZTF18aahqkbt_20180929_HST_v1.ascii and got a crash.


ValueError Traceback (most recent call last)
in
102 #Core superfit function on the binned file, default to plot and save n fits
--> 103 all_parameter_space(redshift,extconstant,templates_sn_trunc,templates_gal_trunc,
104 lam, resolution, n=n, plot=plotting, kind=kind, original=save_bin, save=save_results_path, show=show)

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in all_parameter_space(redshift, extconstant, templates_sn_trunc, templates_gal_trunc, lam, resolution, n, plot, **kwargs)
709 for element in itertools.product(redshift,extconstant):
--> 710
711 a, _ = core_total(element[0],element[1], sn_spec_files, templates_gal_trunc, lam, resolution, **kwargs)

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in core_total(z, extcon, templates_sn_trunc, templates_gal_trunc, lam, resolution, **kwargs)
317
--> 318 sigma = error_obj(kind, lam, original)
319

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in error_obj(kind, lam, obj_path)
145
--> 146 error = savitzky_golay(object_spec)
147

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/error_routines.py in savitzky_golay(spec)
101
--> 102 smooth = mf.savgol_filter(y, 31, 3 )
103 resid = y - smooth

~/anaconda3/lib/python3.8/site-packages/scipy/signal/_savitzky_golay.py in savgol_filter(x, window_length, polyorder, deriv, delta, axis, mode, cval)
338 if window_length > x.size:
--> 339 raise ValueError("If mode is 'interp', window_length must be less "
340 "than or equal to the size of x.")

ValueError: If mode is 'interp', window_length must be less than or equal to the size of x.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in
115 kill_header_and_bin(original,resolution, save_bin = save_bin)
116 #Core superfit function on the binned file, default to plot and save n fits
--> 117 all_parameter_space(redshift,extconstant,templates_sn_trunc,templates_gal_trunc,
118 lam, resolution, n=n, plot=plotting, kind=kind, original=save_bin, save=save_results_path, show=show)

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in all_parameter_space(redshift, extconstant, templates_sn_trunc, templates_gal_trunc, lam, resolution, n, plot, **kwargs)
708
709 for element in itertools.product(redshift,extconstant):
--> 710
711 a, _ = core_total(element[0],element[1], sn_spec_files, templates_gal_trunc, lam, resolution, **kwargs)
712

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in core_total(z, extcon, templates_sn_trunc, templates_gal_trunc, lam, resolution, **kwargs)
316 name = obj_name_int(original, lam, resolution)[0]
317
--> 318 sigma = error_obj(kind, lam, original)
319
320 sn, gal = sn_hg_arrays(z, extcon, lam, templates_sn_trunc, templates_gal_trunc)

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/SF_functions.py in error_obj(kind, lam, obj_path)
144 if kind == 'SG':
145
--> 146 error = savitzky_golay(object_spec)
147
148 object_err_interp = interpolate.interp1d(error[:,0], error[:,1], bounds_error=False, fill_value='nan')

/mnt/c/Users/20xha/Documents/Caltech/Research/superfit/superfit/error_routines.py in savitzky_golay(spec)
100
101
--> 102 smooth = mf.savgol_filter(y, 31, 3 )
103 resid = y - smooth
104

~/anaconda3/lib/python3.8/site-packages/scipy/signal/_savitzky_golay.py in savgol_filter(x, window_length, polyorder, deriv, delta, axis, mode, cval)
337 if mode == "interp":
338 if window_length > x.size:
--> 339 raise ValueError("If mode is 'interp', window_length must be less "
340 "than or equal to the size of x.")
341

ValueError: If mode is 'interp', window_length must be less than or equal to the size of x.

Branches - main

To be consistent with the rest of the ecosystem, the branch pull requests are made against should be called main.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.