Skip to main content

Python client library for the HYDWS web service

Project description

pypi PyPI - License PyPI - Python Version test codecov

HYDWS Client

Hydraulic Web Service Client This client can be used to access the data from a Hydraulic Webservice more comfortably.

Installation

Currently the package needs to be installed via the github repository:

pip install hydws-client

Usage

Imports

from datetime import datetime

from hydws.client import HYDWSDataSource
from hydws.parser import BoreholeHydraulics, SectionHydraulics

TLDR; How to get the data?

hydws_url = 'http://example.api.com/hydws/v1'
hydws = HYDWSDataSource(hydws_url)

Assuming you know exactly what you want, you can use the following methods to get the data you need.

Throughout, you can usually use the name and the id interchangeably.

Let's assume we have the borehole id, and the section name.

borehole_id = 'caf65646-8093-4aaf-989c-1c837f497667'
section_name = '16A-32/section_03'
hydraulics_start = datetime(2024, 4, 6, 1, 0, 0)
hydraulics_end = datetime(2024, 4, 6, 1, 1, 0)

The fastest way to get to the data, without caring about any metadata:

hydraulics = hydws.get_section_hydraulics(borehole_id, section_name, hydraulics_start, hydraulics_end, format='pandas')
hydraulics
topflow toppressure
datetime
2024-04-06 01:00:00 0.212990 4.710498e+07
2024-04-06 01:00:01 0.212990 4.719461e+07
2024-04-06 01:00:02 0.212990 4.721530e+07
2024-04-06 01:00:03 0.212831 4.716703e+07
2024-04-06 01:00:04 0.212646 4.714635e+07
... ... ...
2024-04-06 01:00:56 0.213653 4.716703e+07
2024-04-06 01:00:57 0.213308 4.717393e+07
2024-04-06 01:00:58 0.213308 4.710498e+07
2024-04-06 01:00:59 0.213308 4.714635e+07
2024-04-06 01:01:00 0.213494 4.716014e+07

61 rows × 2 columns

Boreholes and Sections

Otherwise, if you want the metadata, or need to parse a file containing hydws, or prefer an object with the borehole and/or section structure, you can use the hydws client together with BoreholeHydraulics and SectionHydraulics classes:

If you just want to consider one Section, it's easiest to directly use the SectionHydraulics class:

section_json = hydws.get_section(borehole_id, section_name, hydraulics_start, hydraulics_end)
section = SectionHydraulics(section_json)

section.metadata # to access the metadata of the section
section.hydraulics # to access the hydraulic data as a dataframe
topflow toppressure
datetime
2024-04-06 01:00:00 0.212990 4.710498e+07
2024-04-06 01:00:01 0.212990 4.719461e+07
2024-04-06 01:00:02 0.212990 4.721530e+07
2024-04-06 01:00:03 0.212831 4.716703e+07
2024-04-06 01:00:04 0.212646 4.714635e+07
... ... ...
2024-04-06 01:00:56 0.213653 4.716703e+07
2024-04-06 01:00:57 0.213308 4.717393e+07
2024-04-06 01:00:58 0.213308 4.710498e+07
2024-04-06 01:00:59 0.213308 4.714635e+07
2024-04-06 01:01:00 0.213494 4.716014e+07

61 rows × 2 columns

If you prefer to directly get all the metadata and hydraulic data of a Borehole for a given time, use the following methods:

# Get Borehole, containing all of its sections and their hydraulic data for the given time range
borehole_json = hydws.get_borehole(borehole_id, hydraulics_start, hydraulics_end)
borehole = BoreholeHydraulics(borehole_json)

borehole.metadata # to access the metadata of the borehole
{'publicid': 'caf65646-8093-4aaf-989c-1c837f497667',
 'description': 'Well 16A-32',
 'name': '16A-32',
 'location': 'FORGE',
 'institution': 'FORGE Utah',
 'measureddepth': {'value': 3339.1},
 'bedrockaltitude': {'value': 0.0},
 'altitude': {'value': 1650.02},
 'latitude': {'value': -112.906857},
 'longitude': {'value': 38.506874},
 'creationinfo': {'creationtime': '2024-04-01T22:40:47.911589'}}

