Commit d46167a6 authored by Feliks Kuba Kiszkurno's avatar Feliks Kuba Kiszkurno
Browse files

Bug fix in the jupyter noteook

parent 8c75504d
%% Cell type:markdown id: tags:
#### OGS-Data-Compare - Example
Importing os package is in general optional, but required for this notebook.
%% Cell type:code id: tags:
``` python
from ogs_compare import OGSDataCompare
import os
```
%% Cell type:markdown id: tags:
Minimal example of settings dictionary:
%% Cell type:code id: tags:
``` python
settings = {'parameter': 'pressure',
'path': os.path.join(os.path.join(os.getcwd(), 'Data')),
'points_file': os.path.join(os.getcwd(), 'Data' 'points.csv')
}
```
%% Cell type:markdown id: tags:
Folder defined in 'path' contains subfolders - one for each experiment with one pvd file in each:
%% Cell type:code id: tags:
``` python
os.system('ls {}'.format(settings['path']))
```
%% Output
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 os.process('ls {}'.format(settings['path']))
AttributeError: module 'os' has no attribute 'process'
d_1.50_erm_020
d_1.50_erm_025
d_1.50_erm_030
d_1.50_erm_035
d_1.50_erm_040
d_1.50_erm_045
d_1.50_erm_050
d_1.50_erm_060
points.csv
Results
0
%% Cell type:markdown id: tags:
List of observation points has to be provided as csv file. Now it contains 16 points. This matches current setup of ogs_compare() method, but it can be modified.
%% Cell type:code id: tags:
``` python
os.system('ls -n 4 {}'.format(settings['points_file']))
```
%% Output
ls: cannot access '4': No such file or directory
ls: cannot access '/home/kiszkurn/Dev/ogs-data-compare/Documentation/Example/Datapoints.csv': No such file or directory
512
%% Cell type:markdown id: tags:
Initialise OGSDataCompare object let it read data
%% Cell type:code id: tags:
``` python
data_compare = OGSDataCompare(settings)
data_compare.read_data()
```
%% Output
Following mandatory fields are missing:
[]
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Input In [8], in <cell line: 1>()
----> 1 data_compare = OGSDataCompare(settings)
2 data_compare.read_data()
File ~/Dev/ogs-data-compare/ogs_compare/ogs_compare.py:40, in OGSDataCompare.__init__(self, settings)
37 self.__read_config(settings)
38 self.config.output_path = os.path.join(self.config.path, 'Results')
---> 40 self.points = self.read_points()
42 self.data = types.SimpleNamespace()
43 self.data.experiments = None
File ~/Dev/ogs-data-compare/ogs_compare/ogs_compare.py:50, in OGSDataCompare.read_points(self)
49 def read_points(self):
---> 50 points = load_points(self.config.points_file)
52 if self.config.points_plot is True:
53 plot_points(points, self.config.path)
File ~/Dev/ogs-data-compare/ogs_compare/Tools/points.py:32, in load_points(file_path)
15 '''
16 Load list of points from csv files exported from Paraview into format
17 acceptable by vtuIO
(...)
28
29 '''
30 points = {}
---> 32 points_df = pd.read_csv(file_path)
33 #points_df = points_df.sort_values(by=["Points_Magnitude"], ascending=True)
34 points_x = points_df["Points_0"].to_numpy()
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/util/_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
305 if len(args) > num_allow_args:
306 warnings.warn(
307 msg.format(arguments=arguments),
308 FutureWarning,
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/io/parsers/readers.py:680, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
665 kwds_defaults = _refine_defaults_read(
666 dialect,
667 delimiter,
(...)
676 defaults={"delimiter": ","},
677 )
678 kwds.update(kwds_defaults)
--> 680 return _read(filepath_or_buffer, kwds)
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/io/parsers/readers.py:575, in _read(filepath_or_buffer, kwds)
572 _validate_names(kwds.get("names", None))
574 # Create the parser.
--> 575 parser = TextFileReader(filepath_or_buffer, **kwds)
577 if chunksize or iterator:
578 return parser
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/io/parsers/readers.py:933, in TextFileReader.__init__(self, f, engine, **kwds)
930 self.options["has_index_names"] = kwds["has_index_names"]
932 self.handles: IOHandles | None = None
--> 933 self._engine = self._make_engine(f, self.engine)
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/io/parsers/readers.py:1217, in TextFileReader._make_engine(self, f, engine)
1213 mode = "rb"
1214 # error: No overload variant of "get_handle" matches argument types
1215 # "Union[str, PathLike[str], ReadCsvBuffer[bytes], ReadCsvBuffer[str]]"
1216 # , "str", "bool", "Any", "Any", "Any", "Any", "Any"
-> 1217 self.handles = get_handle( # type: ignore[call-overload]
1218 f,
1219 mode,
1220 encoding=self.options.get("encoding", None),
1221 compression=self.options.get("compression", None),
1222 memory_map=self.options.get("memory_map", False),
1223 is_text=is_text,
1224 errors=self.options.get("encoding_errors", "strict"),
1225 storage_options=self.options.get("storage_options", None),
1226 )
1227 assert self.handles is not None
1228 f = self.handles.handle
File ~/Dev/ogs-data-compare/venv2/lib64/python3.8/site-packages/pandas/io/common.py:789, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
784 elif isinstance(handle, str):
785 # Check whether the filename is to be opened in binary mode.
786 # Binary mode does not support 'encoding' and 'newline'.
787 if ioargs.encoding and "b" not in ioargs.mode:
788 # Encoding
--> 789 handle = open(
790 handle,
791 ioargs.mode,
792 encoding=ioargs.encoding,
793 errors=errors,
794 newline="",
795 )
796 else:
797 # Binary mode
798 handle = open(handle, ioargs.mode)
FileNotFoundError: [Errno 2] No such file or directory: '/home/kiszkurn/Dev/ogs-data-compare/Documentation/Example/Datapoints.csv'
%% Cell type:markdown id: tags:
Now all plotting methods can be used:
%% Cell type:code id: tags:
``` python
data_compare.ogs_compare()
```
%% Cell type:code id: tags:
``` python
data_compare.ogs_compare_separate()
```
%% Cell type:code id: tags:
``` python
data_compare.ogs_compare_time_point(time_step=[2.3, 2.5, 2.7])
```
%% Cell type:code id: tags:
``` python
data_compare.ogs_compare_3d_view(time_step=[2.3, 2.5, 2.7])
```
%% Cell type:markdown id: tags:
Method plot_min_max() is slightly different. It uses different data input than the other ones, so method to read data has to be called first:
%% Cell type:code id: tags:
``` python
data_compare.read_data_full()
data_compare.plot_min_max()
```
%% Cell type:markdown id: tags:
All figures are stored in the "Results" folder:
%% Cell type:code id: tags:
``` python
os.system('ls {}'.format(os.path.join(os.getcwd(), settings['path'], 'Results')))
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment