A Tethys app for building tRIBS models for SRP studies.
-
Install libmamba and make it your default solver (see: A Faster Solver for Conda: Libmamba):
conda update -n base conda conda install -n base conda-libmamba-solver conda config --set solver libmamba
-
Clone Tethys and create an environment with Python 3.10 and Django 4.2 using conda:
git clone https://github.com/tethysplatform/tethys.git cd tethys # IMPORTNANT: edit the environment.yml to force python=3.10 and django>=4.2,<5 conda env create -n <ENV_NAME> -f environment.yml pip install -e .
NOTE: replace <ENV_NAME> with the name you want the environment to be called (e.g. tethys, tethys310).
-
Activate the Tethys environment:
conda activate <ENV_NAME>
NOTE: replace <ENV_NAME> with the name gave the environment in Step 2.
-
Install PostGIS, GeoServer, and Redis using Docker:
sudo docker run --name=tribs_postgis --env=POSTGRES_PASSWORD=mysecretpassword -p 5437:5432 -d postgis/postgis:12-2.5 sudo docker run --name=tribs_geoserver --env=ENABLED_NODES=4 --env=REST_NODES=1 --env=NUM_CORES=4 --env=MAX_TIMEOUT=60 --env=MAX_MEMORY=1024 --env=MIN_MEMORY=512 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -p 8181:8181 -d tethysplatform/geoserver:latest sudo docker run --name=srp_redis -p 6379:6379 -d redis:7
NOTE: if you have another PostGIS database bound to port 5437, you can change the first port number to something else, like 5438.
NOTE: the MAX_MEMORY and MIN_MEMORY parameters are per-core allocations (x4 if you have 4 node enabled). Adjust to your machine's capabilities.
-
Create the Tethys portal_config.yml and :
tethys gen portal_config
-
Open the portal_config.yml using the path printed in the output from the previous command. Change the database settings to the following so that Tethys will use the PostGIS database. Also take this time to setup your media url and root:
settings: DATABASES: default: ENGINE: django.db.backends.postgresql USER: tethys_super PASSWORD: pass HOST: localhost PORT: 5437 NAME: tethys_platform MEDIA_URL: '/media/' MEDIA_ROOT: '<path_to_app_workspaces_dir_in_app>' CHANNEL_LAYERS: tribs: BACKEND: channels_redis.core.RedisChannelLayer CONFIG: hosts: - [127.0.0.1, 6379]
NOTE: If you changed the port when you created the PostGIS docker container in step 3, change the PORT database setting in the portal_config.yml to match.
-
Initialize the Tethys Platform database:
PGPASSWORD=mysecretpassword tethys db configure
-
Clone ATCore and install into the Tethys environment in development mode:
git clone https://github.com/Aquaveo/tethysext-atcore.git # edit install.yml to force django>=4.2,<5 cd tethysext-atcore tethys install -d cd ../
-
Install the PDM dependency manager:
pip install --user pdm
NOTE: if you have previously installed pdm in another environment, uninstall pdm first (
pip uninstall pdm), and then reinstall as shown above with the new environment active. -
Install Node Version Manager and Node.js:
a. Install Node Version Manager (nvm): https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script
b. CLOSE ALL OF YOUR TERMINALS AND OPEN NEW ONES
c. Use NVM to install Node.js 20:
nvm install 20 nvm use 20
-
If after installing pdm you see warning messages that say "WARNING: The script dotenv is installed in '<some_path>' which is not on PATH.", do the following to add <some_path> to your PATH:
a. Open your
~/.bashrcfile in a text editor and add the following line to the end of the file (replace <some_path> with the path from the warning messages):export PATH=<some_path>:$PATH
b. Deactivate your Tethys environment and run the
~/.bashrcscript:conda deactivate source ~/.bashrc
-
Install GDAL libraries and the C/C++ compilers with Conda from conda-forge:
conda install -c conda-forge libgdal gdal pyproj cxx-compiler
-
Clone tribs-adapter and install into the Tethys environment in development mode:
git clone git@github.com:Aquaveo/tribs-adapter.git cd tribs-adapter pdm install cd ../
NOTE:
pdm installinstalls the package as an editable package and installs dependencies AND dev dependencies but NOT optional dependencies. -
Clone tethysapp-tribs and install into the Tethys environment in development mode:
git clone git@github.com:Aquaveo/tethysapp-tribs.git cd tethysapp-tribs pdm install npm install --include=dev cd ../
NOTE:
pdm installinstalls the package as an editable package and installs dependencies AND dev dependencies but NOT optional dependencies. -
Install SSH server and create development ssh key for condor to use:
a. Install and start ssh server
sudo apt install openssh-server sudo systemctl start ssh
b. Create condor key named "condorkey" with password "tribs"
ssh-keygen -t rsa -N tribs -f ~/.ssh/condorkeyc. Add the public key to the authorized keys
# if you don't have an authorized_keys file yet cp ~/.ssh/condorkey.pub ~/.ssh/authorized_keys # if you do, just cat condorkey.pub and copy it to a new line in authorized_keys cat ~/.ssh/condorkey.pub vim ~/.ssh/authorized_keys
d. Verify that you can log in with ssh using the key. You should be prompted for the passkey, but not your user password.
ssh -i ~/.ssh/condorkey -p 22 <youruser>@localhost # don't forget to logout of your ssh session exit
-
Set up HTCondor
a. Install HTCondor: see https://htcondor.readthedocs.io/en/latest/getting-htcondor/install-linux-as-root.html
b. Start HTCondor: see https://htcondor.readthedocs.io/en/latest/admin-manual/installation-startup-shutdown-reconfiguration.html
c. Verify that HTCondor is running: see "Verifying a Single-Machine Installation" here: https://htcondor.readthedocs.io/en/latest/getting-htcondor/install-linux-as-root.html
d. Create a symbolic link to your tethys conda environment Python for condor jobs to use:
conda activate <ENV_NAME> sudo ln -s $(which python) /opt/tethys-python
-
Create a Cesium-Ion account and get an API key: see https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/
-
Start Tethys and Navigate to Admin Pages.
a. Create a SpatialDatasetService pointing to the GeoServer container
* Name: <whatever_you_want> * Engine: GeoServer * Endpoint: http://localhost:8181/geoserver/rest/ * Public_endpoint: http://<ip_address>:8181/geoserver/rest/ * Apikey: * Username: admin * Password: geoserverb. Create a PersitentStoreService pointing to the PostGIS database container
* Name: <whatever_you_want> * Engine: PostgreSQL * Host: <ip_address> * Port: 5435 * Username: tethys_super * Password: pass <or_password_set_when_setting_up_tethys>c. Create an HTCondorScheduler pointing to the HTCondor scheduler
* Name: <whatever_you_want> * Host: localhost * Username: <youruser> * Password: * Private key path: /home/<youruser>/.ssh/condorkey * Private key pass: tribsd. Go to the app settings and link the appropriate services to the service settings of the app and fill in the cesium API key setting with the key from step 17.
-
Run syncstores to intialize the persistent store:
tethys manage syncstores tribs
-
Run the init command for the tribs app:
tribs init http://admin:geoserver@localhost:8181/geoserver/rest/ postgresql://tethys_super:pass@localhost:5435/tribs_primary_db
The webpack dev server is configured to proxy the Tethys development server (see webpack.config.js). The app endpoint will be handled by the webpack development server and all other endpoints will be handled by the Tethys (Django) development server. As such, you will need to start both in separate terminals.
-
Start Tethys development server
tethys manage start -
Start webpack development server (in separate terminal)
npm start
See below for more PDM tips like how to manage dependencies, install dependencies, and run scripts.
-
Install all dev dependencies (test & lint)
pdm install -G:all
-
Install only test dependencies
pdm install -G test -
Install only lint and formatter dependencies
pdm install -G lint
- Add a new dependency:
-
Add the package using
pdm:pdm add <package-name>
-
Manually add the dependency to the
install.yml.IMPORTANT: Dependencies are not automatically added to the
install.ymlyet!
-
Add a new dev dependency:
pdm add -dG test <package-name> pdm add -dG lint <package-name>
NOTE: Just use
pdmto install and manage dev dependencies. Theinstall.ymldoes not support dev dependencies, but they shouldn't be needed in it anyway, right? -
Add a new optional dependeny:
pdm add -G <group-name> <package-name>
NOTE: You'll need to decide whether or not to add the optional dependencies to the
install.ymlb/c it does not support optional dependencies. You may consider usingpdmto manage the optional dependencies. -
Remove a dependency:
-
Remove it from the
pyproject.yamland lock file:pdm remove --no-sync <package-name>
-
Manually remove it from the
install.yml -
If you want to remove it from the environment, use
piporcondato remove the package.IMPORTANT: TL;DR: Running
pdm removewithout the--no-syncwill remove nearly all of the dependencies in your environment. Whilepdm removeis capable of removing the package from the environment, runningpdm removewithout the--no-syncoption can break your Tethys environment. This is becausepdmwill attempt to get the environment to match the dependencies listed in yourpyproject.toml, which usually does not include all of the dependencies of Tethys.
The project is configured with several PDM convenience scripts:
```bash
# Run linter
pdm run lint
# Run formatter
pdm run format
# Run tests
pdm run test
# Run all checks
pdm run all
```
This package is configured to use yapf code formatting
-
Install lint dependencies:
pdm install -G lint
-
Run code formatting from the project directory:
yapf --in-place --recursive --verbose . # Short version yapf -ir -vv .
-
Run linter from the project directory:
flake8 .NOTE: The configuration for yapf and flake8 is in the
pyproject.toml.
This package is configured to use pytest for testing
-
Install test dependencies:
pdm install -G test -
Run tests from the project directory:
pytest
NOTE: The configuration for pytest and coverage is in the
pyproject.toml.
Webpack is configured to bundle and build the React app into the tethysapp/<app_package>/public/frontend directory. Before building a Python distribution for release, you should build using this command:
npm run build
Use the following commands to lint and test the React portion of the app.
npm run lint
npm run test
The linting capability is powered by eslint and a number of plugins for React. The testing capabilities include jest, jsdom, testing-framework, user-event, and a few other JavaScript testing utilties to make it easy to test the frontend of the React-Tethys app.
The React + Django implementation is based on the excellent work done by @Jitensid that can be found on GitHub here: Jitensid/django-webpack-dev-server.