# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['necstdb', 'necstdb.utils']

package_data = \
{'': ['*']}

install_requires = \
['numpy>=1.19.0,<2.0.0', 'pandas>=1.1.0,<2.0.0']

setup_kwargs = {
    'name': 'necstdb',
    'version': '0.2.5',
    'description': 'Database for NECST.',
    'long_description': '# NECSTDB\n\n[![PyPI](https://img.shields.io/pypi/v/necstdb.svg?label=PyPI&style=flat-square)](https://pypi.org/pypi/necstdb/)\n[![Python](https://img.shields.io/pypi/pyversions/necstdb.svg?label=Python&color=yellow&style=flat-square)](https://pypi.org/pypi/necstdb/)\n[![Test](https://img.shields.io/github/workflow/status/ogawa-ros/necstdb/Test?logo=github&label=Test&style=flat-square)](https://github.com/ogawa-ros/necstdb/actions)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?label=License&style=flat-square)](LICENSE)\n\nDatabase for NECST.\n\n## TL;DR\n\nNECST, an abbreviation of *NEw Control System for Telescope*, is a flexible control system for radio telescopes. Its efficient data storage is provided here.\n\nThe database contains tables, which keep individual topic of time series data with some metadata attached to them, e.g. spectral data from one spectrometer board (array of data + timestamp), weather data (temperature + humidity + wind speed + ... + timestamp), etc.\n\n## Features\n\nThis package provides:\n\n- database writer with quite flexible data format support\n- database reader which supports various output format\n\n## Installation\n\n```shell\npip install necstdb\n```\n\n## Usage\n\n### Database Writer\n\n1. Create new database instance\n\n    ```python\n    >>> db_dir = "path/to/new_database_directory"\n    >>> db = necstdb.opendb(db_dir, mode="w")  # "w" stands for "write"\n    ```\n\n2. Create table with data information\n\n    ```python\n    >>> data1_info = {\n    ...     "data": [\n    ...         {"key": "recorded_time", "format": "d", "size": 8},\n    ...         {"key": "n_scan_lines", "format": "i", "size": 4},\n    ...         {"key": "obsmode", "format": "3s", "size": 3},\n    ...         {"key": "timestamp", "format": "d", "size": 8},\n    ...     ],\n    ...     "memo": "generated by db_logger_operation",\n    ...     "necstdb_version": necstdb.__version__,\n    ... }\n    >>> db.create_table("data1", data1_info)\n    ```\n\n    The keys "key" and "format" in "data" list are required. The format characters and the sizes are listed below. For more information, see the struct module [documentation](https://docs.python.org/3/library/struct.html#format-characters) and/or the ROS message [wiki](http://wiki.ros.org/msg).\n\n    - *Changed in v0.2.5: "size" in "data" list is no longer required, but is optional.*\n\n    The "memo" and "necstdb_version" keys are not necessary. You can also add any other keys to the data information dict.\n\n    | ROS format | Format character | Size \\[byte\\] |\n    | ---------- | ---------------- | ------------- |\n    | bool       | ``?``            | 1             |\n    | int8       | ``b``            | 1             |\n    | int16      | ``h``            | 2             |\n    | int32      | ``i``            | 4             |\n    | int64      | ``q``            | 8             |\n    | uint8      | ``B``            | 1             |\n    | uint16     | ``H``            | 2             |\n    | uint32     | ``I``            | 4             |\n    | uint64     | ``Q``            | 8             |\n    | float32    | ``f``            | 4             |\n    | float64    | ``d``            | 8             |\n    | string     | ``[length]s``    | 1 * length    |\n\n    ***NOTE:***\n    Array data are also supported. To write them, use repeat count syntax (e.g. ``3d``) or format character sequence syntax (e.g. ``ddd``) for the "format", and the sum of the elements\' sizes for the "size".\n\n    ```python\n    {"key": "data_array", "format": "3d", "size": 3 * 8}  # repeat count syntax\n    {"key": "data_array", "format": "ddd", "size": 8 + 8 + 8}  # format character sequence syntax\n    ```\n\n3. Write data into table\n\n    ```python\n    >>> table1 = db.open_table("data1", mode="ab")  # "ab" stands for "append binary"\n    >>> data1 = [1.6294488758e9, 3, b"SKY", 1.6294488757e9]  # string data are not allowed, use bytes instead\n    >>> table1.append(*data1)\n    ```\n\n    Call the ``append`` method every time you get new data.\n\n    ***NOTE:***\n    Data to pass to ``append`` method should be flattened. The nested structure will be reconstructed on reading.\n\n    ```python\n    data = [1, 2, [3, 4, 5], 6, 7]\n    data = necstdb.utils.flatten_data(data)\n    table.append(*data)\n    ```\n\n    ***NOTE:***\n    Multi-dimensional data are not supported.\n\n### Database Reader\n\n1. Open the database instance\n\n    ```python\n    >>> db = necstdb.opendb("path/to/database_directory")\n    ```\n\n2. Read a desired topic\n\n    ```python\n    >>> data1 = db.open_table("data1").read(astype="array")\n    >>> data1\n    array([[1.6294488758e9, 3, b\'SKY\', 1.6294488757e9], ...], dtype=[(\'recorded_time\', \'<f8\'), (\'n_scan_lines\', \'<i4\'), (\'obsmode\', \'|S3\'), (\'timestamp\', \'<f8\')])\n    ```\n\n    The supported ``astype`` keywords for ``read`` method are:\n\n    | Output type      | Keywords                                             | Notes |\n    | ---------------- | ---------------------------------------------------- | ----- |\n    | tuple            | "tuple"                                              | \\*1   |\n    | dict             | "dict"                                               |       |\n    | pandas.DataFrame | "pandas", "dataframe", "data_frame", "df"            | \\*2   |\n    | numpy.ndarray    | "array", "structuredarray", "structured_array", "sa" |       |\n    | bytes            | "buffer", "raw"                                      |       |\n\n    ***\\*1***: Array data are not supported, but will be flattened.  \n    ***\\*2***: *Changed in v0.2.5: Keyword ``df`` is now supported.*\n\n### Misc\n\n#### List all the tables contained in the database\n\n```python\n>>> db = necstdb.opendb("path/to/database_directory")\n>>> db.list_tables()\n[\'data1\', \'spectral_data\', \'weather_data\', ...]\n```\n\n#### Archive the database\n\n```python\n>>> db = necstdb.opendb("path/to/database_directory")\n>>> db.checkout(saveto="path/to/archive.tar.gz", compression="gz")\n```\n\n#### Get informations of all tables in the database\n\n```python\n>>> db = necstdb.opendb("path/to/database_directory")\n>>> db.get_info()\n"""\n                    file size [byte]    #records    record size [byte]  format\ntable name\ndata1               2448                102         24                  di3sd\nspectral_data       41948160            320         131088              d32768fd\nweather_data        6328                113         56                  ddddddd\n"""\n```\n\n#### Read particular columns and/or rows of the database\n\n```python\n>>> db = necstdb.opendb("path/to/database_directory")\n>>> data = db.open_table("data1").read(num=5, start=3, cols=["timestamp", "obsmode"], astype="tuple")  # order of cols won\'t be preserved\n((b\'SKY\', 1.6294488788e9)  # 4th element (caution 0-based indexing)\n (b\'SKY\', 1.6294488798e9)\n (b\'SKY\', 1.6294488808e9)\n (b\'SKY\', 1.6294488818e9)\n (b\'HOT\', 1.6294488828e9))\n```\n\n#### Flatten nested array\n\n```python\n>>> data = [1, 2, 3, [4, 5], 6]\n>>> flattened = necstdb.utils.flatten_data(data)\n[1, 2, 3, 4, 5, 6]\n```\n',
    'author': 'Kaoru Nishikawa',
    'author_email': 'k.nishikawa@a.phys.nagoya-u.ac.jp',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/ogawa-ros/necstdb',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6.1,<4.0.0',
}


setup(**setup_kwargs)