Accessing the sections inside a borehole, can be done using the publicid as a dict key, or by using the section name and the nloc attribute:

section_id = '37801a57-90b9-4fb5-83d7-506ee9166acf'

section = borehole[section_id] # use the section id as a key to access the section
section = borehole.nloc[section_name] # use the section name as a key to access the section
section.hydraulics
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
topflow toppressure
datetime
2024-04-06 01:00:00 0.212990 4.710498e+07
2024-04-06 01:00:01 0.212990 4.719461e+07
2024-04-06 01:00:02 0.212990 4.721530e+07
2024-04-06 01:00:03 0.212831 4.716703e+07
2024-04-06 01:00:04 0.212646 4.714635e+07
... ... ...
2024-04-06 01:00:56 0.213653 4.716703e+07
2024-04-06 01:00:57 0.213308 4.717393e+07
2024-04-06 01:00:58 0.213308 4.710498e+07
2024-04-06 01:00:59 0.213308 4.714635e+07
2024-04-06 01:01:00 0.213494 4.716014e+07

61 rows × 2 columns

Navigating Boreholes, Sections and Metadata

If you don't exactly know which names or publicids there are, you can use the following methods to display the available boreholes and sections.

borehole_metadata_all = hydws.list_boreholes() # returns all metadata
borehole_names = hydws.list_borehole_names() # only returns name, publicid or both (default is name)
borehole_names
['16A-32', '16B-32']

The first column is the name of the borehole, the second one its public ID. It's generally possible to use either of the two for all of the following functions. The same applies to the section names and their IDs.

section_metadata_all = hydws.list_sections(borehole_names[0]) # returns all metadata
section_names = hydws.list_section_names(borehole_names[0]) # only returns name, publicid or both (default is name)
section_names
['16A-32/section_01', '16A-32/section_02', '16A-32/section_03']

It is also possible to use theget_borehole_metadata or the get_section_metadata functions to get the metadata of a specific borehole or section.

borehole_metadata = hydws.get_borehole_metadata(borehole_names[0])
section_metadata = hydws.get_section_metadata(borehole_names[0], section_names[0])
section_metadata
{'publicid': '8eb6ce9a-247d-4675-8647-880841bb9531',
 'starttime': '2022-04-17T02:35:57',
 'endtime': '2022-04-17T05:50:13',
 'topclosed': True,
 'bottomclosed': True,
 'description': '200 ft long open hole section at the toe of the well',
 'name': '16A-32/section_01',
 'hydraulics': [],
 'casingdiameter': {},
 'holediameter': {},
 'bottommeasureddepth': {'value': 3339.09},
 'topmeasureddepth': {'value': 3278.13},
 'bottomaltitude': {'value': -958.71},
 'bottomlatitude': {'value': 38.504462},
 'bottomlongitude': {'value': -112.893086},
 'topaltitude': {'value': -936.3276802186539},
 'toplatitude': {'value': 38.50454148787154},
 'toplongitude': {'value': -112.89372764195421}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hydws_client-1.3.1.tar.gz (71.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydws_client-1.3.1-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file hydws_client-1.3.1.tar.gz.

File metadata

  • Download URL: hydws_client-1.3.1.tar.gz
  • Upload date:
  • Size: 71.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hydws_client-1.3.1.tar.gz
Algorithm Hash digest
SHA256 759bce727b6068dad245a019a51be1050242217e9a1400705497f1fecb54c3b7
MD5 e5d84e19977443fa219c72ba10a1fabb
BLAKE2b-256 b2675632ed964919a0e79eae7579707c2f14ee730a556547566154c8785ae32e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydws_client-1.3.1.tar.gz:

Publisher: publish.yml on swiss-seismological-service/hydws-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hydws_client-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: hydws_client-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hydws_client-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a5e9f5580f94fcbf06b41becba5ffdb1a74507c5c5ce1d242e3ffd141ab0011
MD5 58b9f5d6488d19a2e52fa23b4a3f5138
BLAKE2b-256 d34c506f5347b59c3cb5525f5cfd64b0f5adf464557e41a0d3e47e96541acab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydws_client-1.3.1-py3-none-any.whl:

Publisher: publish.yml on swiss-seismological-service/hydws-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page