Fitting Data

class eddington.fitting_data.FittingData(data: Union[collections.OrderedDict, Dict[str, <sphinx.ext.autodoc.importer._MockObject object at 0x7fb3a8116110>]], 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, search: bool = True)

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
  • search (bool) – Search for a column if it wasn’t explicitly provided in the constructor.
Raises:

FittingDataColumnsLengthError – Raised if not all columns have the same length

all_columns

Property of columns list.

Returns:list of all columns
Return type:List[str]
all_records

Get all records in data as a list.

Returns:List of all records
Return type:List[List[Any]]
all_selected() → bool

Checks whether all records are selected.

Returns:True if all records are selected, False otherwise.
Return type:bool
cell_data(column_name: str, index: int) → float

Get the data of a column.

Parameters:
  • column_name (str) – The header name of the desired cell.
  • index (int) – The index of the desired cell.
Returns:

The value of the cell

Return type:

float

column_data(column_name: Optional[str], only_selected: bool = True) → Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7fb3a8127150>]

Get the data of a column.

Parameters:
  • column_name (str) – The header name of the desired column. if None, return None
  • only_selected (bool) – If true, return only values selected records. otherwise, Return values of all records.
Returns:

The data of the given column

Return type:

numpy.ndarray or None

column_domain(column_name: Optional[str], only_selected: bool = True) → eddington.interval.Interval

Get the smallest interval containing the values in a column.

Parameters:
  • column_name (str) – The desired column name.
  • only_selected (bool) – If true, return only values selected records. otherwise, Return values of all records.
Returns:

Minimal interval containing column values

Return type:

Interval

copy(only_selected_columns: bool = False, only_selected_records: bool = False)

Make a copy of self.

Parameters:
  • only_selected_columns (bool) – If true, copy only columns which are used as x, x error, y and y error columns. Otherwise, copy all columns
  • only_selected_records (bool) – If true, copy only selected records. Otherwise, copy all records.
Returns:

a copy of this fitting data.

Return type:

Fitting Data

data

Data matrix.

Returns:The actual raw data
Return type:OrderedDict
is_selected(index)

Checks if a record is selected or not.

Parameters:index (int) – index of the desired record starting from 1.
Returns:True if record is selected, otherwise False.
Return type:bool
non_selected() → bool

Checks whether no record has been selected.

Returns:True if no record has been selected, False otherwise.
Return type:bool
number_of_columns

Number of columns.

Returns:Number of columns
Return type:int
number_of_records

Number of records.

Returns:Number of records
Return type:int
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, search: bool = True)

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 (str or numpy.ndarray) – Indicates which column should be used as the y error parameter
  • search (bool) – Search for a column if it wasn’t explicitly provided.
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, search: bool = True)

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 (str or numpy.ndarray) – Indicates which column should be used as the y error parameter
  • search (bool) – Search for a column if it wasn’t explicitly provided.
Returns:

FittingData read from the excel file.

Raises:

FittingDataError – Raised when the given sheet do not exist in 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, search: bool = True)

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 (str or numpy.ndarray) – Indicates which column should be used as the y error parameter
  • search (bool) – Search for a column if it wasn’t explicitly provided.
Returns:

FittingData read from the json file.

record_data(index: int) → <sphinx.ext.autodoc.importer._MockObject object at 0x7fb3a8127250>

Get the data of a column.

Parameters:index (int) – The index of the desired record.
Returns:The record
Return type:numpy.ndarray
records

Get all selected records in data as a list.

Returns:records list
records_indices

Property of selected indices.

Returns:List of booleans indicating which records are selected.
Return type:List[bool]
residuals(fit_func, a: Union[List[float], <sphinx.ext.autodoc.importer._MockObject object at 0x7fb3a8116f90>]) → eddington.fitting_data.FittingData

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

Raises:

FittingDataError – Raised when missing x or y column

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.
select_all_records()

Select all records to be used in fitting.

select_by_domains(xmin: Optional[float] = None, xmax: Optional[float] = None, ymin: Optional[float] = None, ymax: Optional[float] = None, update_selected: bool = False) → None

Select records by limiting y values.

Parameters:
  • xmin (float) – Optional. Minimum value for x. If none, will not consider lower bound for x values
  • xmax (float) – Optional. Maximum value for x. If none, will not consider upper bound for x values
  • ymin (float) – Optional. Minimum value for y. If none, will not consider lower bound for y values
  • ymax (float) – Optional. Maximum value for y. If none, will not consider upper bound for y values
  • update_selected (bool) – If true, combine with records which have already been selected. If false, select from all records
select_by_x_domain(xmin: Optional[float] = None, xmax: Optional[float] = None, update_selected: bool = False) → None

Select records by limiting x values.

Parameters:
  • xmin (float) – Optional. Minimum value for x. If none, will not consider lower bound for x values
  • xmax (float) – Optional. Maximum value for x. If none, will not consider upper bound for x values
  • update_selected (bool) – If true, combine with records which have already been selected. If false, select from all records
select_by_y_domain(ymin: Optional[float] = None, ymax: Optional[float] = None, update_selected: bool = False) → None

Select records by limiting y values.

Parameters:
  • ymin (float) – Optional. Minimum value for y. If none, will not consider lower bound for y values
  • ymax (float) – Optional. Maximum value for y. If none, will not consider upper bound for y values
  • update_selected (bool) – If true, combine with records which have already been selected. If false, select from all records
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(column_name: str, index: int, value: float)

Set new value to a cell.

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

FittingDataSetError – Raised when trying to set a cell with non number value

set_header(old_column, new_column)

Rename header.

Parameters:
  • old_column (str) – The old columns name
  • new_column (str) – The new value to set for the header
Raises:

FittingDataSetError – Raised when trying to set a header which is empty or already been set.

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
Raises:FittingDataColumnExistenceError – Raised when unknown column name is given.
statistics_map

Return updated statistics map.

Returns:Statistics map of the data
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.

Returns:columns used dictionary
Return type:Columns
x

Property of the x values.

Returns:values of the x column
Return type:np.ndarray
x_column

Name of the x column.

Returns:The name of the x error column
Return type:str
x_domain

Minimal interval containing the values of the x column.

Returns:x values domain.
Return type:Interval
x_index

Index of the x column.

Returns:Index of the x column
Return type:int
xerr

Property of the x error values.

Returns:values of the x error column
Return type:np.ndarray
xerr_column

Name of the x error column.

Returns:The name of the x error column
Return type:str
xerr_index

Index of the x error column.

Returns:Index of the x error column
Return type:int
y

Property of the y values.

Returns:values of the y column
Return type:np.ndarray
y_column

Name of the y column.

Returns:The name of the y column
Return type:str
y_domain

Minimal interval containing the values of the y column.

Returns:y values domain.
Return type:Interval
y_index

Index of the y column.

Returns:Index of the y column
Return type:int
yerr

Property of the y error values.

Returns:values of the y error column
Return type:np.ndarray
yerr_column

Name of the y error column.

Returns:The name of the y error column
Return type:str
yerr_index

Index of the y error column.

Returns:Index of the y error column
Return type:int