Skip to content

PetroDB

petropandas.database

Client for postresql petrodb database API

This module provide easy CRUD operations on petrodb database

Usage examples:

from petropandas import pd
from petropandas.database import PetroDB

db = PetroDB('http://127.0.0.1:8000', 'user', 'password')
project = db.projects(name="MyProject")
sample = project.samples(name="DB250")
df = sample.spots.df(mineral="Grt")

PetroDB

Petro database instance

High-level access to online Petro database

logged property

Return True when API credentials are ok.

projects(name=None)

Get project from database

Parameters:

Name Type Description Default
name str

search for project by name

None

Returns:

Type Description

Project instance or list of all projects if the name is not provided.

Raises:

Type Description
ValueError

If project(s) was not found.

create_project(name, description='')

Create project in database

Parameters:

Name Type Description Default
name str

name of the project

required
description str

decription of the project. Default ``.

''

Returns:

Type Description

Created project instance.

Raises:

Type Description
ValueError

If project was not created.

PetroDBProject

Petro DB project instance

Attributes:

Name Type Description
data dict

project attributes

name property writable

str: Name of the project.

description property writable

str: Description of the project.

spots property

Spots accessor

areas property

Areas accessor

samples(name=None)

Get sample from database

Parameters:

Name Type Description Default
name str

search for sample by name

None

Returns:

Type Description

Sample instance or list of all samples if the name is not provided.

Raises:

Type Description
ValueError

If sample(s) was not found.

create_sample(name, description='')

Create project in database

Parameters:

Name Type Description Default
name str

name of the sample

required
description str

decription of the sample. Default ``.

''

Returns:

Type Description

Created sample instance.

Raises:

Type Description
ValueError

If sample was not created.

delete()

Delete project from database. Use with caution!

update()

Update project in database according to the data attribute.

mineral_data(mineral)

Return spots and profile spots of given mineral dataframe

add_user(username)

Add access to the project to user

Parameters:

Name Type Description Default
username str

username

required

remove_user(username)

Remove access to the project for user

Parameters:

Name Type Description Default
username str

username

required

PetroDBSample

Petro DB sample instance

Attributes:

Name Type Description
data dict

project attributes

name property writable

str: Name of the sample.

description property writable

str: Description of the sample.

spots cached property

Spots accessor

areas cached property

Areas accessor

spot(spot_id)

Get spot from database

Parameters:

Name Type Description Default
spot_id int

id of the spot

required

Returns:

Type Description

Spot instance.

Raises:

Type Description
ValueError

If spot was not found.

create_spot(label, mineral, values)

Create spot in database

Parameters:

Name Type Description Default
label str

label of the spot

required
mineral str

Name of mineral. Kretz abbreviations recommended

required
values dict

Data values

required

Returns:

Type Description

Created spot instance.

Raises:

Type Description
ValueError

If spot was not created.

create_spots(df, label_col=None, mineral_col=None)

Create spots in database from pandas dataframe

Parameters:

Name Type Description Default
df DataFrame

data values

required
label_col str

Name of column to be used as label. If not provided, dataframe index is used

None
mineral_col str

Name of column to be used as mineral. If not provided, mineral will be empty

None

Returns:

Type Description

Created spots

Raises:

Type Description
ValueError

If spots were not created.

area(area_id)

Get area from database

Parameters:

Name Type Description Default
area_id int

id of the spot

required

Returns:

Type Description

Area instance.

Raises:

Type Description
ValueError

If area was not found.

create_area(label, values)

Create area in database

Parameters:

Name Type Description Default
label str

label of the area

required
values dict

Data values

required

Returns:

Type Description

Created area instance.

Raises:

Type Description
ValueError

If area was not created.

create_areas(df, label_col=None)

Create areas in database from pandas dataframe

Parameters:

Name Type Description Default
df DataFrame

data values

required
label_col str

Name of column to be used as label. If not provided, dataframe index is used

None

Returns:

Type Description

Created areas

Raises:

Type Description
ValueError

If areas were not created.

profiles(label=None, mineral=None)

Get profile from database

Parameters:

Name Type Description Default
label str

search for sample by name

None

Returns:

Type Description

Profile instance or list of all profiles if the label is not provided.

Raises:

Type Description
ValueError

If profile(s) was not found.

create_profile(label, mineral)

Create profile in database

Parameters:

Name Type Description Default
label str

label of the profile

required
mineral str

Name of mineral. Kretz abbreviations recommended

required

Returns:

Type Description

Created profile instance.

Raises:

Type Description
ValueError

If profile was not created.

delete()

Delete sample from database. Use with caution!

update()

Update sample in database according to the data attribute.

reset()

Reset cached properties spots and areas to access updated data

PetroDBSpot

Petro DB spot instance

Attributes:

Name Type Description
data dict

project attributes

label property writable

str: Label of the spot.

mineral property writable

str: Mineral of the spot.

delete()

Delete spot from database. Use with caution!

update()

Update spot in database according to the data attribute.

PetroDBArea

Petro DB area instance

Attributes:

Name Type Description
data dict

project attributes

label property writable

str: Label of the area.

delete()

Delete area from database. Use with caution!

update()

Update area in database according to the data attribute.

PetroDBProfile

Petro DB sample instance

Attributes:

Name Type Description
data dict

project attributes

samplename str

name of the sample

label property writable

str: Label of the profile.

mineral property writable

str: Mineral of the profile.

spots cached property

Profile spots accessor

spot(spot_id)

Get profile spot from database

Parameters:

Name Type Description Default
spot_id int

id of the profile spot

required

Returns:

Type Description

Profile spot instance.

Raises:

Type Description
ValueError

If profile spot was not found.

create_spot(index, values)

Create profile spot in database

Parameters:

Name Type Description Default
index int

used to define order of spots on profile

required
values dict

Data values

required

Returns:

Type Description

Created profile spot instance.

Raises:

Type Description
ValueError

If profile spot was not created.

create_spots(df)

Create profile spots in database from pandas dataframe

Parameters:

Name Type Description Default
df DataFrame

data values, index must be numeric and is used to define order

required

Returns:

Type Description

Created profile spots

Raises:

Type Description
ValueError

If profile spots were not created.

delete()

Delete profile from database. Use with caution!

update()

Update profile in database according to the data attribute.

reset()

Reset cached property spots to access updated data

PetroDBProfileSpot

Petro DB profile spot instance

Attributes:

Name Type Description
data dict

project attributes

index property writable

int: Index of the profile spot.

delete()

Delete profile spot from database. Use with caution!

update()

Update profile spot in database according to the data attribute.

PetroDBRecords

Petro DB records accessor

df(**kwargs)

Get records as pandas dataframe

Keyword arguments col=val are used to select records with given value.

col must be on of the available columns in attribute cols.

Attributes:

Name Type Description
cols list

list of attributes for selection

PetroDBAdmin

Admin client for postresql petrodb database API.

create_user(username, password, email)

Create user in database

Parameters:

Name Type Description Default
username str

username

required
password str

password

required
email str

email

required