BuildingsPy icon indicating copy to clipboard operation
BuildingsPy copied to clipboard

Load file partially to avoid buffer overload

Open kldjonge opened this issue 5 years ago • 8 comments

Is it possible to only load the .mat file partially? When only wanting to extract a few variables it seems that still the whole .mat file is loaded. This results in a buffer overload error when the .mat file gets to big (e.g. when also the protected variables were stored for debugging purposes) which might be avoided when only the necessary data is loaded.

I got the inspiration from the optional 'variable_names' argument in de scipy.io.loadmat class. https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.loadmat.html

kldjonge avatar Nov 16 '21 17:11 kldjonge

Did you check if DyMat supports this? Reading the .mat files is done through the DyMat library.

mwetter avatar Nov 16 '21 18:11 mwetter

I checked indeed and it doesn't i'm afraid. DyMat uses the scipy.io.loadmat I mentioned but doesn't use the 'variables _names' option so I think it always loads the whole file.

kldjonge avatar Nov 16 '21 18:11 kldjonge

Hi @kldjonge , Did you find a solution to the buffer error? I have the same issue with larger files: https://github.com/lbl-srg/BuildingsPy/issues/474

Walshest avatar Mar 02 '22 08:03 Walshest

@Walshest, I haven't. DyMat (and later BuildingsPy) should be updated so that the optional argument 'variables_names' of scipy.io.loadmat could be used.

kldjonge avatar Mar 02 '22 09:03 kldjonge

https://stackoverflow.com/questions/70513151/opening-big-result-mat-file-raises-buffer-is-too-small-for-requested-array https://github.com/jraedler/DyMat/issues/4

thorade avatar Mar 02 '22 12:03 thorade

@thorade, indeed, exporting a smaller .MAT file is what I ended up doing. Well, I first simulated and stored all variables (might need them for later analysis or used to check the internal workings of the model/controls) then I plotted the once I needed and exported a .MAT file with only those variables.

This wasn't convient though and is a lot of manual work for bath simulations. It would be nice to be able to load only a subset of the original .MAT file directly in Python. I haven't actually tried this, but as scipy.io.loadmat can do it, probably the fix is not that far away. Although I don't think there is any active developement for DyMat.

kldjonge avatar Mar 03 '22 11:03 kldjonge

Hi @thorade and @kldjonge , Thanks for all of the feedback and suggestions. I can confirm that Variable selections as outlined here: https://stackoverflow.com/questions/70513151/opening-big-result-mat-file-raises-buffer-is-too-small-for-requested-array reduced the size of the simulation file a lot.

However there is still a limitation when we run much longer & complex Modelica simulation e.g. for months/ year of seasonal operation.

  • It would be defiantly beneficial if the BuildingsPy was updated to support these larger files. e.g. only loading variables of interest or resampling of the variables.

Walshest avatar Mar 07 '22 09:03 Walshest

Thanks @Walshest , I agree that it would probably be better to allow BuildingsPy to handle larger results. I will take a look at it.

bravache avatar Mar 07 '22 18:03 bravache