Fit Data

class eddington.fitting_data.FittingData(data: Union[collections.OrderedDict, Dict[str, <sphinx.ext.autodoc.importer._MockObject object at 0x7f36c2ccb1d0>]], x_column: Union[str, int, None] = None, xerr_column: Union[str, int, None] = None, y_column: Union[str, int, None] = None, yerr_column: Union[str, int, None] = None)

Fitting data class.

Constructor.

Parameters:
  • data (dict or OrderedDict from str to numpy.ndarray) – Dictionary from a column name to its values
  • x_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • xerr_column (str or numpy.ndarray) – Indicates which column should be used as the x error parameter
  • y_column (str or numpy.ndarray) – Indicates which column should be used as the y parameter
  • yerr_column (str or numpy.ndarray) – Indicates which column should be used as the y error parameter
all_columns

Columns list.

all_records

Get all records in data as a list.

column_data(column_header: str)

Get the data of a column.

Parameters:column_header (str) – The header name of the desired column.
Returns:The data of the given column
Return type:numpy.array
data

Data matrix.

is_selected(index)

Checks if a record is selected or not.

Parameters:index (int) – index of the desired record starting from 1.
Returns:bool
length

Number of records.

classmethod random(fit_func, x: Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7f36c2ccb790>] = None, a: Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7f36c2ccb890>] = None, xmin: float = -20.0, xmax: float = 20.0, min_coeff: float = -10.0, max_coeff: float = 10.0, xsigma: float = 0.5, ysigma: float = 0.5, measurements: int = 20)

Generate a random fit data.

Parameters:
  • fit_func (FittingFunction) – FittingFunction to evaluate with the fit data
  • x (numpy.ndarray) – Optional. The input for the fitting algorithm. If not given, generated randomly.
  • a (numpy.ndarray) – Optional. the actual parameters that should be returned by the fitting algorithm. If not given, generated randomly.
  • xmin (float) – Minimum value for x.
  • xmax (float) – Maximum value for x.
  • min_coeff (float) – Minimum value for a coefficient.
  • max_coeff (float) – Maximum value for a coefficient.
  • xsigma (int) – Standard deviation for x.
  • ysigma (int) – Standard deviation for y.
  • measurements (int) – Number of measurements
Returns:

random FittingData

classmethod read_from_csv(filepath: Union[str, pathlib.Path], x_column: Union[str, int, None] = None, xerr_column: Union[str, int, None] = None, y_column: Union[str, int, None] = None, yerr_column: Union[str, int, None] = None)

Read FittingData from csv file.

Parameters:
  • filepath – str or Path. Path to location of csv file
  • x_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • xerr_column (str or numpy.ndarray) – Indicates which column should be used as the x error parameter
  • y_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • yerr_column – Indicates which column should be used as the y error parameter
Returns:

FittingData read from the csv file.

classmethod read_from_excel(filepath: Union[str, pathlib.Path], sheet: str, x_column: Union[str, int, None] = None, xerr_column: Union[str, int, None] = None, y_column: Union[str, int, None] = None, yerr_column: Union[str, int, None] = None)

Read FittingData from excel file.

Parameters:
  • filepath – str or Path. Path to location of excel file
  • sheet – str. The name of the sheet to extract the data from.
  • x_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • xerr_column (str or numpy.ndarray) – Indicates which column should be used as the x error parameter
  • y_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • yerr_column – Indicates which column should be used as the y error parameter
Returns:

FittingData read from the excel file.

classmethod read_from_json(filepath: Union[str, pathlib.Path], x_column: Union[str, int, None] = None, xerr_column: Union[str, int, None] = None, y_column: Union[str, int, None] = None, yerr_column: Union[str, int, None] = None)

Read FittingData from json file.

Parameters:
  • filepath – str or Path. Path to location of csv file
  • x_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • xerr_column (str or numpy.ndarray) – Indicates which column should be used as the x error parameter
  • y_column (str or numpy.ndarray) – Indicates which column should be used as the x parameter
  • yerr_column – Indicates which column should be used as the y error parameter
Returns:

FittingData read from the json file.

records

Get all selected records in data as a list.

records_indices

List of booleans indicating which records are selected.

residuals(fit_func, a: <sphinx.ext.autodoc.importer._MockObject object at 0x7f36c2ccb750>)

Creates residuals FittingData objects.

Parameters:
  • fit_func (FittingFunction) – FittingFunction to evaluate with the fit data
  • a (numpy.ndarray) – the parameters of the given fitting function
Returns:

residuals FittingData

save_csv(output_directory: Union[str, pathlib.Path], name: str = 'fitting_data')

Save FittingData to csv file.

Parameters:
  • output_directory (Path or str) – Path to the directory for the new excel file to be saved.
  • name (str) – Optional. The name of the file, without the .csv suffix. “fitting_data” by default.
save_excel(output_directory: Union[str, pathlib.Path], name: str = 'fitting_data', sheet: Optional[str] = None)

Save FittingData to xlsx file.

Parameters:
  • output_directory (Path or str) – Path to the directory for the new excel file to be saved.
  • name (str) – Optional. The name of the file, without the .xlsx suffix. “fitting_data” by default.
  • sheet (str) – Optional. Name of the sheet that the data will be saved to.
save_statistics_csv(output_directory: Union[str, pathlib.Path], name: Optional[str] = None)

Save the fitting data statistics to csv file.

Parameters:
  • output_directory (Path or str) – Path to the directory for the new excel file to be saved.
  • name (str) – Optional. The name of the file, without the .csv suffix. “fitting_data” by default.
save_statistics_excel(output_directory: Union[str, pathlib.Path], name: Optional[str] = None, sheet: Optional[str] = None)

Save the fitting data statistics to xlsx file.

Parameters:
  • output_directory (Path or str) – Path to the directory for the new excel file to be saved.
  • name (str) – Optional. The name of the file, without the .xlsx suffix. “fitting_data_statistics” by default.
  • sheet (str) – Optional. Name of the sheet that the data will be saved to.
select_all_records()

Select all records to be used in fitting.

select_record(index: int)

Select a record to be used in fitting.

Parameters:index (int) – index of the desired record starting from 1.
set_cell(record_number, column_name, value)

Set new value to a cell.

Parameters:
  • record_number (int) – The number of the record to set, starting from 1
  • column_name (str) – The column name
  • value (float) – The new value to set for the cell
set_header(old, new)

Rename header.

Parameters:
  • old (str) – The old columns name
  • new (str) – The new value to set for the header
statistics(column_name: str) → Optional[eddington.statistics.Statistics]

Get statistics of the values in a column.

Parameters:column_name (str) – The column name to get statistics of
Returns:Statistics of the given column
Return type:Statistics
unselect_all_records()

Unselect all records from being used in fitting.

unselect_record(index: int)

Unselect a record to be used in fitting.

Parameters:index (int) – index of the desired record starting from 1.
used_columns

Dictionary of columns in use.

x

X values.

x_column

Name of the x column.

xerr

X error values.

xerr_column

Name of the x error column.

y

Y values.

y_column

Name of the y column.

yerr

Y error values.

yerr_column

Name of the y error column.