def list2array(self): """ Set internal storage for timeseries data. Open file and read data into internal storage. """ Model.list2array(self) # read and store data for ii in range(self.n): idx = self.idx.v[ii] path = self.path.v[ii] sheet = self.sheet.v[ii] try: df = pd.read_excel(path, sheet_name=sheet) except FileNotFoundError as e: logger.error('<%s idx=%s>: File not found: "%s"', self.class_name, idx, path) raise e except ValueError as e: logger.error('<%s idx=%s>: Sheet not found: "%s" in "%s"', self.class_name, idx, sheet, path) raise e for field in self.fields.v[ii]: if field not in df.columns: raise ValueError('Field {} not found in timeseries data'.format(field)) self._data[idx] = df
def list2array(self): """ Set internal storage for timeseries data. Open file and read data into internal storage. """ # TODO: timeseries file must exist for setup to pass. Consider moving # the file reading to a later stage so that adding sheets to xlsx file can work # without the file existing. Model.list2array(self) # read and store data for ii in range(self.n): idx = self.idx.v[ii] path = self.path.v[ii] sheet = self.sheet.v[ii] if not os.path.isabs(path): path = os.path.join(self.system.files.case_path, path) if not os.path.exists(path): raise FileNotFoundError('<%s idx=%s>: File not found: "%s"', self.class_name, idx, path) # --- read supported formats --- if path.endswith("xlsx") or path.endswith("xls"): df = self._read_excel(path, sheet, idx) elif path.endswith("csv"): df = pd.read_csv(path) for field in self.fields.v[ii]: if field not in df.columns: raise ValueError( 'Field {} not found in timeseries data'.format(field)) self._data[idx] = df logger.info('Read timeseries data from "%s"', path)