asi_core.matlab_converters

This module provides functions to convert data structures from matlab into python.

Classes

MatlabCamera

Used calibrations etc. are initialized via MATLAB

Functions

map_data_columns(matlab_column_names)

Maps MATLAB-style column names to their corresponding Python-style names using a predefined renaming dictionary.

load_matlab_struct(mat_file, struct_name[, return_df])

Loads matlab struct from mat-file and stores it to python dict or pd.DataFrame.

get_mat_dict(mat_file_path[, suffix])

Import Matlab structure (.mat file) into python dictionary using scipy loadmat.

load_matlab_mesor_file(mat_file[, struct_name, ...])

Loads matlab mesor file. Function for loading irradiance measurements and other meteorological measurements from

load_matlab_linke_turbidity_per_day(tl_files[, ...])

Loads daily linke turbidity values from mat-files.

load_matlab_dni_classes(mat_files[, struct_name, ...])

Loads dni variability classes from mat-files. Precomupted DNI variability classes for each measurement timestamo

load_matlab_persistence_values(mat_files[, norm_max, ...])

Loads matlab persistence values.

load_matlab_ceilometer_data(mat_file[, timestamp_col, ...])

Loads matlab ceilometer values (only the 3 channels for the cloud base height measurement).

pandas_datetime_to_matlab_datenum(date)

Converts a Python datetime object to a MATLAB datenum.

matlab_datenum_to_pandas_datetime(datenum[, round_to, ...])

Convert matlab datenum to pandas datetime.

Module Contents

asi_core.matlab_converters.map_data_columns(matlab_column_names)

Maps MATLAB-style column names to their corresponding Python-style names using a predefined renaming dictionary.

Parameters:

matlab_column_names – List of column names from MATLAB data.

Returns:

A dictionary mapping MATLAB column names to their Python-equivalent names.

asi_core.matlab_converters.load_matlab_struct(mat_file, struct_name, return_df=False)

Loads matlab struct from mat-file and stores it to python dict or pd.DataFrame.

Parameters:
  • mat_file – full path of mat-file.

  • struct_name – name of struct variable in mat-file.

  • return_df – if true, parameters are renamed to new format.

Returns:

python dict or pd.DataFrame of data stored in struct variable of mat-file.

asi_core.matlab_converters.get_mat_dict(mat_file_path, suffix=None)

Import Matlab structure (.mat file) into python dictionary using scipy loadmat.

The method is very similar to load_matlab_struct and is deprecated.

Parameters:
  • (string) (mat_file_path) – Path to Matlab file

  • optional) (suffix (string,) – Add suffix to key names

Returns:

Dictionary containing Matlab struture data

asi_core.matlab_converters.load_matlab_mesor_file(mat_file, struct_name='MesorDat', param_tz=MATLAB_TZ, param_datenum=MATLAB_DATENUM, convert_timezone=None, rename_params=False, drop_datenum=True)
Loads matlab mesor file. Function for loading irradiance measurements and other meteorological measurements from

a mat-file containing single struct (‘MesorDat’) to python dict or pandas dataframe.

Parameters:
  • mat_file – full path of mat-file.

  • struct_name – name of struct variable in mat-file.

  • param_tz – name of timezone parameter.

  • param_datenum – name of matlab datenum parameter.

  • convert_timezone – timezone value (+/- UTC) to convert date times.

  • rename_params – if true, parameters are renamed to new format.

  • drop_datenum – drop matlab datenum data.

Returns:

python dict of mesor data.

asi_core.matlab_converters.load_matlab_linke_turbidity_per_day(tl_files, struct_name='tl_data', param_name_tl='tl_per_day', param_name_dt='SDN_per_day')

Loads daily linke turbidity values from mat-files.

Parameters:
  • tl_files – list of full paths of mat-files containing turbidity data.

  • struct_name – name of struct variable in mat-files.

  • param_name_tl – name of daily turbididty parameter.

  • param_name_dt – name of datetime (datenum) parameter.

Returns:

pd.Series of daily Linke turbidity values.

asi_core.matlab_converters.load_matlab_dni_classes(mat_files, struct_name='DNIClass', param_dni_class=MATLAB_DNIVARCLASS, param_dt=MATLAB_SDN, param_tz=MATLAB_TZ, convert_timezone=None, rename_params=False)

Loads dni variability classes from mat-files. Precomupted DNI variability classes for each measurement timestamo (https://doi.org/10.1127/metz/2018/0875) are loaded from mat-files and concatenated into single pandas dataframe.

Parameters:
  • mat_files – list of full paths of mat-files.

  • struct_name – name of struct variable in mat-files.

  • param_dni_class – name of dni variability class parameter.

  • param_dt – name of datetime (datenum) parameter.

  • param_tz – name of timezone parameter.

  • convert_timezone – timezone value (+/- UTC) to convert date times.

  • rename_params – if true, parameters are renamed to new format.

Returns:

pd.DataFrame of DNI variabilty classes.

asi_core.matlab_converters.load_matlab_persistence_values(mat_files, norm_max=None, norm_min=None, stand_mean=None, stand_std=None, param_dt=MATLAB_SDN, persist_col='nowGHIPer', timezone=1, convert_timezone=None)

Loads matlab persistence values.

Parameters:
  • mat_files – list of full paths of mat-files.

  • norm_max – max value to normalize persistence values (optional).

  • norm_min – min value to standardize persistence values (optional).

  • stand_mean – mean value to standardize persistence values (optional).

  • stand_std – std value to standardize persistence values (optional).

  • param_dt – name of datetime (datenum) parameter.

  • persist_col – name of persistence column.

  • timezone – timezone as integer (+/- UTC).

  • convert_timezone – timezone value (+/- UTC) to convert date times.

Returns:

pd.DataFrame of persistence values.

asi_core.matlab_converters.load_matlab_ceilometer_data(mat_file, timestamp_col='time', cloud_base_height_col='cloud_base_height', timezone=pytz.UTC)

Loads matlab ceilometer values (only the 3 channels for the cloud base height measurement).

Parameters:
  • mat_file – full path of mat file.

  • timestamp_col – name of column with timestamps

  • cloud_base_height_col – name of column with cloud base height measurements

:param timezone as pytz timezone or as integer (+/- UTC).

asi_core.matlab_converters.pandas_datetime_to_matlab_datenum(date)

Converts a Python datetime object to a MATLAB datenum.

Parameters:

date – Pandas datetime series to be converted.

Returns:

Pandas series with MATLAB datenum floats.

asi_core.matlab_converters.matlab_datenum_to_pandas_datetime(datenum, round_to='s', timezone=None, convert_timezone=None)

Convert matlab datenum to pandas datetime.

Parameters:
  • datenum – matlab datenum values.

  • round_to – abbreviation to round values (default: ‘s’ -> second).

  • timezone – implicit timezone of inserted matlab datenum timestamps or pytz.timezone. If not provided, the returned timestamps will be timezone unaware: UTC –> 0; CET –> +1; CEST –> +2

  • convert_timezone – timestamps will be returned in this timezone if specified: UTC –> 0; CET –> +1; CEST –> +2

Returns:

pd.DatetimeIndex of timestamps.

class asi_core.matlab_converters.MatlabCamera(path_matlab_workspace)

Bases: asi_core.camera.RadiometricImager

Used calibrations etc. are initialized via MATLAB

This class can be useful for testing.

camera_mask
rel_exp_tol = 0.1
load_ocam(ocam_path)

Load ocam model from mat-file.