Tabular Data¶
Tabular data is data usually stored in spreadsheets. It can contain important information about subject background and performance. In large projects there may be several hundreds of variables, and a very wide spreadsheet would be required to store them.
Data is stored in a structure that can be viewed as a table. The first column would contain the ids of the subjects in the study, and the first row would contain the variable names. The values of the variables would be stored in the rest of the table.
Real variables are stored as float numbers, and the metadata contains the minimum, maximum and optimal value for each variable. This parameters can be modified by the subject, and it is not enforced that values lay in this range, however applications may check this and give warnings if there is an inconsistency. This metadata is also useful for plotting.
Nominal variables are stored as numerical labels. Metadata contains a table that maps numerical labels to strings. Which
can be accessed with the function get_labels_dict()
, for example
>>> get_labels_dict(4)
{
1 : "male" ,
2 : "female" ,
}
Several of the functions in this module return instances of pandas.DataFrame
.
Subjects¶
Modify¶
-
recursive_delete_subject
(*args, **kwargs)[source]¶ Deletes a subject from the database
Warning
This may affect large amounts of information and can’t be reversed
Some references to the variable may remain in scenario data, subsamples or outside the database. There must not exist any geometrical structure (see
geom_db
) associated with the subject, if that is the case the operation will be aborted without modifying the database.Parameters: var_idx (int) – Variable index
Variables¶
Read¶
-
get_variables
(mask=None)[source]¶ Gets available variables
Parameters: mask (str) – If not None, limit answer to results whose name match the given mask (sql like
syntax)Returns: pandas.DataFrame
with variable indexes as index, and a single column with variable names
-
get_var_idx
(var_name)[source]¶ Index of variable with given name
Parameters: var_name (str) – Variable name Returns: Index of variable with the given name if it exists, None
otherwise
Values¶
Read¶
-
get_data_frame_by_index
(columns, col_name_index=False)[source]¶ A data frame containing one column for each variable index in columns
Parameters: columns (list) – Variable indexes Returns: pandas.DataFrame
with subject ids as index and one column for each variable
-
get_data_frame_by_name
(columns)[source]¶ A data frame containing one column for each variable name in columns
Parameters: columns (list) – Variable names Returns: pandas.DataFrame
with subject ids as index and one column for each variable
-
get_laterality
(subj_id)[source]¶ Gets the laterality for a given subject
Parameters: subj_id – The id of the subject Returns: “l” for a left handed subject, “r” otherwise
-
get_var_value
(*args, **kwargs)[source]¶ Gets a single variable value
Parameters: - var_idx (int) – Variable index
- subject – Subject id
Returns: The numerical value for the given variable and subject
-
get_subject_variables
(subj_code, var_codes)[source]¶ Get several values for one subjects
Parameters: - subj_code – Subject id
- var_codes (list) – Variable codes
Returns: pandas.DataFrame
with two columns – Variable name, and variable value; for each index in var_codes, which will be used as indexes in the DataFrame.
Modify¶
-
update_variable_value
(*args, **kwargs)[source]¶ Updates a single value for a variable and a subject
Parameters: - var_idx (int) – Variable index
- subject – Subject id
- new_value – Value to be saved
-
update_multiple_variable_values
(*args, **kwargs)[source]¶ Updates values for variables and subjects
Parameters: idx_subject_value_tuples (list) – Tuples of the form (var_idx, subject, value)
where var_idx and subject are the variable and subject for whom the new value will be set.
-
update_variable_values
(*args, **kwargs)[source]¶ Updates values for one variable and some subjects
Parameters:
-
add_data_frame
(*args, **kwargs)[source]¶ Inserts a whole dataframe into the database
Parameters: - df (pandas.DataFrame) – DataFrame with subject ids as index, and one column for each new variable.
- callback (func) – Called after each row with the index of the current column as argument, can be used for example to update a progress bar
Metadata¶
Read¶
-
is_variable_real
(var_idx)[source]¶ Find if the variable is real or nominal
Parameters: var_idx (int) – Variable index Returns: False
if the variable is Nominal,True
otherwise
-
is_variable_nominal
(var_idx)[source]¶ Find if the variable is real or nominal
Parameters: var_idx (int) – Variable index Returns: True
if the variable is Nominal,False
otherwise
-
is_variable_name_real
(var_name)[source]¶ Find if the variable is real or nominal
Parameters: var_name (str) – Variable name Returns: False
if the variable is Nominal,True
otherwise
-
is_variable_name_nominal
(var_name)[source]¶ Find if the variable is real or nominal
Parameters: var_name (str) – Variable name Returns: True
if the variable is Nominal,False
otherwise
-
are_variables_real
(var_idxs)[source]¶ For each variable in a list, find if it is real
Parameters: var_idxs (list) – variable indexes Returns: A dictionary with variable indexes as keys, and booleans as values as in is_variable_real()
-
are_variables_nominal
(var_idxs)[source]¶ For each variable in a list, find if it is real
Parameters: var_idxs (list) – variable indexes Returns: A dictionary with variable indexes as keys, and booleans as values as in is_variable_nominal()
-
are_variables_names_real
(var_names)[source]¶ For each variable in a list, find if it is real
Parameters: var_names (list) – variable names Returns: A dictionary with variable names as keys, and booleans as values as in is_variable_name_real()
-
are_variables_names_nominal
(var_names)[source]¶ For each variable in a list, find if it is real
Parameters: var_names (list) – variable names Returns: A dictionary with variable names as keys, and booleans as values as in is_variable_name_nominal()
-
get_labels_dict
(var_idx=None, var_name=None)[source]¶ Map numerical labels to strings in nominal variables
Parameters: var_idx (int) – Variable Index Returns: A dictionary with numerical labels as keys, and the text for each label as values.
-
get_labels_dict_by_name
(var_name)[source]¶ Map numerical labels to strings in nominal variables
Parameters: var_name (str) – Variable name Returns: A dictionary with numerical labels as keys, and the text for each label as values.
-
get_minimum_value
(var_idx)[source]¶ Gets the minimum value for a real variable as recorded in meta-data
If there is no metadata, it is calculated from the existing values
Parameters: var_idx (int) – Variable index Returns: Minimum values as recorded in the metadata, if there is no metadata, minimum from existing values.
-
get_maximum_value
(var_idx)[source]¶ Gets the maximum value for a real variable as recorded in meta-data
If there is no metadata, it is calculated from the existing values
Parameters: var_idx (int) – Variable index Returns: Maximum values as recorded in the metadata, if there is no metadata, maximum from existing values.
-
get_min_max_values
(var_idx)[source]¶ Gets the minimum and maximum values for a real variable as recorded in meta-data
If there is no metadata, they are calculated from the existing values
Parameters: var_idx (int) – Variable index Returns: (min_val, max_val)
values as recorded in the metadata, if there is no metadata, they are calculated from existing values
-
get_min_max_values_by_name
(var_name)[source]¶ Gets the minimum and maximum values for a real variable as recorded in meta-data
If there is no metadata, they are calculated from the existing values
Parameters: var_name (str) – Variable name Returns: (min_val, max_val)
values as recorded in the metadata, if there is no metadata, they are calculated from existing values
-
get_min_max_opt_values_by_name
(var_name)[source]¶ Gets the minimum, maximum and optimal values for a real variable as recorded in meta-data
If there is no metadata, they are calculated from the existing values
Parameters: var_name (str) – Variable name Returns: (min_val, max_val, optimum_val)
values as recorded in the metadata, if there is no metadata, they are calculated from existing values. In this case the optimum will be the mean of existing values.
-
get_var_description
(var_idx)[source]¶ Get description for a variable
Parameters: var_idx (int) – Variable index Returns: A string containing the description of the variable.