Package GeoDataBase
Module Recorder
This file is part of pyCSAMT.
pyCSAMT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
pyCSAMT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with pyCSAMT. If not, see <https://www.gnu.org/licenses/>.
Created on Wed Oct 14 13:38:13 2020
@author:kkouaoLaurent alias @Daniel03
- class pycsamt.geodrill.geoDB.sql_recorder.GeoDataBase(geo_structure_name=None)[source]
Geodatabase class . Currently we do not create the specific pattern for each geostructures. DataBase is built is built following the
codef code, label,`__description`,`pattern`, pat_size,`pat_density`, pat_thickness,`RGBA`, electrical_props, hatch, colorMPL, FGDC .
- Attributes
colorMPLreturn geocolorMPL
electrical_propsreturn electrical property
- hatch
patternreturn geopattern
rgbreturn georgb
- static _add_geo_structure(new_geological_rock_name=None, **kws)[source]
Add new _geological information into geodatabase .
- _avoid_injection()[source]
For secure , we do not firstly introduce directly the request. We will check whether the object request exists effectively in our GeoDatabase . if not , request will be redirect to structural and strata class issue from module structural
- _get_geo_structure(structure_name=None)[source]
After checking wether the name of structures exists , let find the geoformation properties from geodatabase .
- Parameters
struture_name (str) – name of geological rock or layer
- _reminder_geo_recorder(geo_structure_name)[source]
To have reminder of geological formation into the geodatabase , this method allow to output information if the structure doesnt not exist, An error will occurs.
- Parameters
geo_structure_name (str) – name of geological formation
- _retreive_databasecolumns(columns)[source]
Retreive data from database columns
- Parameters
columns – Columns name is str. To retreive data of many columns please put the columns name on list.
- Returns
list of data of each columns.
- Exemple
>>> from pycsamt.geodriil.geoDB.sql_recorder import GeoDataBase >>> dbObj = GeoDataBase() >>> values = dbObj.._retreive_databasecolumns( ['__description', 'electrical_props'])
- property _setGeoDatabase
Note
property of GeoDataBase -create the GeoDataBase Setting geoDataBase table No Need to reset the DataBase at least you dropped the table, avoid to do that if you are not sure of what you are doing.
- _update_geo_structure(geo_formation_name=None, **kws)[source]
Update _indormation into geoDataBase .
Remember that the geodatabase is build following this table codef ‘code’,’label’,’__description’,’pattern’, ‘pat_size’, ‘pat_density’,’pat_thickness’,’rgb’,’electrical_props’, ‘hatch’, ‘colorMPL’, ‘FGDC’.
- Parameters
geo_formation_name (str) – name of formation be sure the formation already exists in the geoDataBase if not an error occurs
Update the electrical property of basement rocks = [1e99, 1e6 ]
- Example
>>> from pycsamt.geodrill.geoDB.sql_recorder import GeoDataBase >>> GeoDataBase()._update_geo_structure( **{'__description':'basement rocks', 'electrical_props':[1e99, 1e6 ]})
- property colorMPL
return geocolorMPL
- property electrical_props
return electrical property
- property pattern
return geopattern
- property rgb
return georgb
- class pycsamt.geodrill.geoDB.sql_recorder.Recorder_sql(database, table=None, **kwargs)[source]
Class to record data from file or pd.core.DataFrame and to tranfer into SQL database.
Methods
arrangeData_for_dictapp(datalist, **kwargs)Function overwritten from "set_on_dictapp func".
keepDataInfos(data[, new_tablename])Function to KeepData from file infos .
recordData(data[, new_tablename])Function to KeepData from file infos .
set_on_dict_app(datalist, **kwargs)Function overwritten from "set_on_dictapp func".
transferdata_to_sqlDB([record_list, ...])Function to transfer Data from Dict_app to SQL DataBase.
- static arrangeData_for_dictapp(datalist, **kwargs)[source]
Function overwritten from “set_on_dictapp func”. Reorganise data to dict_app model.
- Parameters
- * datalistlist, dict
list of value providen for fill the dict_app.
- Returns
- dict
datalist, Data arranged according to dict_app arrangement.
- Raises
- pyCSAMTError_SQL_manager
None dataname detected
- static keepDataInfos(data, new_tablename=None, **kwargs)[source]
Function to KeepData from file infos . the function is otherwritten fo RecordData. The difference between two function is that function organise data from each row of columns
- Parameters
- * datastr, np.array, list, or pd.core.DataFrame object
Data ca, be on the format above or filename of data if the argument “data” is a filename, we must be convert on “.csv” format.
- new_tablenamestr, optional
Name of database. if name is not given , the function return only list . The default is None.
- Returns
- list
list of value in the case of no name is providen for tablename. else return dict if name of datatable is providen.
- Raises
- IndexError.
if lengh of number of columns like heads of data
does not match the data.shape[0], then errors will occurs.
- static recordData(data, new_tablename=None, **kwargs)[source]
Function to KeepData from file infos . the function is otherwritten fo RecordData. The difference between two function is that function organise data from each row of columns
- Parameters
- * datastr, np.array, list, or pd.core.DataFrame object
Data ca, be on the format above or filename of data if the argument “data” is a filename, we must be convert on “.csv” format.
- new_tablenamestr, optional
Name of database. if name is not given , the function return only list . The default is None.
- Returns
- list
list of value in the case of no name is providen for tablename. else return dict if name of datatable is providen.
- Raises
- IndexError.
if lengh of number of columns like heads of data
does not match the data.shape[0], then errors will occurs.
- static set_on_dict_app(datalist, **kwargs)[source]
Function overwritten from “set_on_dictapp func”. Reorganise data to dict_app model.
- Parameters
- * datalistlist, dict
list of value providen for fill the dict_app.
- Returns
- dict
datalist, Data arranged according to dict_app arrangement.
- Raises
- pyCSAMTError_SQL_manager
None dataname detected
- transferdata_to_sqlDB(record_list=None, filename=None, table_name=None, **kwargs)[source]
Function to transfer Data from Dict_app to SQL DataBase. Users can use this function byincluding several arguments. The function will build the data , arrange it and put it in the dataBase by commit the dataBase. Use only this func is benefit. It is better to revise arguments of that function.
- Parameters
- * record_listdict, optional
Dictionnay build according the dict_app model. The default is None.
- filenamestr, optional
file must be on “.csv” format. The default is None.
- table_namestr, optional
Name of DataBase Table. The default is None.
- commentsstr
little comment to identify your database table.
- path_to_sqlDataBasestr
path where the SQL dataBase is located .
- visualize_table_creating_querybool
If the connexion to server is unlikable set to True to see whether query entered is right or wrong.
- Drop_DB_Tablesstr,
way to drop table in SQL Database . set litteral arguments like
the name of database user want to drop or [ no “*” or all to drop all tables.
- Ready_to_transferstr
process to commit Database , the curso tranfered the dataBase to SQL connexion. set litteral ‘no’ or ‘yes’ to do.
- close_connexionbool ,
set True when transfer is done . it seems connexion.close()
- Raises
- Exception occurs when Table Name is not set on dict_app.
Note
The process of organization is full request of PostgreSQL ..
Module Interface
This file is part of pyCSAMT.
pyCSAMT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
pyCSAMT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with pyCSAMT. If not, see <https://www.gnu.org/licenses/>.
- synopsis
Specially dedicate to Manage SQL
Created on Tue Oct 13 15:28:57 2020
@author: @Daniel03
- class pycsamt.geodrill.geoDB.interfaceDB.ManageDB(db_name=None, db_host=None)[source]
build a datable postgre Sql from dict_app.py simple way to make a transit between two objects One object dict_app to populate DataBase
Methods
closeDB()simple method to close Database.
commit()special commit method for the database when cursor and connexion are still open.
connect_DB([db_host, db_name])Create sqqlite Database
dicT_sqlDB(dicTables, **kwargs)Method to create Table for sqlDataBase .
drop_TableDB(dicTables[, drop_table_name, ...])Drop the name of table on dataBase or all databases.
executeReq(query[, param])Execute request of dataBase with detection of error.
export_req([query, export_type])method to export data from DataBase
print_query([column_name])return the result of the previous query.
- connect_DB(db_host=None, db_name=None)[source]
Create sqqlite Database
- Parameters
db_host (str) – DataBase location path
db_name (str) – str , DataBase name
- dicT_sqlDB(dicTables, **kwargs)[source]
Method to create Table for sqlDataBase . Enter Data to DataBase from dictionnary. Interface objet : Database _Dictionnary to see how dicTable is arranged , may consult dict_app module
- Parameters
- * dictTablesdict
Rely on dict_app.py module. it populates the datababse from dictionnay app
- Returns
- str
execute queries from dict_app
- :Example :
>>> mDB=GestionDB (dbname='memory.sq3, ... db_host =os.getcwd()') >>> mDB.dicT_sqlDB(dicTables=Glob.dicoT, ... visualize_request=False) >>> ss=mB.print_last_query() >>> print(ss)
- drop_TableDB(dicTables, drop_table_name=None, drop_all=False)[source]
Drop the name of table on dataBase or all databases.
- Parameters
- * dicTablesdict
application dictionnary. Normally provide from dict_app.py module
- * drop_table_namestr, optional
field name of dictionnay (Table Name). The default is None.
- * drop_allBool, optional
Must select if you need to drop all table. The default is False.
- Raises
- ExceptionErrors occurs ! .
- executeReq(query, param=None)[source]
Execute request of dataBase with detection of error.
- Parameters
- * querystr
sql_query
- * paramstr
Default is None .
- export_req(query=None, export_type='.csv', **kwargs)[source]
method to export data from DataBase
- Parameters
- * querystr, optional
Sql requests. You may consult sql_request files. The default is None.
- * export_typeStr, optional
file extension. if None , it will export on simple file. The default is ‘.csv’.
- * kwargsstr
Others parameters.
- Raises
- Exception
Print wrong sqlrequests.
- Example
>>> from sqlrequests import SqlQ >>> manageDB.executeReq(SqlQ.sql_req[2]) >>> ss=manageDB.print_last_Query() >>> print(ss) >>> manageDB.export_req(SqlQ.sql_req[-1], export_type='.csv', )
Module Request
This file is part of pyCSAMT.
pyCSAMT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
pyCSAMT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with pyCSAMT. If not, see <https://www.gnu.org/licenses/>.
- synopsis
Deal with Boreholes and well data , requests to DataBase
Created on Tue Oct 13 17:36:35 2020
@author: @Daniel03
Module DictApp
This file is part of pyCSAMT.
pyCSAMT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
pyCSAMT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with pyCSAMT. If not, see <https://www.gnu.org/licenses/>.
Created on Tue Oct 13 14:52:08 2020
@author: Daniel03
- use :
for sql dataBase works dico to sql_database .
- class pycsamt.geodrill.geoDB.dict_app.Glob[source]
Spaces of variables and fonctions pseudo-globales . dictionnary can be set outside the container class Glob, following the dicoT datastructuration .
- Example
>>> value_DB =[('id_new', 'i', 'new_vision'), ... ('infoTab','k','no comment'), ... ('collar','d','collarDH')] >>> Glob.dicoT.__setitem__('TableDB_set',value_DB )