The MeerTime project is a five-year program on the MeerKAT array by an international consortium that has regularly timed over 1000 radio pulsars to perform tests of relativistic gravity, search for the gravitational wave signature induced by supermassive black hole binaries in the timing residuals of millisecond pulsars, explore the interiors of neutron stars through a pulsar glitch monitoring programme, explore the origin and evolution of binary pulsars, monitor the swarms of pulsars that inhabit globular clusters and monitor radio magnetars. MeerTime has complemented the TRAPUM project and time pulsars TRAPUM discovers in surveys of the galactic plane, globular clusters and the galactic centre. In addition to these primary MeerKAT programmes, new MeerKAT timing projects will have their arrival times monitored and the data made immediately public.
This application provides a ReactJS frontend for access to the MeerKAT and Molonglo timing projects' data for authenticated astronomers and provides a Django powered graphQL API.
- Python >= 3.8
- MySQL server
- Docker
- Docker Compose
-
Clone the repository and move into
backenddirectory. -
Install python packages using python poetry: To install
poetry, follow the instructions on their website. As of Nov. 24 the instructions were to installpipx, to then runpipx install poetry. There is no need to create an environment for this project aspoetrywill take care of it. Instead, addpoetry runbefore running any Python scripts from this project.
Run poetry install --no-dev for minimum install. This only installs required production packages.
Run poetry install to also install development packages such as testing tools.
-
Prepare the environment running
cp .env.template .env. Do not change any fields tobackend/.envyet. -
Install
postgresqlwithsudo apt install postgresql postgresql-contrib libpq-dev.
If you have a Mac, install with brew: brew install postgresql libpq redis. You also need to change REDIS_SERVER=redis://localhost:6379 in your backend/.env file.
- Create the
postgresqldatabase and themeertimedatabase user using the following commands (filling in the$value and copying it in yourbackend/.env). If you have a Mac, replace the first line withpsql postgres. You are opening a postgreSQL shell in databasepostgresas your shell user.
sudo -u postgres psql
CREATE DATABASE meertime; CREATE USER meertime WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD'; ALTER ROLE meertime SET client_encoding TO 'utf8'; ALTER ROLE meertime SET default_transaction_isolation TO 'read committed'; ALTER ROLE meertime SET timezone TO 'UTC'; ALTER USER meertime CREATEDB; \q
The last command is to be able to run poetry run python manage.py test. Also, change POSTGRES_DATABASE=meertime and POSTGRES_USER=meertime in your backend/.env.
To then load a local copy of the database, ask ADACS for a copy (here named prd.meertime.sql) and do: pg_restore -U meertime -d meertime -h localhost -p 5432 -v prd.meertime.sql. You can check this step was successful using the postgreSQL shell (see 5.) by running \du and \l.
-
Migrate all the changes to the database if any, so it is in the correct format:
poetry run python manage.py migrate. -
Create Django superuser. Execute the following in the
backendfolder:poetry run python manage.py createsuperuserto create a Django admin that will be able to log in on the Django admin page: http://localhost:8000/admin. You will have to login using e-mail. -
Start the development server: run
poetry run python manage.py runserverand open the Django development server. -
Run tests on the backend development server to check it is all working. In the
backendfolder run:poetry run python manage.py test.
The React frontend is currently only available locally (not using Docker compose) while in development.
- NPM (installation guide)
- NVM (installation guide)
- Start Django server (see
djangoalias creation below) - Open the frontend directory at
frontend - Run
nvm use - Install required packages with
npm install --legacy-peer-deps - Generate the relay schema with
npm run relay - Run tests to make sure everything is setup correctly with
npm test. - Start the server with
npm run devand open http://localhost:X where X is the local address the output of the command gives you. - More tests can be run using
npm run cypress.
You likely want to create at least one Django user via that admin page although the superuser will be able to view the data as well. If you want to mimick the actual setup more closely, you can also setup a second user with permissions to create observations (dataportal | observations | Can add observations) and use that user for ingesting data.
You can set up the following aliases in your .bashrc (.zshrc for Mac) to set up Django then React locally, replacing paths as required:
alias djangomanage="cd yourpath/meertime_dataportal/backend/ && poetry run python manage.py"
alias django="cd yourpath/meertime_dataportal/backend/ && poetry run python manage.py makemigrations && poetry run python manage.py migrate && poetry run python manage.py graphql_schema && poetry run python manage.py runserver"
alias react="cd yourpath/meertime_dataportal/frontend/ && npm run relay && npm run dev"
GraphQL queries can be made at http://localhost:8000/graphql/ or running a Django shell in the backend directory: poetry run python manage.py shell_plus.
- Clone the repository.
- (optional but recommended) prepare environment and set it up with
set -a; source src/.envwheresrc/.envis based onsrc/.env.template. Note that if you're using .env file in docker-compose, you need to setDB_HOSTtomysql - Run
docker-compose up.
Currently, manual initialisation of the DB and migration are required. To do this, get a shell in the django container:
docker exec -it $(docker container ls | grep meertime | grep django | awk '{print $1}') /bin/bash. Then create users as detailed above in the local server instructions.
When building the images, we recommend running:
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose up --build
for optimal image size and build speed.
If you want to use DEVELOPMENT_MODE=True in docker-compose, the process is slightly different. First, you need to build the images:
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose build --build-arg DEVELOPMENT_MODE=True
followed by bringing the images up:
docker-compose up
Contributions can be made to the code base on GitLab.
To manually run tests of the backend, execute poetry run python manage.py test while in the backend directory.
To manually run tests of the frontend, run npm run cypress in the frontend directory.
Requirements are managed using python poetry.
- Run
poetry add helloto add packagehello(production, use--devfor development) - Run
poetry install
Local install:
From the backend folder: poetry env list then poetry env remove the relevant environment.
From the frontend folder, use npm to uninstall.