Skip to content

Database of observation targets for target selection and fiber allocation

License

Notifications You must be signed in to change notification settings

Subaru-PFS/ets_target_database

Repository files navigation

PFS Target Database

About The Project

PFS Target Database (targetdb) is a Python package to manage and interact with a PostgreSQL database for Prime Focus Spectrograph at Subaru Telescope. The targetdb is designed to store information from the observatory and observers on proposals and science targets. It also stores information on sky positions and flux standard stars required for PFS observation.

Please see the documentation for more details.

Prerequisites

PostgreSQL database

You need a PostgreSQL server to host the database. If you do not have a PostgreSQL server, you can use a Docker container to host a database for testing without affecting the host environment. To set up a PostgreSQL Docker container, you need to install Docker from Docker Hub.

Q3C extension

The Q3C extension is required for the database. You can install it by the following instruction in the q3c repository

Python environment

Python and the following packages as well as their dependencies will be used by installing targetdb. Package versions shown here are those used for the development (as of April 2024). Newer (and somewhat older) versions should also work.

Package Version
Python 3.9.18
SQLAlchemy 2.0.29
pandas 2.2.2
NumPy 1.26.4
Astropy 6.0.1
loguru 0.7.2
SQLAlchemy-Utils 0.41.2
tabulate 0.9.0
alembic 1.13.1
pyarrow 15.0.2
Typer 0.12.3
openpyxl 3.1.2

If you are using Python 3.10 or earlier, you may need to install tomli package.

Package Version
tomli 2.0.1

For building the documentation, the following packages are required.

Package Version
MkDocs 1.5.3
mkdocs-material 9.5.18

Additionally, the following tools may be useful for testing and development.

Getting Started

Installation

# Clone the repository and go to the cloned directory.
git clone https://github.com/Subaru-PFS/ets_target_database.git
cd ets_target_database

# (optional) Create a virtual environment
# python3 -m venv .venv
# source .venv/bin/activate

# Install the package in the development mode
python3 -m pip install -e .

By doing this, Python imports targetdb package directly from the cloned directory, which is convenient for development. If you want to install the package under the Python library directory, you can execute python3 -m pip install ..

The installation process will install some command-line tools under the directory where your Python executable is located.

Usage Examples

Here, we show a few examples of how to use the targetdb package.

Setup a PostgreSQL server (optional)

If a postgres database server to create targetdb is not running, you can easily make one as a Docker container.

cd example/docker/
docker compose build
docker compose -up -d

In this example, the local port 15432 is mapped to the port 5432 inside the container. The database data will be stored in the examples/docker/db-data directory and can be accessed from the host by using the PostgreSQL client via the port 15432 (see examples/docker/db-conf.toml).

Create targetDB

Following commands create a database and tables as configured in the dbconf.toml file.

# create a database
pfs-targetdb-cli create-db -c dbconf.toml

# install the Q3C extension
pfs-targetdb-cli install-q3c -c dbconf.toml

# create tables in the database
pfs-targetdb-cli create_schema -c dbconf.toml

Generate an ER diagram of the database

Using SchemaCrawler, you can make an Entity Relationship diagram (ERD) of the targetdb.

# draw the ER diagram
pfs-targetdb-cli diagram -c dbconf.toml

Insert test data into tables

In the examples/data directory, example data files are located. You can insert them into the database by the following commands.

pfs-targetdb-cli insert -c dbconf.toml -t proposal_category examples/data/proposal_category.csv --commit
pfs-targetdb-cli insert -c dbconf.toml -t proposal examples/data/proposals.csv --commit
pfs-targetdb-cli insert -c dbconf.toml -t input_catalog examples/data/input_catalogs.csv --commit
pfs-targetdb-cli insert -c dbconf.toml -t target_type examples/data/target_types.csv --commit
pfs-targetdb-cli insert -c dbconf.toml -t filter_name examples/data/filter_names.csv --commit

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Masato Onodera - GitHub

Project Link: https://github.com/Subaru-PFS/ets_target_database

References