Package GeoDataBase
Module GeoDB
- class pycsamt.geodrill.geodatabase.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 .
- Parameters
**geo_structure_name** (str) – Name of geological rocks , strata or layer.
See also
FGDC-Digital cartographic Standard for Geological Map Symbolisation.
- static _add_geo_structure(new_geological_rock_name=None, **kws)[source]
Add new _geological information into geodatabase .
code
label
__description
pattern
pat_size
pat_density
pat_thickness
rgb’
electrical_props
hatch
colorMPL
FGDC
Note
__description could be replaced by name. code , label and FGDC dont need to be fill. Values are rejected if given.
- Parameters
new_geological_rock_name (str) – new name of geological formation to add
informations (dict) –
- dict , must be on keyward keys when keywords keys
are provided , program will check whether all keys are effectively the right keys. if not will aborted the process.
- Example
>>> from pycsamt.geodrill.geodatabase import GeoDataBase >>> geodatabase_obj= GeoDataBase._add_geo_structure( **{ ... 'name': 'massive sulfure', ... 'pattern': 218., ... 'pat_size': 250., ... 'pat_density': 0.75, ... 'pat_thickness': 2., ... 'rgb': 'R128B28', ... 'hatch': '+.+.o.+', ... 'electrical_props':[1e0 , 1e-2], ... } )
- _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 classes from module structural to not corrupt the memory.
- _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 does 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.geodrill.geodatabase 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.geodatabase 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.geodatabase.Recorder_sql(database, table=None, **kwargs)[source]
Class to record data from file or pd.core.DataFrame and to tranfer into SQL database.
- Parameters
**database** (str ,) – name of sql database
**table** (str ,) – name of table in dict_app
**Glob.dicoT** (dict,) – dicoT is from dict_app module , Global class for sql variable encapsulated on particular dictionnary.
Methods
Description
transferdata_to_sqlDB
transfer Data to SQL Database
keepDataInfos
keep informations from datafile ‘*csv’
arrangeData_for_dictapp
to arrange data, acording the dict_app arangement
- Example
>>> from pycsamt.pycsamt.geodrill.geodatabase import Recorder_sql >>> realpath=os.path.dirname(os.path.realpath(__file__)) >>> #where 'the file'sql_recorder is located' >>> print(realpath) >>> path_to_files =os.path.normpath(os.path.join(realpath,'sql_utils', ... 'sql_DB')) >>> os.chdir(path_to_files) >>> filename='nofacies_data_2.csv' >>> memory_DB='memory.sq3' >>> path_to_memory=os.path.dirname(os.path.realpath(memory_DB)) >>> Rec=Recorder_sql(database=memory_DB,table=None) >>> recordList1=Recorder_sql.recordData( data=filename,new_tablename='TEST2',sep=',') >>> sdico_app=Recorder_sql.set_on_dict_app( datalist=recordList0) >>> sdico_app=Recorder_sql.arrangeData_for_dictapp( datalist=recordList0) >>> trand_sql= Rec.transferdata_to_sqlDB( filename=filename,record_list= None, ... table_name='exam_zju_2',comments=None, ... visualize_table_creating_query=True, ... path_to_sqlDataBase=path_to_files, ... Drop_DB_Tables='none', fetchall=True, ... ready_to_transfer='n', ... close_connexion =False)
- static arrangeData_for_dictapp(datalist, **kwargs)[source]
Function overwritten from “set_on_dictapp func”. Reorganise data to dict_app model.
- Parameters
datalist (*) – list of value providen for fill the dict_app.
- Raises
pyCSAMTError_SQL_manager – None dataname detected
- Returns
datalist, Data arranged according to dict_app arrangement.
- Return type
dict
- 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
data (*) – 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_tablename (*) – Name of database. if name is not given , the function return only list . The default is None.
- Raises
IndexError. – if lengh of number of columns like heads of data does not match the data.shape[0], then errors will occurs.
- Returns
list of value in the case of no name is providen for tablename. else return dict if name of datatable is providen.
- Return type
list
- 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
data (*) – 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_tablename (*) – Name of database. if name is not given , the function return only list . The default is None.
- Raises
IndexError. – if lengh of number of columns like heads of data does not match the data.shape[0], then errors will occurs.
- Returns
list of value in the case of no name is providen for tablename. else return dict if name of datatable is providen.
- Return type
list
- static set_on_dict_app(datalist, **kwargs)[source]
Function overwritten from “set_on_dictapp func”. Reorganise data to dict_app model.
- Parameters
datalist (*) – list of value providen for fill the dict_app.
- Raises
pyCSAMTError_SQL_manager – None dataname detected
- Returns
datalist, Data arranged according to dict_app arrangement.
- Return type
dict
- 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_list (*) – Dictionnay build according the dict_app model. The default is None.
filename (*) – file must be on “.csv” format. The default is None.
table_name (*) – Name of DataBase Table. The default is None.
comments (*) – little comment to identify your database table.
path_to_sqlDataBase (*) – path where the SQL dataBase is located .
visualize_table_creating_query (*) – If the connexion to server is unlikable set to True to see whether query entered is right or wrong.
Drop_DB_Tables (*) – 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_transfer (*) – process to commit Database , the curso tranfered the dataBase to SQL connexion. set litteral ‘no’ or ‘yes’ to do.
close_connexion (*) – 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 Request
- class pycsamt.geodrill.requestmanager.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
- Parameters
**db_name** (str) – name of dataBase
**db_host** (st) – path to database
Attributes
Type
Explanation
connex
object
DataBase connection
curs
object
Database cursor
Methods
Explanation
dicT_sqlDB
send infos as dictionnary to dataBase
execute req
execute a sql_request
drop_TableDB
drop all Tables in sql memory DB or single Table
closeDB
close after requests the connection and the cursor
commit
transfer the data to DataBase. if not the data will still in the cursor and not in the dataBase
print_last_Query
print the last operating system
export_req
export the request on datasheet like excelsheet .
- Example
>>> from pycsamt.geodrill.requestmanager import ManageDB >>> path= os.getcwd() >>> nameofDB='memory.sq3' >>> manDB=ManageDB(db_name=nameofDB, ... db_host=path) ... print(SqlQ.sql_req[-1]) ... manDB.executeReq(SqlQ.sql_req[2]) ... ss=manDB.print_last_Query() ... print(ss) ... manDB.export_req(SqlQ.sql_req[-1], export_type='.csv') ... manDB.dicT_sqlDB(dictTables=Glob.dicoT, visualize_request=False)
- 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
dictTables (*) – Rely on dict_app.py module. it populates the datababse from dictionnay app
- Returns
execute queries from dict_app
- Return type
str
: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
dicTables (*) – application dictionnary. Normally provide from dict_app.py module
drop_table_name (*) – field name of dictionnay (Table Name). The default is None.
drop_all (*) – Must select if you need to drop all table. The default is False.
:raises Exception : Errors occurs ! .:
- executeReq(query, param=None)[source]
Execute request of dataBase with detection of error.
- Parameters
query (*) – sql_query
param (*) – Default is None .
raise –
------- – layout the wrong sql queries .
return –
------- –
- int
1, the request has been successuful run .
- :param>>> for keys in Glob.dicoT.keys():
… reqst=’select * from %s’%keys >>> ss=manageDB.executeReq(query=reqst) >>> print(ss)
:type : Example:
- export_req(query=None, export_type='.csv', **kwargs)[source]
method to export data from DataBase
- Parameters
query (*) – Sql requests. You may consult sql_request files. The default is None.
export_type (*) – file extension. if None , it will export on simple file. The default is ‘.csv’.
kwargs (*) – 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', )