π§ββοΈπ§ Utils that can be reused and shared across and beyond the ESO Nowcast project
This is a public repository hosted on GitHub via a push mirror setup in the internal ESO GitLab repository
Simply run
pip install nowcastlib
Nowcast Library (nowcastlib) consists in a collection of functions organized in submodules (API) and a tool accessible via the command line (CLI). The latter is primarily intended for accessing the Nowcast Library Pipeline, an opinionated yet configurable set of processing steps for wrangling data and evaluating models in a consistent and rigorous way. More information can be found on the nowcastlib pipeline index page (link to markdown and link to hosted docs)
Please refer to the examples folder on GitHub for usage examples.
Here is a quick example of how one may import nowcastlib and access to one of the functions:
"""Example showing how to access compute_trig_fields function"""
import nowcastlib as ncl
import pandas as pd
import numpy as np
data_df = pd.DataFrame(
np.array([[0, 3, 4, np.NaN], [32, 4, np.NaN, 4], [56, 8, 0, np.NaN]]).T,
columns=["A", "B", "C"],
index=pd.date_range(start="1/1/2018", periods=4, freq="2min"),
)
result = ncl.datasets.compute_trig_fields(data_df, ["A", "C"])
More in-depth API documentation can be found here.
Some of the library's functionality is bundled in configurable subcommands
accessible via the terminal with the command nowcastlib
:
usage: nowcastlib [-h] [-v]
{triangulate,preprocess,sync,postprocess,datapipe} ...
positional arguments:
{triangulate,preprocess,sync,postprocess,datapipe}
available commands
triangulate Run `nowcastlib triangulate -h` for further help
preprocess Run `nowcastlib preprocess -h` for further help
sync Run `nowcastlib sync -h` for further help
postprocess Run `nowcastlib postprocess -h` for further help
datapipe Run `nowcastlib datapipe -h` for further help
optional arguments:
-h, --help show this help message and exit
-v, --verbose increase verbosity level from INFO to DEBUG
The following output is generated with tree . -I 'dist|docs|*.pyc|__pycache__'
.
βββ LICENSE
βββ Makefile # currently used to build docs
βββ README.md
βββ de421.bsp # not committed
βββ docs/ # html files for the documentation static website
βββ examples
βΒ Β βββ README.md
βΒ Β βββ cli_triangulate_config.yaml
βΒ Β βββ data/ # not committed
βΒ Β βββ datasync.ipynb
βΒ Β βββ output/ # not committed
βΒ Β βββ pipeline_datapipe.json
βΒ Β βββ pipeline_preprocess.json
βΒ Β βββ pipeline_sync.json
βΒ Β βββ signals.ipynb
βΒ Β βββ triangulation.ipynb
βββ images
βΒ Β βββ pipeline_flow.png
βββ nowcastlib # the actual source code for the library
βΒ Β βββ __init__.py
βΒ Β βββ cli
βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ triangulate.py
βΒ Β βββ datasets.py
βΒ Β βββ dynlag.py
βΒ Β βββ gis.py
βΒ Β βββ pipeline
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ cli.py
βΒ Β βΒ Β βββ process
βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βββ postprocess
βΒ Β βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ cli.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ generate.py
βΒ Β βΒ Β βΒ Β βββ preprocess
βΒ Β βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ cli.py
βΒ Β βΒ Β βΒ Β βββ utils.py
βΒ Β βΒ Β βββ split
βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ structs.py
βΒ Β βΒ Β βββ sync
βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βββ cli.py
βΒ Β βΒ Β βββ utils.py
βΒ Β βββ signals.py
βΒ Β βββ utils.py
βββ poetry.lock # lock file generated by python poetry for dependency mgmt
βββ pyproject.toml # general information file, handled by python poetry
There are a number of files and folders that are not committed due to their large and static nature that renders them inappropriate for git version control. The following files and folder warrant a brief explanation.
- Certain functions (time since sunset, sun elevation) of the Nowcast Library rely on the use of a .bsp file, containing information on the locations through time of various celestial bodies in the sky. This file will be automatically downloaded upon using one of these functions for the first time.
- The examples scripts make use of a
data/
directory containing a series of csv files. Most of the data used in the examples can be downloaded from the ESO Ambient Condition Database. Users can then change the paths set in the examples to fit their needs. For users interested in replicating the exact structure and contents of the data directory, a compressed copy of it (1.08 GB) is available to ESO members through this Microsoft Sharepoint link. - At times the examples show the serialization functionality of the nowcastlib
pipeline or need to output some data. In these situations the
output/
directory in the examples folder is used.
This repository relies on Poetry for tracking dependencies, building and publishing. It is therefore recommended that developers install poetry and make use of it throughout their development of the project.
Make sure you are in the right Python environment and run
poetry install
This reads pyproject.toml, resolves the dependencies, and installs them.
The repository is published to PyPi, so to make it
accessible via a pip install
command as mentioned earlier.
To publish changes follow these steps. Ideally this process is automated via a CI tool triggered by a push/merge to the master branch:
-
Optionally run
poetry version
with the appropriate argument based on semver guidelines. -
Update the documentation by running
make document
-
Prepare the package by running
poetry build
-
Ensure you have TestPyPi and PyPi configured as your poetry repositories:
poetry config repositories.testpypi https://test.pypi.org/legacy/ poetry config repositories.pypi https://pypi.org/
-
Publish the repository to TestPyPi, to see that everything works as expected:
poetry publish -r testpypi
-
Stage, commit and push your changes (to master) with git.
-
Publish the repository to PyPi:
poetry publish -r pypi
Upon successful deployment, the library should be available for install via
pip