Skip to content
Snippets Groups Projects
Commit 86d05f04 authored by Luise Odenthal's avatar Luise Odenthal
Browse files

flake8 test database init

parent 5ca49f90
No related branches found
No related tags found
No related merge requests found
...@@ -91,7 +91,7 @@ def adapt_array(arr): ...@@ -91,7 +91,7 @@ def adapt_array(arr):
""" """
http://stackoverflow.com/a/31312102/190597 (SoulNibbler) http://stackoverflow.com/a/31312102/190597 (SoulNibbler)
""" """
if array is None: if arr is None:
raise ValueError('array must not be None') raise ValueError('array must not be None')
out = io.BytesIO() out = io.BytesIO()
np.save(out, arr) np.save(out, arr)
...@@ -123,11 +123,13 @@ It creates three sql table on initialisation. ...@@ -123,11 +123,13 @@ It creates three sql table on initialisation.
"""Initialisation of the database """ """Initialisation of the database """
if not isinstance(filename, str): if not isinstance(filename, str):
raise TypeError('filename should be a string') raise TypeError('filename should be a string')
if (not isinstance(channels, list) or not isinstance(channels,np.array)): if (not isinstance(channels, list) or
not isinstance(channels, np.array)):
raise TypeError('nb_channel should be a list or np array') raise TypeError('nb_channel should be a list or np array')
"""for c in channels: """for c in channels:
if not c in ['R','G','B','D']: if not c in ['R','G','B','D']:
raise ValueError('channels must be either R,G,B or D (Distance)')""" raise ValueError('channels
must be either R,G,B or D (Distance)')"""
self.filename = filename self.filename = filename
self.channels = channels self.channels = channels
self.normalisation_columns = list() self.normalisation_columns = list()
...@@ -159,8 +161,8 @@ It creates three sql table on initialisation. ...@@ -159,8 +161,8 @@ It creates three sql table on initialisation.
self.db_cursor = self.db.cursor() self.db_cursor = self.db.cursor()
for tablename, _ in self.tablecolumns.items(): for tablename, _ in self.tablecolumns.items():
if not self.table_exist(tablename): if not self.table_exist(tablename):
raise Exception('{} does not contain a table named {}'.format( raise Exception('{} does not contain a table\
filename, tablename)) named {}'.format(filename, tablename))
elif self.create: elif self.create:
# Create database # Create database
self.db = sqlite3.connect( self.db = sqlite3.connect(
...@@ -196,7 +198,7 @@ It creates three sql table on initialisation. ...@@ -196,7 +198,7 @@ It creates three sql table on initialisation.
return bool(self.db_cursor.fetchone()) return bool(self.db_cursor.fetchone())
def check_data_validity(self, rowid): def check_data_validity(self, rowid):
if not isinstance(rowid,int): if not isinstance(rowid, int):
raise TypeError('rowid must be an integer') raise TypeError('rowid must be an integer')
if rowid <= 0: if rowid <= 0:
raise ValueError('rowid must be greater zero') raise ValueError('rowid must be greater zero')
...@@ -226,8 +228,8 @@ It creates three sql table on initialisation. ...@@ -226,8 +228,8 @@ It creates three sql table on initialisation.
return valid return valid
def get_posid(self, posorient): def get_posid(self, posorient):
if no isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series') raise TypeError('posorient should be a pandas Series')
if posorient is not None: if posorient is not None:
if not isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series') raise TypeError('posorient should be a pandas Series')
...@@ -313,11 +315,13 @@ class DataBaseLoad(DataBase): ...@@ -313,11 +315,13 @@ class DataBaseLoad(DataBase):
"""Initialise the DataBaseLoader""" """Initialise the DataBaseLoader"""
if not isinstance(filename, str): if not isinstance(filename, str):
raise TypeError('filename should be a string') raise TypeError('filename should be a string')
if (not isinstance(channels, list) or not isinstance(channels,np.array)): if (not isinstance(channels, list) or
not isinstance(channels, np.array)):
raise TypeError('nb_channel should be a list or np array') raise TypeError('nb_channel should be a list or np array')
for c in channels: for c in channels:
if not c in ['R','G','B','D']: if c not in ['R', 'G', 'B', 'D']:
raise ValueError('channels must be either R,G,B or D (Distance)') raise ValueError('channels must be either\
R,G,B or D (Distance)')
DataBase.__init__(self, filename, channels=channels) DataBase.__init__(self, filename, channels=channels)
@property @property
...@@ -356,7 +360,7 @@ database ...@@ -356,7 +360,7 @@ database
return posorient return posorient
def read_posorient(self, posorient=None, rowid=None): def read_posorient(self, posorient=None, rowid=None):
if no isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series') ('posorient should be a pandas Series')
if posorient is not None: if posorient is not None:
if not isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
...@@ -375,15 +379,15 @@ database ...@@ -375,15 +379,15 @@ database
raise ValueError('missing index alpha_1') raise ValueError('missing index alpha_1')
if 'alpha_2' not in posorient.index: if 'alpha_2' not in posorient.index:
raise ValueError('missing index alpha_2') raise ValueError('missing index alpha_2')
if not ~np.any(pd.isnull(posorient)): if np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan') raise ValueError('posorient must not contain nan')
if not isinstance(rowid,int): if not isinstance(rowid, int):
raise TypeError('rowid must be an integer') raise TypeError('rowid must be an integer')
if rowid <= 0: if rowid <= 0:
raise ValueError('rowid must be greater zero') raise ValueError('rowid must be greater zero')
if rowid is np.nan: if rowid is np.nan:
raise ValueError('rowid must not be nan') raise ValueError('rowid must not be nan')
if (posorient is None) and (rowid is None): if (posorient is None) and (rowid is None):
Exception('posorient and rowid can not be both None') Exception('posorient and rowid can not be both None')
if posorient is not None: if posorient is not None:
rowid = self.get_posid(posorient) rowid = self.get_posid(posorient)
...@@ -402,7 +406,7 @@ database ...@@ -402,7 +406,7 @@ database
return toreturn return toreturn
def read_image(self, posorient=None, rowid=None): def read_image(self, posorient=None, rowid=None):
if no isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series') ('posorient should be a pandas Series')
if posorient is not None: if posorient is not None:
if not isinstance(posorient, pd.Series): if not isinstance(posorient, pd.Series):
...@@ -421,9 +425,9 @@ database ...@@ -421,9 +425,9 @@ database
raise ValueError('missing index alpha_1') raise ValueError('missing index alpha_1')
if 'alpha_2' not in posorient.index: if 'alpha_2' not in posorient.index:
raise ValueError('missing index alpha_2') raise ValueError('missing index alpha_2')
if not ~np.any(pd.isnull(posorient)): if np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan') raise ValueError('posorient must not contain nan')
if not isinstance(rowid,int): if not isinstance(rowid, int):
raise TypeError('rowid must be an integer') raise TypeError('rowid must be an integer')
if rowid <= 0: if rowid <= 0:
raise ValueError('rowid must be greater zero') raise ValueError('rowid must be greater zero')
...@@ -463,7 +467,7 @@ database ...@@ -463,7 +467,7 @@ database
FROM {} FROM {}
WHERE (rowid={}) WHERE (rowid={})
""".format(tablename, rowid), self.db) """.format(tablename, rowid), self.db)
if cmaxminrange.shape[0] != 1: if cmaxminrange.shape[0] != 1:
raise Exception('Error while reading normalisation factors') raise Exception('Error while reading normalisation factors')
cmaxminrange = cmaxminrange.iloc[0, :] cmaxminrange = cmaxminrange.iloc[0, :]
cmaxminrange.name = cmaxminrange.id cmaxminrange.name = cmaxminrange.id
...@@ -475,19 +479,23 @@ database ...@@ -475,19 +479,23 @@ database
if len(image.shape) != 3: if len(image.shape) != 3:
raise Exception('image should be 3D array') raise Exception('image should be 3D array')
if image.shape[2] != len(self.channels): if image.shape[2] != len(self.channels):
raise Exception('image does not have the required number of channels {}'.format( raise Exception('image does not have the required\
number of channels {}'.format(
len(self.channels))) len(self.channels)))
if not isinstance(cmaxminrange, pd.Series): if not isinstance(cmaxminrange, pd.Series):
raise Exception('cmaxminrange should be a pandas Series') raise Exception('cmaxminrange should be a pandas Series')
if cmaxminrange.empty: if cmaxminrange.empty:
raise Exception('cmaxminrange must not be empty') raise Exception('cmaxminrange must not be empty')
for chan_n in self.channels: for chan_n in self.channels:
if str(chan_n) + '_max' not in posorient.index: if str(chan_n) + '_max' not in cmaxminrange.index:
raise ValueError('cminmax range is missing index '+str(chan_n) + '_max') raise ValueError('cminmax range is missing index '
if str(chan_n) + '_min' not in posorient.index: + str(chan_n) + '_max')
raise ValueError('cminmax range is missing index '+str(chan_n) + '_min') if str(chan_n) + '_min' not in cmaxminrange.index:
if str(chan_n) + '_range' not in posorient.index: raise ValueError('cminmax range is missing index '
raise ValueError('cminmax range is missing index '+str(chan_n) + '_range') + str(chan_n) + '_min')
if str(chan_n) + '_range' not in cmaxminrange.index:
raise ValueError('cminmax range is missing index '
+ str(chan_n) + '_range')
if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_max'])): if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_max'])):
raise ValueError('cmaxminrange contains nans') raise ValueError('cmaxminrange contains nans')
if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_min'])): if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_min'])):
...@@ -575,15 +583,16 @@ class DataBaseSave(DataBase): ...@@ -575,15 +583,16 @@ class DataBaseSave(DataBase):
self.db.commit() self.db.commit()
def normalise_image(self, image, dtype=np.uint8): def normalise_image(self, image, dtype=np.uint8):
if not isinstance(image,np.ndarray): if not isinstance(image, np.ndarray):
raise TypeError('image must be np.array') raise TypeError('image must be np.array')
if any(np.isnan(image)): if any(np.isnan(image)):
raise ValueError('image must not contain nan values') raise ValueError('image must not contain nan values')
if image.shape[0]<=0 or image.shape[1]<=0: if image.shape[0] <= 0 or image.shape[1] <= 0:
raise Exception('image dimensions incorrect') raise Exception('image dimensions incorrect')
if image.shape[2]!=len(self.channels): if image.shape[2] != len(self.channels):
raise Exception('image channels number differs from given channel number') raise Exception('image channels number differs from\
if not tools.is_numeric_array(scene): given channel number')
if not tools.is_numeric_array(image):
raise TypeError('scene is of non numeric type') raise TypeError('scene is of non numeric type')
normed_im = np.zeros(image.shape, dtype=dtype) normed_im = np.zeros(image.shape, dtype=dtype)
maxval_nim = np.iinfo(normed_im.dtype).max maxval_nim = np.iinfo(normed_im.dtype).max
......
...@@ -84,12 +84,15 @@ import pandas as pd ...@@ -84,12 +84,15 @@ import pandas as pd
import sqlite3 import sqlite3
import io import io
import warnings import warnings
import navipy.processing.tools as tools
def adapt_array(arr): def adapt_array(arr):
""" """
http://stackoverflow.com/a/31312102/190597 (SoulNibbler) http://stackoverflow.com/a/31312102/190597 (SoulNibbler)
""" """
if array is None:
raise ValueError('array must not be None')
out = io.BytesIO() out = io.BytesIO()
np.save(out, arr) np.save(out, arr)
out.seek(0) out.seek(0)
...@@ -97,6 +100,8 @@ def adapt_array(arr): ...@@ -97,6 +100,8 @@ def adapt_array(arr):
def convert_array(text): def convert_array(text):
if text is None:
raise ValueError('text must not be None')
out = io.BytesIO(text) out = io.BytesIO(text)
out.seek(0) out.seek(0)
return np.load(out) return np.load(out)
...@@ -118,8 +123,13 @@ It creates three sql table on initialisation. ...@@ -118,8 +123,13 @@ It creates three sql table on initialisation.
"""Initialisation of the database """ """Initialisation of the database """
if not isinstance(filename, str): if not isinstance(filename, str):
raise TypeError('filename should be a string') raise TypeError('filename should be a string')
if not isinstance(channels, list): if (not isinstance(channels, list) or
raise TypeError('nb_channel should be an integer') not isinstance(channels, np.array)):
raise TypeError('nb_channel should be a list or np array')
"""for c in channels:
if not c in ['R','G','B','D']:
raise ValueError('channels
must be either R,G,B or D (Distance)')"""
self.filename = filename self.filename = filename
self.channels = channels self.channels = channels
self.normalisation_columns = list() self.normalisation_columns = list()
...@@ -150,9 +160,9 @@ It creates three sql table on initialisation. ...@@ -150,9 +160,9 @@ It creates three sql table on initialisation.
timeout=10) timeout=10)
self.db_cursor = self.db.cursor() self.db_cursor = self.db.cursor()
for tablename, _ in self.tablecolumns.items(): for tablename, _ in self.tablecolumns.items():
assert self.table_exist(tablename),\ if not self.table_exist(tablename):
'{} does not contain a table named {}'.format( raise Exception('{} does not contain a table\
filename, tablename) named {}'.format(filename, tablename))
elif self.create: elif self.create:
# Create database # Create database
self.db = sqlite3.connect( self.db = sqlite3.connect(
...@@ -177,7 +187,8 @@ It creates three sql table on initialisation. ...@@ -177,7 +187,8 @@ It creates three sql table on initialisation.
self.viewing_directions[..., 1] = ma self.viewing_directions[..., 1] = ma
def table_exist(self, tablename): def table_exist(self, tablename):
assert isinstance(tablename, str), 'tablename should be a string' if not isinstance(tablename, str):
raise TypeError('tablename should be a string')
self.db_cursor.execute( self.db_cursor.execute(
""" """
SELECT count(*) SELECT count(*)
...@@ -187,6 +198,12 @@ It creates three sql table on initialisation. ...@@ -187,6 +198,12 @@ It creates three sql table on initialisation.
return bool(self.db_cursor.fetchone()) return bool(self.db_cursor.fetchone())
def check_data_validity(self, rowid): def check_data_validity(self, rowid):
if not isinstance(rowid, int):
raise TypeError('rowid must be an integer')
if rowid <= 0:
raise ValueError('rowid must be greater zero')
if rowid is np.nan:
raise ValueError('rowid must not be nan')
self.db_cursor.execute( self.db_cursor.execute(
""" """
SELECT count(*) SELECT count(*)
...@@ -211,8 +228,27 @@ It creates three sql table on initialisation. ...@@ -211,8 +228,27 @@ It creates three sql table on initialisation.
return valid return valid
def get_posid(self, posorient): def get_posid(self, posorient):
assert isinstance(posorient, pd.Series),\ if not isinstance(posorient, pd.Series):
'posorient should be a pandas Series' raise TypeError('posorient should be a pandas Series')
if posorient is not None:
if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series')
if posorient.empty:
raise Exception('position must not be empty')
if 'x' not in posorient.index:
raise ValueError('missing index x')
if 'y' not in posorient.index:
raise ValueError('missing index y')
if 'z' not in posorient.index:
raise ValueError('missing index z')
if 'alpha_0' not in posorient.index:
raise ValueError('missing index alpha_0')
if 'alpha_1' not in posorient.index:
raise ValueError('missing index alpha_1')
if 'alpha_2' not in posorient.index:
raise ValueError('missing index alpha_2')
if not ~np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan')
where = """x>=? and x<=?""" where = """x>=? and x<=?"""
where += """and y>=? and y<=?""" where += """and y>=? and y<=?"""
where += """and z>=? and z<=?""" where += """and z>=? and z<=?"""
...@@ -277,6 +313,15 @@ class DataBaseLoad(DataBase): ...@@ -277,6 +313,15 @@ class DataBaseLoad(DataBase):
def __init__(self, filename, channels=['R', 'G', 'B', 'D']): def __init__(self, filename, channels=['R', 'G', 'B', 'D']):
"""Initialise the DataBaseLoader""" """Initialise the DataBaseLoader"""
if not isinstance(filename, str):
raise TypeError('filename should be a string')
if (not isinstance(channels, list) or
not isinstance(channels, np.array)):
raise TypeError('nb_channel should be a list or np array')
for c in channels:
if c not in ['R', 'G', 'B', 'D']:
raise ValueError('channels must be either\
R,G,B or D (Distance)')
DataBase.__init__(self, filename, channels=channels) DataBase.__init__(self, filename, channels=channels)
@property @property
...@@ -315,8 +360,35 @@ database ...@@ -315,8 +360,35 @@ database
return posorient return posorient
def read_posorient(self, posorient=None, rowid=None): def read_posorient(self, posorient=None, rowid=None):
assert (posorient is None) or (rowid is None),\ if not isinstance(posorient, pd.Series):
'posorient and rowid can not be both None' ('posorient should be a pandas Series')
if posorient is not None:
if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series')
if posorient.empty:
raise Exception('position must not be empty')
if 'x' not in posorient.index:
raise ValueError('missing index x')
if 'y' not in posorient.index:
raise ValueError('missing index y')
if 'z' not in posorient.index:
raise ValueError('missing index z')
if 'alpha_0' not in posorient.index:
raise ValueError('missing index alpha_0')
if 'alpha_1' not in posorient.index:
raise ValueError('missing index alpha_1')
if 'alpha_2' not in posorient.index:
raise ValueError('missing index alpha_2')
if np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan')
if not isinstance(rowid, int):
raise TypeError('rowid must be an integer')
if rowid <= 0:
raise ValueError('rowid must be greater zero')
if rowid is np.nan:
raise ValueError('rowid must not be nan')
if (posorient is None) and (rowid is None):
Exception('posorient and rowid can not be both None')
if posorient is not None: if posorient is not None:
rowid = self.get_posid(posorient) rowid = self.get_posid(posorient)
# Read images # Read images
...@@ -334,6 +406,37 @@ database ...@@ -334,6 +406,37 @@ database
return toreturn return toreturn
def read_image(self, posorient=None, rowid=None): def read_image(self, posorient=None, rowid=None):
if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series')
if posorient is not None:
if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series')
if posorient.empty:
raise Exception('position must not be empty')
if 'x' not in posorient.index:
raise ValueError('missing index x')
if 'y' not in posorient.index:
raise ValueError('missing index y')
if 'z' not in posorient.index:
raise ValueError('missing index z')
if 'alpha_0' not in posorient.index:
raise ValueError('missing index alpha_0')
if 'alpha_1' not in posorient.index:
raise ValueError('missing index alpha_1')
if 'alpha_2' not in posorient.index:
raise ValueError('missing index alpha_2')
if np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan')
if not isinstance(rowid, int):
raise TypeError('rowid must be an integer')
if rowid <= 0:
raise ValueError('rowid must be greater zero')
if rowid is np.nan:
raise ValueError('rowid must not be nan')
if (posorient is None) and (rowid is None):
raise Exception('posorient and rowid can not be both None')
if posorient is not None:
rowid = self.get_posid(posorient)
"""Read an image at a given position-orientation or given id of row in the \ """Read an image at a given position-orientation or given id of row in the \
database. database.
...@@ -343,8 +446,8 @@ database ...@@ -343,8 +446,8 @@ database
:returns: an image :returns: an image
:rtype: numpy.ndarray :rtype: numpy.ndarray
""" """
assert (posorient is None) or (rowid is None),\ if (posorient is None) and (rowid is None):
'posorient and rowid can not be both None' Exception('posorient and rowid can not be both None')
if posorient is not None: if posorient is not None:
rowid = self.get_posid(posorient) rowid = self.get_posid(posorient)
# Read images # Read images
...@@ -364,8 +467,8 @@ database ...@@ -364,8 +467,8 @@ database
FROM {} FROM {}
WHERE (rowid={}) WHERE (rowid={})
""".format(tablename, rowid), self.db) """.format(tablename, rowid), self.db)
assert cmaxminrange.shape[0] == 1,\ if cmaxminrange.shape[0] != 1:
'Error while reading normalisation factors' raise Exception('Error while reading normalisation factors')
cmaxminrange = cmaxminrange.iloc[0, :] cmaxminrange = cmaxminrange.iloc[0, :]
cmaxminrange.name = cmaxminrange.id cmaxminrange.name = cmaxminrange.id
cmaxminrange.drop('id') cmaxminrange.drop('id')
...@@ -373,13 +476,32 @@ database ...@@ -373,13 +476,32 @@ database
return self.denormalise_image(image, cmaxminrange) return self.denormalise_image(image, cmaxminrange)
def denormalise_image(self, image, cmaxminrange): def denormalise_image(self, image, cmaxminrange):
assert len(image.shape) == 3,\ if len(image.shape) != 3:
'image should be 3D array' raise Exception('image should be 3D array')
assert image.shape[2] == len(self.channels),\ if image.shape[2] != len(self.channels):
'image does not have the required number of channels {}'.format( raise Exception('image does not have the required\
len(self.channels)) number of channels {}'.format(
assert isinstance(cmaxminrange, pd.Series),\ len(self.channels)))
'cmaxminrange should be a pandas Series' if not isinstance(cmaxminrange, pd.Series):
raise Exception('cmaxminrange should be a pandas Series')
if cmaxminrange.empty:
raise Exception('cmaxminrange must not be empty')
for chan_n in self.channels:
if str(chan_n) + '_max' not in cmaxminrange.index:
raise ValueError('cminmax range is missing index '
+ str(chan_n) + '_max')
if str(chan_n) + '_min' not in cmaxminrange.index:
raise ValueError('cminmax range is missing index '
+ str(chan_n) + '_min')
if str(chan_n) + '_range' not in cmaxminrange.index:
raise ValueError('cminmax range is missing index '
+ str(chan_n) + '_range')
if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_max'])):
raise ValueError('cmaxminrange contains nans')
if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_min'])):
raise ValueError('cmaxminrange contains nans')
if any(np.isnan(cmaxminrange.loc[str(chan_n) + '_range'])):
raise ValueError('cmaxminrange contains nans')
denormed_im = np.zeros(image.shape, dtype=np.float) denormed_im = np.zeros(image.shape, dtype=np.float)
maxval_nim = np.iinfo(image.dtype).max maxval_nim = np.iinfo(image.dtype).max
# #
...@@ -408,7 +530,6 @@ class DataBaseSave(DataBase): ...@@ -408,7 +530,6 @@ class DataBaseSave(DataBase):
DataBase.__init__(self, filename, channels=channels) DataBase.__init__(self, filename, channels=channels)
self.arr_dtype = arr_dtype self.arr_dtype = arr_dtype
def create(self): def create(self):
"""use to decide weather to alter the database or not """use to decide weather to alter the database or not
return True because we will need return True because we will need
...@@ -433,10 +554,10 @@ class DataBaseSave(DataBase): ...@@ -433,10 +554,10 @@ class DataBaseSave(DataBase):
self.insert_replace(tablename, params) self.insert_replace(tablename, params)
def insert_replace(self, tablename, params): def insert_replace(self, tablename, params):
assert isinstance(tablename, str),\ if not isinstance(tablename, str):
'table are named by string' raise ValueError('table are named by string')
assert isinstance(params, dict),\ if not isinstance(params, dict):
'params should be dictionary columns:val' raise ValueError('params should be dictionary columns:val')
params_list = list() params_list = list()
columns_str = '' columns_str = ''
for key, val in params.items(): for key, val in params.items():
...@@ -462,6 +583,17 @@ class DataBaseSave(DataBase): ...@@ -462,6 +583,17 @@ class DataBaseSave(DataBase):
self.db.commit() self.db.commit()
def normalise_image(self, image, dtype=np.uint8): def normalise_image(self, image, dtype=np.uint8):
if not isinstance(image, np.ndarray):
raise TypeError('image must be np.array')
if any(np.isnan(image)):
raise ValueError('image must not contain nan values')
if image.shape[0] <= 0 or image.shape[1] <= 0:
raise Exception('image dimensions incorrect')
if image.shape[2] != len(self.channels):
raise Exception('image channels number differs from\
given channel number')
if not tools.is_numeric_array(image):
raise TypeError('scene is of non numeric type')
normed_im = np.zeros(image.shape, dtype=dtype) normed_im = np.zeros(image.shape, dtype=dtype)
maxval_nim = np.iinfo(normed_im.dtype).max maxval_nim = np.iinfo(normed_im.dtype).max
# #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment