Skip to content

Commit

Permalink
Merge pull request #16 from ImperialCollegeLondon/feat/db-app-plus-po…
Browse files Browse the repository at this point in the history
…da-and-sdc

Feat/db app plus poda and sdc
  • Loading branch information
alastairtree authored Aug 5, 2024
2 parents 68daf32 + 508fca7 commit 4320699
Show file tree
Hide file tree
Showing 57 changed files with 2,173 additions and 264 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ ENV PATH="$PYENV_ROOT/bin:$PATH"
RUN curl https://pyenv.run | bash
RUN $PYENV_ROOT/bin/pyenv install -v ${PYTHON_VERSIONS}

USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
postgresql-client
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"remoteEnv": {
// add the pyenv bin and poetry to the PATH for the dev user vscode
"PATH": "/home/vscode/.pyenv/bin:/home/vscode/.local/bin:${containerEnv:PATH}",
"WEBPODA_AUTH_CODE": "${localEnv:WEBPODA_AUTH_CODE}"
"WEBPODA_AUTH_CODE": "${localEnv:WEBPODA_AUTH_CODE}",
"SDC_AUTH_CODE": "${localEnv:SDC_AUTH_CODE}",
"IMAP_DATA_ACCESS_URL": "${localEnv:IMAP_DATA_ACCESS_URL}",
},
"postCreateCommand": "pip install --user -U pre-commit && pre-commit install-hooks && pre-commit autoupdate",
// install poetry in first startup in vscode
Expand Down
7 changes: 7 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DB Connection string
SQLALCHEMY_URL=postgresql://USER_HERE:PASSWORD_HERE@db:5432/imap

# API credentials fpr LASP PODA API - See https://lasp.colorado.edu/ops/imap/poda/
WEBPODA_AUTH_CODE=
# API credentials for SDC API - See https://github.com/IMAP-Science-Operations-Center/imap-data-access
SDC_AUTH_CODE=
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
# use custom value instead of git tag
type=semver,pattern={{version}},value=${{ env.PACKAGE_VERSION }}
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest
# branch event
type=ref,event=branch
# pull request event
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ dmypy.json

# mkdocs build dir
site/
src/main.py

.work
/output
deploy/test-env/ssh_test_keys/
dev.env
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"args": [
"process",
"--config",
"config.yml"
"config.yaml"
],
"console": "integratedTerminal",
"justMyCode": true,
Expand Down
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,20 @@
"cSpell.words": [
"xtce",
"xtcedef"
],
"python.analysis.extraPaths": [
"./src"
],
"sqltools.connections": [
{
"previewLimit": 50,
"server": "host.docker.internal",
"port": 5432,
"driver": "PostgreSQL",
"name": "postgres",
"password": "",
"database": "imap",
"username": "postgres"
}
]
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ To use WebPODA APIs, an access token needs to be defined in the environment as `
pre-commit install
```

5. To use the docker /data mount you need a folder on your WSL and a user with a given UID

```bash
# in WSL on your HOST
mkdir -p /mnt/imap-data
sudo adduser -u 5678 --disabled-password --gecos "" appuser
# you have created the user with the same UID as in the container. now grant the folder to the user
chown -R appuser:appuser /mnt/imap-data
```

### Build, pack and test

```bash
Expand Down
2 changes: 1 addition & 1 deletion build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mkdir -p dist

docker run \
--volume "$(pwd):/src/" \
--volume "$(pwd):/src/imap_mag" \
batonogov/pyinstaller-linux:latest \
"rm -rf dist/pyinstaller && \
python3 -m pip install poetry && \
Expand Down
2 changes: 1 addition & 1 deletion build-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mkdir -p dist

docker run \
--volume "$(pwd):/src/" \
--volume "$(pwd):/src/imap_mag" \
batonogov/pyinstaller-windows:latest \
"rm -rf dist/pyinstaller && \
python -m pip install poetry && \
Expand Down
8 changes: 8 additions & 0 deletions calibration_application_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source:
folder: /data/science/imap/mag/l1b/2025/05

work-folder: .work

destination:
folder: /data/science/imap/mag/l2/2025/05
filename: imap_mag_l2_norm-mago_20250511_v000.cdf
8 changes: 8 additions & 0 deletions calibration_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source:
folder: /data/science/imap/mag/l1b/2025/05

work-folder: .work

destination:
folder: /data/science/imap/mag/l1b/2025/05
filename: calibration.json
11 changes: 11 additions & 0 deletions config-hk-download.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source:
folder: /data/hk_l0/

work-folder: /data/.work

destination:
folder: /data/hk_l0/
filename: power.pkts

packet-definition:
hk: src/imap_mag/xtce/tlm_20240724.xml
11 changes: 11 additions & 0 deletions config-hk-process.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source:
folder: /data/hk_l0/

work-folder: /data/.work

destination:
folder: /data/hk_l1/
filename: result.csv

packet-definition:
hk: src/imap_mag/xtce/tlm_20240724.xml
11 changes: 11 additions & 0 deletions config-sci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source:
folder: tests/data/2025

work-folder: /data/science

destination:
folder: output/
filename: result.cdf

packet-definition:
hk: src/imap_mag/xtce/tlm_20240724.xml
2 changes: 1 addition & 1 deletion config.yml → config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ destination:
filename: result.cdf

packet-definition:
hk: src/xtce/tlm_20240724.xml
hk: src/imap_mag/xtce/tlm_20240724.xml
10 changes: 10 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

COPY deploy/entrypoint.sh /app/entrypoint.sh
COPY *.yaml /app/

#TODO: this is a hack mounting the src folder to the container
COPY src/imap_mag/xtce/*.xml /app/src/imap_mag/xtce/

COPY dist/python${PYTHON_VERSION}/${TOOL_PACKAGE} /app/python${PYTHON_VERSION}/

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers

RUN adduser -u 5678 --disabled-password --gecos "" appuser && \
chown -R appuser /app && \
mkdir -p /data && \
chown -R appuser /data && \
chmod +x /app/entrypoint.sh

# Install the postgres client and any other dependencies needed to install our app
RUN apt-get update && apt-get install -y libpq-dev gcc

WORKDIR /app
USER appuser

Expand Down
27 changes: 24 additions & 3 deletions deploy/entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
#!/bin/bash
set -e

echo "Starting IMAP MAG pipeline..."
sleep 20

imap-db create-db

imap-db upgrade-db

echo "DB admin complete"

while :
do
imap-mag hello world
# delete all data
rm -rf /data/*

START_DATE='2025-05-02'
END_DATE='2025-05-03'

imap-mag fetch-binary --config config-hk-download.yaml --apid 1063 --start-date $START_DATE --end-date $END_DATE

imap-mag process --config config-hk-process.yaml power.pkts

imap-mag fetch-science --level l1b --start-date $START_DATE --end-date $END_DATE --config config-sci.yaml

imap-db query-db

imap-mag calibrate --config calibration_config.yaml --method SpinAxisCalibrator imap_mag_l1b_norm-mago_20250511_v000.cdf

imap-mag fetch-binary --config tests/config/hk_download.yaml --apid 1063 --start-date 2025-05-02 --end-date 2025-05-03
imap-mag process --config tests/config/hk_process.yaml MAG_HSK_PW.pkts
imap-mag apply --config calibration_application_config.yaml --calibration calibration.json imap_mag_l1b_norm-mago_20250511_v000.cdf

ls -l /data

Expand Down
Loading

0 comments on commit 4320699

Please sign in to comment.