pyrc.postprocessing.parser#
- class FastParser(network_solution_path_tuple: tuple[RCNetwork, str], solution_size=None)#
Bases:
objectClass to process the solutions of an RC-network.
Here all calculations for a single RC-network are performed. Also, this class should make filtering easy and the processing fast without a lot of RAM usage. For this, the calculation should be done in a queue and after this the network solution is removed from the memory to free RAM and only the requested calculation/solution data is kept in memory.
To compare several RCNetwork Solutions use the class
MultiParserwhich processes multiple FastParser instances.- add_filter(name: str = None, return_index=False)#
Adds a new
NetworkFilterobject. It initially filters out everything (empty matrix).The
NetworkFilterobjects are used to create different sets of data using the same data source. You can manipulate the filter/mask using the methods of theNetworkFilterclass.- Parameters:
name (str, optional) – The name of the filter to add. If None, the filter is only accessible by its index.
return_index (bool, optional) – If True the index of the added
NetworkFilteris returned.
- Returns:
If return_index: the index of the just added
NetworkFilterobject that can be used to get the filter using self.filter(index)- Return type:
None | int
- add_node_filter(name: str = None, return_index=False)#
Adds a new
NodeFilterobject. It initially filters out everything (empty matrix).The
NodeFilterobjects are used to create different sets of data using the same data source. You can manipulate the filter/mask using the methods of theNodeFilterclass.- Parameters:
name (str, optional) – The name of the filter to add. If None, the filter is only accessible by its index.
return_index (bool, optional) – If True the index of the added
NodeFilteris returned.
- Returns:
If return_index: the index of the just added
NodeFilterobject that can be used to get the filter using self.filter(index)- Return type:
None | int
- add_time_filter(name: str = None, return_index=False)#
Adds a new
TimeFilterobject. It initially filters out everything (empty matrix).The
TimeFilterobjects are used to create different sets of data using the same data source. You can manipulate the filter/mask using the methods of theTimeFilterclass.- Parameters:
name (str, optional) – The name of the filter to add. If None, the filter is only accessible by its index.
return_index (bool, optional) – If True the index of the added
TimeFilteris returned.
- Returns:
If return_index: the index of the just added
TimeFilterobject that can be used to get the filter using self.filter(index)- Return type:
None | int
- add_time_filters(days=None, weeks=None, months=None, years=None, filter_name_add_on='', return_names=False)#
Adds time filters for all passed days, weeks, months and years.
The time filters are named like “day{index of this day in list}{filter_name_add_on}”. The weeks, months and years are represented by their start day.
If no value is passed no filter is created.
- Parameters:
days (list[datetime] | datetime, optional) – The days that should be plotted.
weeks (list[datetime] | datetime, optional) – The weeks that should be plotted. Each week is represented by its start date.
months (list[datetime] | datetime, optional) – The months that should be plotted. Each month is represented by its start date.
years (list[datetime] | datetime, optional) – The years that should be plotted. Each year is represented by its start date.
filter_name_add_on (str, optional) – A name add-on for the time filter that is added.
return_names (bool, optional) – If True the names of the time filters are returned as dictionary with the entries days, weeks, months and years and the corresponding list.
- Returns:
If return_names, a dict with the layout: {“days”: [], “weeks”: [], “months”: [], “years”: []} with the names of the filters in the lists.
- Return type:
dict | None
- filter(entry: int | Any | str = -1) NetworkFilter | TimeFilter | NodeFilter#
Returns a
Filterobject specified by entry. If entry is not given the lastFilteris used.- Parameters:
entry (int | Any, optional) – If an int the index of the filter in the filter list self._filter. If a string the name of the filter in self._filter_names. Is parsed to an index. If None, the last
Filteris used.
- property filters: list[NetworkFilter | TimeFilter | NodeFilter]#
- free_ram()#
Deletes the network solution from memory without deleting any calculated/filtered/requested data.
- #TODO: Append this function with all variables that are existing in the state of this class containing the
whole solution data. The garbage collection has to be able to free the RAM from the most data!
- property input_vectors#
- load_solution()#
Loads solution, but only if enough RAM is available.
- Raises:
MemoryError : – If not enough memory is available.
- load_solution_safe()#
Like load_solution, but it waits for up to 1 hour for enough RAM.
- Raises:
MemoryError : – If not enough memory is available within 1 hour.
- map(function: Callable, *args, **kwargs)#
Maps the passed function to every filter and returns the result as a tuple.
- Parameters:
function (Callable) – The function to map on every filter. The first argument is a FilteredRCSolution.
- Returns:
The results for each filter.
- Return type:
tuple
- property network_filter: list[NetworkFilter]#
- property node_filter: list[NodeFilter]#
- remove_filter(entry: int | Any = -1)#
Removes the desired filter from the filters list.
Remember: Previously passed filter indexes might change.
- Parameters:
entry (int | Any, optional) – If an int the index of the filter in the filter list self._filter. If a string the name of the filter in self._filter_names. Is parsed to an index. If None, the last filter is used.
- property result_vectors#
- property solution_exist: bool#
- property solution_size#
- property time_filters: list[TimeFilter]#
- property time_vector#
- class FilterMixin(values: list | ndarray, settings: Settings)#
Bases:
Filter- apply_filter(matrix: ndarray, axis=None) ndarray#
Returns the filtered matrix.
This does not save any data to the class so the RAM usage is not affected.
- Parameters:
matrix (np.ndarray) – The matrix to be filtered.
axis (int, optional) – If 0 the mask is applied to the row mask, to the column mask either. If None, it is added to the mask of same length.
- Returns:
The filtered matrix.
- Return type:
np.ndarray
- property filtered_values: ndarray#
- invert()#
Inverts the mask of the given axis.
- class FilteredRCSolution(rc_solution: RCSolution, filter_obj: Filter)#
Bases:
object- __getattr__(item)#
Returns the attribute from RCSolution. But for some attributes it returns the filtered version.
- class MultiParser(objects: list)#
Bases:
objectClass to process multiple solutions of an RC-network (FastParser instances).
It behaves like FastParser, but it always executes all calls to every parser instance defined in the init.
This should be used with brain! Only compare networks with same hashes or with comparable layout.
Objects can be a list of FastParser instances or network solution-path tuples.
- Parameters:
objects (list[FastParser] | list[tuple[RCNetwork, str]]) – These objects are compared to each other (same calculations are done for all of them).
- __init__(objects: list)#
Objects can be a list of FastParser instances or network solution-path tuples.
- Parameters:
objects (list[FastParser] | list[tuple[RCNetwork, str]]) – These objects are compared to each other (same calculations are done for all of them).
- class NetworkFilter(seconds: ndarray, nodes: list[Capacitor], settings: Settings, time_accuracy='ms')#
Bases:
FilterCombines a TimeFilter for the row and a NodeFilter for the columns to one filter.
Initially: filter out everything.
- Parameters:
- __init__(seconds: ndarray, nodes: list[Capacitor], settings: Settings, time_accuracy='ms')#
Initially: filter out everything.
- apply_column_filter(matrix)#
- apply_filter(matrix, axis=None)#
- apply_row_filter(matrix)#
- class NodeFilter(nodes: list[Capacitor] | ndarray, settings: Settings)#
Bases:
FilterMixinInitially: filter out everything.
- Parameters:
- add_nodes(nodes: list[Node] | str)#
Adds the nodes to the current node mask. If string is given, the corresponding group is added.
- apply_filter(matrix: ndarray, axis=1) ndarray#
Returns the filtered matrix.
This does not save any data to the class so the RAM usage is not affected.
- Parameters:
matrix (np.ndarray) – The matrix to be filtered.
axis (int, optional) – If 0 the mask is applied to the row mask, to the column mask either. If None, it is added to the mask of same length.
- Returns:
The filtered matrix.
- Return type:
np.ndarray
- class TimeFilter(seconds: ndarray, settings: Settings, time_accuracy='ms', initial_mask_value=False)#
Bases:
FilterMixinA class that contains the filter for one RCSolution, especially nodes (columns) and dates (rows).
Initially: filter out everything.
- Parameters:
seconds (np.ndarray) – The row index as increasing seconds.
settings (Settings) – The
Settingsobject that matches the settings of the network. Is used to get the start_date and the weather_data_pathtime_accuracy (str, optional) – The time accuracy used in numpy.datetime64 calculations. E.g.: “ms”, “s”, “m”
- __init__(seconds: ndarray, settings: Settings, time_accuracy='ms', initial_mask_value=False)#
Initially: filter out everything.
- Parameters:
seconds (np.ndarray) – The row index as increasing seconds.
settings (Settings) – The
Settingsobject that matches the settings of the network. Is used to get the start_date and the weather_data_pathtime_accuracy (str, optional) – The time accuracy used in numpy.datetime64 calculations. E.g.: “ms”, “s”, “m”
- apply_filter(matrix: ndarray, axis=0) ndarray#
Returns the filtered matrix.
This does not save any data to the class so the RAM usage is not affected.
- Parameters:
matrix (np.ndarray) – The matrix to be filtered.
axis (int, optional) – If 0 the mask is applied to the row mask, to the column mask either. If None, it is added to the mask of same length.
- Returns:
The filtered matrix.
- Return type:
np.ndarray
- daterange(datetime1, datetime2=None)#
Filters rows using a datetime range. The current row mask is overwritten.
If datetime2 is None, the same day is used as end of the range. If datetime2 is not None, the exact datetime is used as end (included). So if you want the same result as with “None” then you have to use datetime1 + np.timedelta64(1, “D”).
- Parameters:
datetime1 (np.datetime64 | datetime.datetime | Any) – The start of the range. Is included in the range. Is converted to np.datetime64.
datetime2 (np.datetime64 | datetime.datetime | Any, optional) – The end of the range. Is included in the range (but with time. So if you want the whole day you have to use the next day at 00:00:00). If None, the same day as datetime1 is used as end of the range. Is converted to np.datetime64.
Examples
- To apply a range of three days:
self.range(datetime(2022,4,1), “2022-04-03”)
which will result in the range 1.4.22 00:00:00 up to 4.4.22 00:00:00.
- property datetime#
Returns the date times from filtered values as vector with datetime.datetime objects (instead of np.datetime64).
- Returns:
Date times of filtered values.
- Return type:
np.ndarray(datetime.datetime)
- class WeatherFilter(settings: Settings)#
Bases:
FilterMixin- property weather: WeatherData#
- parse_direction(direction: ndarray | str) ndarray#
Makes one direction vector out of the input.
- Parameters:
direction
- Returns:
The corresponding array for the string (or numpy array).
- Return type:
np.ndarray