diff --git a/src/vai_lab/DataProcessing/plugins/RGBcalculation.py b/src/vai_lab/DataProcessing/plugins/RGBcalculation.py new file mode 100644 index 00000000..4868fb80 --- /dev/null +++ b/src/vai_lab/DataProcessing/plugins/RGBcalculation.py @@ -0,0 +1,66 @@ +import numpy as np +from sklearn.base import BaseEstimator +from vai_lab._plugin_templates import DataProcessingT + +_PLUGIN_READABLE_NAMES = {"RGBcalculation":"default"} # type:ignore +_PLUGIN_MODULE_OPTIONS = {"Type": "Other"} # type:ignore +_PLUGIN_REQUIRED_SETTINGS = {"Data": "str"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {} # type:ignore +_PLUGIN_REQUIRED_DATA = {} # type:ignore +_PLUGIN_OPTIONAL_DATA = {"X","Y","X_tst", 'Y_tst'} # type:ignore + +class RGBcalculation(DataProcessingT): + + def __init__(self): + """Initialises parent class. + Passes `globals` dict of all current variables + """ + super().__init__(globals()) + self.proc = model() + + # def configure(self, config: dict): + # """Sets and parses plugin configurations options + # :param config: dict of internal tags set in the XML config file + # """ + # super().configure(config) + + # def set_data_in(self, data_in): + # """Sets and parses incoming data + # :param data_in: saves data as class variable + # expected type: aidesign.Data.Data_core.Data + # """ + # super().set_data_in(data_in) + + # def fit(self): + # cleaned_options = self._clean_solver_options() + # self.proc.set_params(**cleaned_options) + # self.proc.fit(self.X) + + # def transform(self, data: DataInterface) -> DataInterface: + # data.append_data_column("X", pd.DataFrame(self.proc.transform(data))) + # # if self.X_tst is not None: + # # data.append_data_column("X_test", pd.DataFrame(self.proc.transform(self.X_tst))) + # print(data) + # return data + +class model(BaseEstimator): + def __init__(self): + return + + def fit(self, X): + return self + + def transform(self, X): + """ Calculates the mean RGB value of an image. + + Parameters + ---------- + X : {array-like, sparse matrix} of shape (pixels, pixels, RGB) + The image data with the RGB information. + Returns + ------- + mean_RGB : {int, float} + Mean RGB value of the input image. + """ + mean_RGB = np.mean(X) + return mean_RGB \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/RectangleDetection.py b/src/vai_lab/DataProcessing/plugins/RectangleDetection.py new file mode 100644 index 00000000..e9fea98f --- /dev/null +++ b/src/vai_lab/DataProcessing/plugins/RectangleDetection.py @@ -0,0 +1,124 @@ +import numpy as np +from sklearn.base import BaseEstimator +from vai_lab._plugin_templates import DataProcessingT +import matplotlib.pyplot as plt + +_PLUGIN_READABLE_NAMES = {"RectangleDetection":"default", + "RectDet": "alias", + "rectangledetection": "alias"} # type:ignore +_PLUGIN_MODULE_OPTIONS = {"Type": "Other"} # type:ignore +_PLUGIN_REQUIRED_SETTINGS = {"Data": "str"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {"r": "int", + "c": "int", + "h":"float", + "w": "float"} # type:ignore +_PLUGIN_REQUIRED_DATA = {} # type:ignore +_PLUGIN_OPTIONAL_DATA = {"X","Y","X_tst","Y_tst"} # type:ignore + + +class RectangleDetection(DataProcessingT): + """ + Red rectangle detection in an image + """ + def __init__(self): + """Initialises parent class. + Passes `globals` dict of all current variables + """ + super().__init__(globals()) + self.proc = model() + + # def configure(self, config: dict): + # """Sets and parses plugin configurations options + # :param config: dict of internal tags set in the XML config file + # """ + # super().configure(config) + + # def set_data_in(self, data_in): + # """Sets and parses incoming data + # :param data_in: saves data as class variable + # expected type: aidesign.Data.Data_core.Data + # """ + # super().set_data_in(data_in) + + # def fit(self): + # cleaned_options = self._clean_solver_options() + # self.proc.set_params(**cleaned_options) + # """ + # # TODO: Temporary solution until input data module is cofigured.""" + + # # dst_img = os.path.join( + # # get_lib_parent_dir(), + # # 'examples', + # # 'crystalDesign') + # # #iterating over dst_image to get the images as arrays + # # # for image in sorted(os.listdir(dst_img)): + # # arr = np.array(Image.open(os.path.join(dst_img, '00007.png'))) + # # self.proc.fit(arr) + # """""" + # self.proc.fit(self.X) + + # def transform(self, data: DataInterface) -> DataInterface: + # """ + # # TODO: Temporary solution until input data module is cofigured.""" + # # dst_img = os.path.join( + # # get_lib_parent_dir(), + # # 'examples', + # # 'crystalDesign') + # # arr = np.array(Image.open(os.path.join(dst_img, '00007.png'))) + # # self.proc.transform(arr) + # """""" + # data.append_data_column("X", pd.DataFrame(self.proc.transform(data))) + # return data + +class model(BaseEstimator): + def __init__(self, optional=False): + self.optional = optional + + def fit(self, X, r=7, c=4, h=35, w=79, hs=34, vs=23, buffer=5): + """Defines the number of samples in the design, their placement + and their size. + + Parameters + ---------- + X : {array-like, sparse matrix} of shape (pixels, pixels, RGB) + The image data with the samples with RGB information. + Samples are expected to be marked with a red rectangle. + r : int + Number of rows with samples. + c : int + Number of columns with samples. + h : float + Sample height. + w : int + Sample width. + hs : float + Horizontal spacing. + vs : int + Vertical spacing. + buffer : int + Pixel buffer. Inidcates the margin for the inner rectangle. + Returns + ------- + self : object + Fitted model. + """ + self.r = r + self.c = c + self.h = h + self.w = w + self.hs = hs + self.vs = vs + self.buffer = buffer + mask = (X[:,:,0] > 120) * (X[:,:,1] < 80) * (X[:,:,2] < 80) + self.ii_ini, self.jj_ini = np.unravel_index(mask.argmax(), mask.shape) + # return self + + def transform(self, X): + X_dict = {} + fig, axs = plt.subplots(self.r, self.c) + for i in np.arange(self.r): + for j in np.arange(self.c): + X_dict[i,j] = X[self.ii_ini+self.h*i+self.vs*i+self.buffer*(1+i):self.ii_ini+self.h*(i+1)+self.vs*i-self.buffer*(1-i), + self.jj_ini+self.w*j+self.hs*j+self.buffer*(1+j):self.jj_ini+self.w*(j+1)+self.hs*j-self.buffer*(1-j),:] + axs[i, j].imshow(X_dict[i,j]) + return X_dict diff --git a/src/vai_lab/DataProcessing/plugins/argopt.py b/src/vai_lab/DataProcessing/plugins/argopt.py new file mode 100644 index 00000000..a8ee1cfe --- /dev/null +++ b/src/vai_lab/DataProcessing/plugins/argopt.py @@ -0,0 +1,35 @@ +from distutils.command.config import config +from numpy import argmin, argmax +from vai_lab._plugin_templates import DataProcessingT +import pandas as pd + +_PLUGIN_READABLE_NAMES = {"argopt": "default", + "argmax": "alias", + "argmin": "alias"} # type:ignore +_PLUGIN_MODULE_OPTIONS = {"Type": "math operator"} # type:ignore +_PLUGIN_REQUIRED_SETTINGS = {"Data": "str"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {'min/max': "str"} # type:ignore +_PLUGIN_REQUIRED_DATA = {} # type:ignore +_PLUGIN_OPTIONAL_DATA = {"X","Y","X_tst", 'Y_tst'} # type:ignore + +class argopt(DataProcessingT): + """ + Calculate the optimum argument + """ + + def __init__(self): + """Initialises parent class. + Passes `globals` dict of all current variables + """ + super().__init__(globals()) + + def fit(self): + self.cleaned_options = self._clean_solver_options() + return + + def transform(self,data): + if config['min/max'] == 'max': + data.append_data_column("X", pd.DataFrame(argmax(self.X))) + else: + data.append_data_column("X", pd.DataFrame(argmin(self.X))) + return data \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/imgtofeatvect.py b/src/vai_lab/DataProcessing/plugins/imgtofeatvect.py new file mode 100644 index 00000000..d1fb47ab --- /dev/null +++ b/src/vai_lab/DataProcessing/plugins/imgtofeatvect.py @@ -0,0 +1,51 @@ +from vai_lab._plugin_templates import DataProcessingT +from sklearn.base import BaseEstimator +import pandas as pd +import numpy as np + +_PLUGIN_READABLE_NAMES = {"ImgToFeatVect":"default", + "imgtofeatvect": "alias", + "ImageToFeatureVector": "alias"} # type:ignore +_PLUGIN_MODULE_OPTIONS = {"Type": "Other"} # type:ignore +_PLUGIN_REQUIRED_SETTINGS = {"Data": "str"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {} # type:ignore +_PLUGIN_REQUIRED_DATA = {} # type:ignore +_PLUGIN_OPTIONAL_DATA = {"X","Y","X_tst","Y_tst"} # type:ignore + + +class ImgToFeatVect(DataProcessingT): + + def __init__(self): + """Initialises parent class. + Passes `globals` dict of all current variables + """ + super().__init__(globals()) + self.proc = model() + + +class model(BaseEstimator): + def __init__(self, optional=False): + self.optional = optional + + def fit(self, X): + """Defines the number of samples in the design, their placement + and their size. + + Parameters + ---------- + X : {dict} + A dictionary containing images in each entry. + Returns + ------- + self : object + Fitted model. + """ + self.n = len(X.keys()) + h,w,self.rgb = next(iter(X.values())).shape + self.d = h*w + return self + + def transform(self, X): + X_mat = np.dstack([X[el].reshape(self.d,self.rgb) for el in X.keys()]) + X_mat = X_mat.reshape(self.n,self.d,self.rgb) + return pd.DataFrame(X_mat) \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/integral.py b/src/vai_lab/DataProcessing/plugins/integral.py new file mode 100644 index 00000000..6778dbec --- /dev/null +++ b/src/vai_lab/DataProcessing/plugins/integral.py @@ -0,0 +1,32 @@ +from scipy.integrate import simps as model +from vai_lab._plugin_templates import DataProcessingT +import pandas as pd + +_PLUGIN_READABLE_NAMES = {"Integral": "default", + "integral": "alias"} # type:ignore +_PLUGIN_MODULE_OPTIONS = {"Type": "math operator"} # type:ignore +_PLUGIN_REQUIRED_SETTINGS = {"Data": "str"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {"dx": "float", + "axis": "int", + "even": "str"} # type:ignore +_PLUGIN_REQUIRED_DATA = {} # type:ignore +_PLUGIN_OPTIONAL_DATA = {"X","Y","X_tst","Y_tst"} # type:ignore + +class Integral(DataProcessingT): + """ + Calculate integral of array using the composite trapezoidal rule + """ + + def __init__(self): + """Initialises parent class. + Passes `globals` dict of all current variables + """ + super().__init__(globals()) + self.proc = model() + + def fit(self): + return + + def transform(self,data): + data.append_data_column("X", pd.DataFrame(self.proc(self.X))) + return data \ No newline at end of file diff --git a/src/vai_lab/UserInteraction/plugins/OptimisationInput.py b/src/vai_lab/UserInteraction/plugins/OptimisationInput.py index d0027488..7d54b562 100644 --- a/src/vai_lab/UserInteraction/plugins/OptimisationInput.py +++ b/src/vai_lab/UserInteraction/plugins/OptimisationInput.py @@ -20,7 +20,7 @@ _PLUGIN_MODULE_OPTIONS = {"layer_priority": 2, "required_children": None} # type:ignore _PLUGIN_REQUIRED_SETTINGS = {} # type:ignore -_PLUGIN_OPTIONAL_SETTINGS = {"Bounds": "list"} # type:ignore +_PLUGIN_OPTIONAL_SETTINGS = {"Bounds": "list"} # type:ignore _PLUGIN_REQUIRED_DATA = {"X"} # type:ignore diff --git a/src/vai_lab/examples/xml_files/BO_demo.xml b/src/vai_lab/examples/xml_files/BO_demo.xml new file mode 100644 index 00000000..50af59a3 --- /dev/null +++ b/src/vai_lab/examples/xml_files/BO_demo.xml @@ -0,0 +1,32 @@ + + + + + + + + + + [(350.0,50),0,{}] + + + + + + + + + [(350.0,350.0),2,{0:'d0-u2'}] + + + + + + + + + + [(350.0,650),1,{2:'d2-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/DecisionMaking_demo.xml b/src/vai_lab/examples/xml_files/DecisionMaking_demo.xml new file mode 100644 index 00000000..a90e63b0 --- /dev/null +++ b/src/vai_lab/examples/xml_files/DecisionMaking_demo.xml @@ -0,0 +1,29 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + + [(350.0, 350.0), 2, {0: 'd0-u2'}] + + + + + + + + + [(350.0, 650), 1, {2: 'd2-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/bayes_opt_demo.xml b/src/vai_lab/examples/xml_files/bayes_opt_demo.xml new file mode 100644 index 00000000..728002fe --- /dev/null +++ b/src/vai_lab/examples/xml_files/bayes_opt_demo.xml @@ -0,0 +1,36 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + [(350.0,350.0),2,{0:'d0-u2'}] + + + + None + + + {'CsPbI': (0,1), 'MAPbI': (0, 1), 'FAPbI': (0, 1)} + + + + + + + + + + [(350.0,650),1,{2:'d2-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/crystalDesign_v2.xml b/src/vai_lab/examples/xml_files/crystalDesign_v2.xml new file mode 100644 index 00000000..4884286e --- /dev/null +++ b/src/vai_lab/examples/xml_files/crystalDesign_v2.xml @@ -0,0 +1,33 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + [(350.0,350.0),2,{0:'d0-u2'}] + + + + X + + + + + + + + + + [(350.0,650),1,{2:'d2-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/crystalDesign_v3.xml b/src/vai_lab/examples/xml_files/crystalDesign_v3.xml new file mode 100644 index 00000000..d8152bef --- /dev/null +++ b/src/vai_lab/examples/xml_files/crystalDesign_v3.xml @@ -0,0 +1,33 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + [(350.0,350.0),2,{0:'d0-u2'}] + + + + str + + + + + + + + + + [(350.0,650),1,{2:'d2-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/materialdesign_demo.xml b/src/vai_lab/examples/xml_files/materialdesign_demo.xml new file mode 100644 index 00000000..16b994b9 --- /dev/null +++ b/src/vai_lab/examples/xml_files/materialdesign_demo.xml @@ -0,0 +1,59 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + + [(249, 180), 2, {0: 'd0-u2'}] + + + + + + + + + + [(447, 179), 3, {2: 'r2-l3'}] + + + + + + + + + + [(350.0, 350.0), 4, {3: 'd3-u4'}] + + + + + + + + + + [(350, 501), 5, {4: 'd4-u5'}] + + + + + + + + + [(350.0, 650), 1, {5: 'd5-u1'}] + + + diff --git a/src/vai_lab/examples/xml_files/optimisation_demo.xml b/src/vai_lab/examples/xml_files/optimisation_demo.xml new file mode 100644 index 00000000..048c4a23 --- /dev/null +++ b/src/vai_lab/examples/xml_files/optimisation_demo.xml @@ -0,0 +1,55 @@ + + + + + + + [(350.0,50),0,{}] + + + + + + + + + + + + + [(350.0,350.0),2,{0:'d0-u2'}] + + + + None + + + EI + + + ['./examples/optimisation/phasestability/CsFA/fulldata/CsFA_T300_above.csv', './examples/optimisation/phasestability/FAMA/fulldata/FAMA_T300_above.csv', './examples/optimisation/phasestability/CsMA/fulldata/CsMA_T300_above.csv'] + + + True + + + local_penalization + + + 0.01 + + + [{'name': 'CsPbI', 'type': 'continuous', 'domain': (0, 1)}, {'name': 'MAPbI', 'type': 'continuous', 'domain': (0, 1)}, {'name': 'FAPbI', 'type': 'continuous', 'domain': (0, 1)}] + + + + + + + + + + [(350.0,650),1,{2:'d2-u1'}] + + +