Skip to main content

No project description provided

Project description

Resourcecode library

Installation

To install the library, you may first of all, create a dedicated virtual environment:

$ cd /your/work/directory
$ python3 -m venv env-resourcecode

then, you activate it:

$ source env-resourcecode/bin/activate
(env-resourcecode)$

In this virtual environment, you can now install the library. The library is not available on PyPI yet, therefore you have to download the archive (here for instance), and then install it:

(env-resourcecode)$ python -m pip install /your/downloads/directory/resourcecode-branch-default.zip
[…]

To test whether the install has been successful, you can run:

(env-resourcecode)$ python -c "import resourcecode ; print(resourcecode.__version__)"
0.1.0

which should print the current locally installed version of resourcecode.

Configuration

The library needs a configuration file to work properly. This file contains in particular the URL of the Cassendra API.

The library will look for the configuration at the following location (in the order) :

  • in the file described by the RESOURCECODE_CONFIG_FILEPATH environment variable.
  • in a file named resourcecode.ini in the current directory.
  • in a file located in $HOME/.config/resourcecode.ini.
  • in a file located in /usr/local/etc/resourcecode/config.ini

The search stops at the first file found.

The default configuration file can be found here. You may download it and move it to this location: $HOME/.config/resourcecode.ini.

You may need to update the Cassandra URL.

Example of use

Once the library is installed and the configuration is done, you can use the library.

The first thing to do, is a create a Client. The client will query the cassandra database for you, and return a pandas dataframe of your selection.

See the following example:

>>> import resourcecode
>>> client = resourcecode.Client()
>>> data = client.get_dataframe_from_criteria(
"""
{
    "node": 0,
    "start": 1483228400,
    "end": 1489903600,
    "parameter": ["fp", "hs"]
}
""")
>>> data
                        fp     hs
2017-01-01 00:00:00  0.074  0.296
2017-01-01 01:00:00  0.072  0.400
2017-01-01 02:00:00  0.071  0.356
2017-01-01 03:00:00  0.071  0.350
2017-01-01 04:00:00  0.074  0.256
...                    ...    ...
2017-01-31 19:00:00  0.096  0.250
2017-01-31 20:00:00  0.096  0.332
2017-01-31 21:00:00  0.096  0.480
2017-01-31 22:00:00  0.096  0.612
2017-01-31 23:00:00  0.097  0.756

[744 rows x 2 columns]
>>> data.describe()
               fp          hs
count  744.000000  744.000000
mean     0.088046    0.537551
std      0.011400    0.192594
min      0.058000    0.160000
25%      0.081000    0.370000
50%      0.087000    0.533000
75%      0.095000    0.688500
max      0.120000    0.948000

>>> # if you have malptolib installed, you can do the following
>>> ax = data.plot()
>>> ax.figure.savefig('fp_hs.png')

which will generate the following plot:

plot_hs_fp

Acknowledgments

The ResourceCode Python module was developed by Logilab based on various scientific codes written by the partners of the ResourceCode Projet: EMEC, CentraleNantes, Ocean Data Lab, Smart Bay Ireland, University College Dublin, INNOSEA, Ifremer, University of Edinburgh. More information at http://resourcecode.info.

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

resourcecode-0.5.2.tar.gz (11.3 MB view hashes)

Uploaded Source

Built Distribution

resourcecode-0.5.2-py3-none-any.whl (11.3 MB view hashes)

Uploaded Python 3

Supported by

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