An open API service indexing awesome lists of open source software.

https://github.com/opencdms/opencdms-workshop

✅🐍 Demo / tutorial for using the opencdms python package
https://github.com/opencdms/opencdms-workshop

pandas python r

Last synced: about 2 months ago
JSON representation

✅🐍 Demo / tutorial for using the opencdms python package

Awesome Lists containing this project

README

          

# opencdms-workshop
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![License: CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-sa/4.0/)

### The following section gives an example of a Jupyter notebook session

```python
import os
from pathlib import Path
from opencdms import MidasOpen
```

```python
connection = os.path.join(
Path.home(), 'work', 'opencdms-dev', 'git', 'opencdms-test-data')
```

```python
session = MidasOpen(connection)
```

```python
filters = {
'src_id': 838,
'period': 'hourly',
'year': 1991,
'elements': ['wind_speed', 'wind_direction'],
}
```

```python
obs = session.obs(**filters)
```

```python
obs

```




ob_time
src_id
wind_direction
wind_speed




0
1991-01-01 00:00:00
838
230.0
3.0


1
1991-01-01 01:00:00
838
230.0
3.0


2
1991-01-01 02:00:00
838
210.0
4.0


3
1991-01-01 03:00:00
838
200.0
2.0


4
1991-01-01 04:00:00
838
220.0
1.0


...
...
...
...
...


16212
1991-12-31 19:00:00
838
190.0
1.0


16213
1991-12-31 20:00:00
838
220.0
2.0


16214
1991-12-31 21:00:00
838
210.0
3.0


16215
1991-12-31 22:00:00
838
200.0
4.0


16216
1991-12-31 23:00:00
838
220.0
5.0

16217 rows × 4 columns


```python
type(obs)

```
> pandas.core.frame.DataFrame

```python
from opencdms.process.climatol import windrose
```

```python
windrose(obs)
```

### Setting up database servers

| | Postgres | MySQL | Oracle | File-based |
|------------|:--------:|:-----:|:------:|:----------:|
| CliDE | :white_check_mark: || | |
| Climsoft | | :white_check_mark: || |
| MCH | | :white_check_mark: || |
| Midas Open | | | | :white_check_mark: |

#### Installing PostgreSQL

In this demo we'll install PostgreSQL by using the [Timescale docker image](https://docs.timescale.com/latest/getting-started/installation/docker/installation-docker) that includes PostgreSQL 12, TimescaleDB (time series) and PostGIS (spatial) extensions.

When the container is running, the database server will be available on port `5432`

See: Docker website for instructions on [installing docker](https://docs.docker.com/engine/install/ubuntu/)
You may also want to add the current user to the `docker` group so that you don't have to prefix each command with `sudo` by using: `sudo gpasswd -a $USER docker`

```
docker pull timescale/timescaledb-postgis:latest-pg12
# Note: change `password` below to a suitable password
docker run -d --name timescaledb -p 5432:5432 -e POSTGRES_PASSWORD=password timescale/timescaledb:latest-pg12
# List running containers
docker ps

docker stop c0eb1c33aad9
# Show stopped containers
docker ps -a
docker start c0eb1c33aad9
docker exec -it c0eb1c33aad9 env
# POSTGRES_PASSWORD=...
# PG_VERSION=12.4
# TIMESCALEDB_VERSION=1.7.4

```