SNFit package

Submodules

SNFit.lc_analysis module

SNFit.lc_analysis.fitting_function(time, brightness, order, error=None)

Fit a polynomial to supernova lightcurve data and compute goodness-of-fit.

If measurement errors are provided, computes both the reduced chi-squared and R^2 metrics. If errors are not provided, computes only the R^2 metric.

Parameters:
  • time (array-like) – Time values (e.g., Phase or MJD).

  • brightness (array-like) – Corresponding brightness measurements (e.g., flux, magnitude, or luminosity).

  • order (int) – Degree of the polynomial to fit.

  • error (array-like, optional) – Measurement uncertainties for brightness. Used as weights in fitting and for chi-squared calculation. Defaults to None.

Returns:

numpy.ndarray: Fitted data from the polynomial

numpy.ndarray: Polynomial coefficients from highest degree to constant term.

float or None: Reduced chi-squared statistic indicating goodness-of-fit, or None if errors are not provided.

float: Coefficient of determination indicating fraction of variance explained by fit.

Return type:

tuple

SNFit.lightcurve module

class SNFit.lightcurve.LightCurve(filepath, upload_df=None)

Bases: object

Loads and formats a supernova lightcurve file into a pandas DataFrame for plotting, including detection of associated error columns for multiple brightness columns.

filepath

Path to the lightcurve file.

Type:

str

df

DataFrame containing the loaded and formatted lightcurve data.

Type:

pd.DataFrame

time_col

Name of the column representing time (phase, MJD, etc.).

Type:

str or None

value_cols

List of columns representing brightness values (flux, luminosity, magnitude).

Type:

list of str

error_cols

Mapping from brightness columns to the associated error columns.

Type:

dict

get_error_column(brightness_col)

Public method to get the error column corresponding to a brightness column.

Parameters:

brightness_col (str) – Name of brightness column.

Returns:

Name of error column or None if not found.

Return type:

str or None

time_colnames = ['phase', 'mjd', 'time', 'date']
value_colnames = ['l', 'mag', 'luminosity', 'f', 'flux']

SNFit.load_file module

SNFit.load_file.load_and_format(filepath=None, contents=None, upload_filename=None, df=None)

Load or parse data into a pandas DataFrame, handling file paths, uploaded base64 contents, or directly passed DataFrames.

Tries multiple parsing strategies in order until one works.

Parameters:
  • file (str or file-like, optional) – Path to a local file or StringIO.

  • contents (str, optional) – Base64-encoded uploaded file content.

  • upload_filename (str, optional) – Name of the uploaded file (for parsing).

  • df (pd.DataFrame, optional) – DataFrame already loaded.

Returns:

Loaded and cleaned DataFrame.

Return type:

pd.DataFrame

Raises:
  • ValueError – If unsupported file type or invalid input.

  • RuntimeError – If file parsing fails.

SNFit.load_file.load_dir(filepath=None)

Scan the data directory and build a dictionary mapping user-friendly labels to file paths. Optionally adds an extra file via the filepath argument. Default is the files included in the data_dir directory.

Parameters:

filepath (str, optional) – Filepath input of location of file on disk to plot. Defaults to None.

Returns:

Dictionary mapping user-friendly labels to file paths.

Return type:

dict

SNFit.plot module

SNFit.plot.main()

Set up the Dash app layout including headers, upload button, dropdowns, sliders, inputs for phase range, and the graph container.

This initializes all UI components with appropriate styles and default values.

SNFit.plot.open_browser()

Open the default web browser to the local Dash app address.

Returns:

None

SNFit.plot.run_plot()

Start the Dash server and open the app in the browser after a short delay.

Returns:

None

SNFit.plot.update_column_dropdowns(selected_file, upload_contents, upload_filename)

Populate time and brightness column dropdowns based on selected file or uploaded data.

Parameters:
  • selected_file (str) – The filename or path currently selected.

  • upload_contents (str) – Base64-encoded uploaded file contents.

  • upload_filename (str) – Filename of the uploaded file.

Returns:

list: Time axis options

str: Currently selected time axis option

list: Brightness axis options

str: Currently selected brightness axis option

Return type:

tuple

SNFit.plot.update_dropdown_options(upload_contents, upload_filename, options, current_value)

Update dropdown options and selection to include uploaded files.

Parameters:
  • upload_contents (str) – Base64-encoded contents of an uploaded file.

  • upload_filename (str) – Filename of the uploaded file.

  • options (list) – Existing list of dropdown options.

  • current_value (str) – Currently selected dropdown value.

Returns:

list: Updated dropdown options list str: Selected value

Return type:

tuple

SNFit.plot.update_figure(file, time_col, value_col, order, phase_min, phase_max, upload_contents, upload_filename, relayoutData)

Update the lightcurve plot and display fit results based on selected inputs.

Parameters:
  • file (str) – Selected filename.

  • time_col (str) – Selected time column name.

  • value_col (str) – Selected brightness column name.

  • order (int) – Polynomial order for fitting.

  • phase_min (float) – Minimum phase to include in fit.

  • phase_max (float) – Maximum phase to include in fit.

  • upload_contents (str) – Base64-encoded contents of uploaded file.

  • upload_filename (str) – Filename of the uploaded file.

  • relayoutData (dict) – Plotly relayout data to preserve zoom/pan.

Returns:

plotly.graph_objs.Figure: Updated figure with data and fit.

html.Div: Div containing the fit coefficients table.

html.Div: Label indicating the loaded file.

Return type:

tuple

SNFit.plot.update_phase_range(file, time_col, upload_contents, upload_filename)

Compute default phase range (min and max) for inputs based on selected time column.

Parameters:
  • file (str) – Selected filename.

  • time_col (str) – Selected time column.

  • upload_contents (str) – Base64 encoded contents of uploaded file.

  • upload_filename (str) – Filename of the uploaded file.

Returns:

float: Minimum phase/time value

float: Maximum phase/time value

Return type:

tuple

Module contents