Warning
CCMORPH2 (version 2.0) is no longer supported. The new official fork of the software is available here: CMORPH.
The toolbox is series of Python scripts accompanied with JavaScript tool that can be utilized to analyse dynamics of coastal cliffs based on DEM from different sources such as GPS-RTK, UAVs, aerial or terrestrial LiDAR scanners. Python scripts are client-based (run locally), while Java Script tool can be run as a server-based application (in a web-browser environment).
The repository includes Python tools for automatic analysis of input data (generator-py, finder-py and analyser-py), a web tool that allows manual correction of selected coastal characteristic points (base and top of the profile), and sample data and configurations demonstrating how the tools work.
The repository also includes Jupyter notebook scripts for automatic comparison of output data (csv_compared-ipynb, csv_compared_2-ipynb, dem_compared-ipynb, figures-ipynb and figures_compared-ipynb)
The program is used to generate elevation profiles based on a given coastal DEM file (geotiff), a specified shoreline (SHP line) and a trimming area (SHP polygon). Basic parameters such as input and output data paths or transect parameters (lengths and spacing) can be set in the config.json file. Note that for a shoreline and a trimming area, in addition to *.shp files, *.prj files should be prepared, containing information about coordinate reference systems. In the configuration (shapes/coastline/dst_crs and shapes/buffer/dst_crs), you have to specify a system they are being transformed to for further calculations.
Both final results and all intermediate results are stored in separate files that can be used, for example, by finder-py, analyzer-py or click-the-coast-js
What does the program do?
- validates input data
- creates or cleans directories for output and intermediate data
- initializes the database
- generates transects based on shoreline (
data/input/coast) - creates buffers around transects and for each buffer creates a DEM based on the overall image (
data/input/dem) - generates elevation profiles from transects and trimmed DEM models
- trims profiles to the specified area (
data/input/crop) and saves them (data/output/profiles/cropped) - saves data for profile visualization in click-the-coast-js web application (
data/output/web/geotif,data/output/web/geojdon,data/output/web/names)
The default configuration of the program can be changed by editing the generator-py/config.json file. Among other things, we can specify:
- directory paths for input data,
- directory paths for output data,
- the path to the database,
- parameters of generated transects,
- parameters of layers in the database (names, crs, ...), etc.
The program allows you to automatically determine the base and the top of a cliff on each profile by approximating the distance between shoreline and the cliff top. A new feature has been implemented in the methodology of the finder-py script which is called “beyond_top_buffer”. It refers to the distance between the maximum height point (top point of the cliff) to the last point determined by the algorithm. It informs how far beyond the highest point of the profile the profile itself ends (as long as we do not go beyond its maximum range).
- reads the trimmed profiles generated by generator-py (
data/output/profiles/cropped) - finds the base and the top on the profiles (choose one of the methods described in the article)
- saves finder.csv results to two directories (
data/output/resultsanddata/output/web/results) - optionally saves calculation details for each profile for method no. 1 (
data/output/debug)
- paths to the input data,
- paths to the output data,
- the selected method of determining points (1 or 2),
- optional profile smoothing parameters,
- optional debug parameters, etc.
A web application that visualizes elevation profiles for which the base and the top could not be automatically determined. It allows you to manually set both parameters of the profile. The profile is displayed as a line on the map (top view) and an intersection (side view). Basic parameters, such as paths, can be set in scripts/config.js file).
- reads profile names generated by generator-py (
data/output/web/names/names.json) - reads trimmed profiles (
output/web/geojson) and BBOXes (bounding boxes) (data/output/web/geotiff) - reads information about profiles for which base and top have already been automatically determined by finder-py (
data/output/results/finder.csv) - visualizes profiles without designated bases and tops and allows you to mark them manually
- saves the results to a csv file (
data/output/web/results/manual.csv)
NOTE: Click-the-coast-js is a web-based application. Practically all the application logic is executed on the client side (JavaScript). Only the saving to a file of points marked on the map is performed on the server side and requires the PHP interpreter. The application can therefore be run using any web server supporting PHP. Since the application can only refer to the directory in which it is placed, so the necessary data must be copied to and from it. The easiest way is to move a piece of the data/output/web directory hierarchy to the application directory. Remember to manually copy the manual.csv file created by the application to the original results directory so that analyzer-py can use it!
The default configuration can be changed by editing the click-the-coast-js/scripts/config.js file. Among other things, you can set:
- path to the directory with profiles,
- path to the directory with bbox files,
- path to the file with profile names,
- map parameters, etc.
The program collects information about the bases and tops of profiles (generated automatically or marked manually) and calculates their properties such as distance, slope and volume. Parameters should be set in the config.json file.
- reads the trimmed profiles generated by generator-py (
data/output/profiles/cropped) - reads information about profiles whose base and top have already been automatically determined by finder-py (
data/output/web/results/finder.csv) - reads the results of click-the-coast-js, i.e. bases and tops marked manually (
data/output/web/results/manual.csv- remember to copy this file after using click-the-coast-js from the web application's data directory) - determines profile parameters (distance, slope, volume) for designated bases and tops
- saves the results in a csv file (
data/output/finall) - saves lists of tops and bases separately to shp files (
data/output/finall)
- paths to the input data,
- paths to the output data,
- format of csv file with results from finder-py, etc.
The script takes the generated CSV file from analyzer-py for comparison, the user can input multiple CSV files for comparison.
- reads the morphological properties inside the CSV (
data/output/analyzer) - Compares the properties between inputted CSV files
- Saves the results of multiple CSVs in a single csv file (
OUTPUT_CSV_FOLDER, f'{field}_diff.csv')
The script takes the generated CSV file from analyzer-py for comparison, the user make comparison between two different CSV files.
- reads the morphological properties inside the CSV (
data/output/analyzer) - Compares the properties between both CSV files.
- Saves the results of CSVs in a single csv file (
OUTPUT_CSV_FOLDER, f'{field}_diff.csv')
Figures script is specifically implemented to generate graphical representations and comparisons of important cliff features such as cliff zero, top, and bottom points in multiple CSV files. The figures subcomponent marks these critical cliff features on automatically drawn lines according to the profile id in the corresponding CSV
- Reads the important cliff features (cliff top, bottom and zero) according to the profile_id in the given CSV.
- Generates graphical images representing the cliff features
- Saves the images in either SVG/PNG/JPG (
(OUTPUT_FOLDER, f'{title}.cut{".zoom" if zoom else ""}.jpg'))
Figures script is specifically implemented to generate graphical representations and comparisons of important cliff features such as cliff zero, top, and bottom points between two different CSV files. The figures subcomponent marks these critical cliff features on automatically drawn lines according to the profile id in the corresponding CSV
- Reads the important cliff features (cliff top, bottom and zero) according to the profile_id in the given CSV.
- Generates graphical images representing the cliff features in (SVG/PNG) format
- Saves the images in either SVG/PNG/JPG (
(OUTPUT_FOLDER, f'{title}.cut{".zoom" if zoom else ""}.jpg'))
A similar approach to representing cliff features is employed by this script, which generates a set of SVG/PNG/JPG images for a specified list of input cropped DEM files. The subcomponent marks the top, bottom and zero points of the cliff on the DEM raster.
- Reads the important cliff features (cliff top, bottom and zero) according to the profile_id in the given CSV.
- Generates graphical images with marked cliff top, bottom and zero points on a DEM raster
- Saves the images in either SVG/PNG/JPG (
(OUTPUT_FOLDER, f'{title}.cut{".zoom" if zoom else ""}.jpg'))
O jeito mais simples de rodar o toolbox: o único pré-requisito é ter o Docker (e o plugin docker compose) instalados e em execução. Não é necessário instalar Python, GDAL, Rtree ou qualquer outra dependência no host.
git clone <url-do-repositorio>
cd CCMORPH
docker compose build toolboxIsso constrói uma imagem Ubuntu 22.04 com Python 3.10, GDAL, Rtree e todos os pacotes de requirements.txt (incluindo o richdem, compilado com a correção de compatibilidade necessária).
Para rodar todos os samples de demonstração de uma vez (equivalente a ./run_demo.sh):
docker compose run --rm toolboxPara rodar apenas um sample específico:
docker compose run --rm toolbox ./run_sample.sh sample_1
docker compose run --rm toolbox ./run_sample.sh meu_dadoO diretório do projeto é montado como volume dentro do container (/app), então os resultados aparecem normalmente em demo/<sample>/output/ no host, e qualquer alteração de configuração feita localmente já é refletida no container sem precisar reconstruir a imagem.
Para abrir um shell interativo dentro do container (útil para depuração):
docker compose run --rm toolbox bashAlternativa sem Docker, testada em Debian/Ubuntu via WSL2 no Windows 11 Pro, com Python 3.10. O script init.sh automatiza toda a configuração do ambiente.
- Linux (Ubuntu/Debian) ou WSL2 no Windows
gitinstalado (sudo apt install git)- Conexão com a internet (para baixar pyenv e pacotes)
Execute na raiz do projeto:
./init.shO script realiza automaticamente:
- Instala o pyenv (se necessário) e o Python 3.10
- Instala as dependências do sistema: GDAL, Rtree, OpenBLAS
- Cria e ativa o ambiente virtual Python (
env/) - Detecta a versão do GDAL instalada e atualiza o
requirements.txt - Compila e instala o
richdemcom correção de compatibilidade - Instala todos os pacotes Python
- Monta os arquivos TIF de demo (divididos em partes no repositório)
source env/bin/activateHá cinco conjuntos de dados de teste em demo/sample_1 até demo/sample_5. Para rodar todos de uma vez (após ./init.sh, ou usando docker compose run --rm toolbox como na Opção 1):
./run_demo.shUse o script run_sample.sh passando o nome do diretório dentro de demo/ (prefixe com docker compose run --rm toolbox se estiver usando Docker):
./run_sample.sh sample_1
./run_sample.sh meu_dadoCrie um diretório em demo/ com a seguinte estrutura:
demo/meu_dado/
├── input/
│ ├── coast/ # shapefile da linha de costa (.shp + .prj + .dbf + .shx)
│ ├── dem/ # arquivo GeoTIFF do DEM
│ └── crop/ # shapefile do polígono de recorte (.shp + .prj + .dbf + .shx)
├── generator_config.json
├── finder_config.json
└── analyzer_config.json
Os arquivos de configuração seguem o modelo dos samples existentes. O campo "base" deve apontar para ../../demo/meu_dado e o CRS deve corresponder ao dos seus dados (verifique com gdalinfo ou inspecionando o .prj).
Para alterar o espaçamento entre transectos, edite o generator_config.json:
"transect": {
"distance": 10,Requer Docker instalado e em execução (independente de estar usando a Opção 1 ou 2 acima):
# Sobe a aplicação web com os dados de um sample
./ctc-start.sh demo/sample_5/output/web
# Acesse: http://localhost:8082
# Baixa os resultados corrigidos manualmente
./ctc-download.sh demo/sample_5/output/web/results
# Remove o container quando terminar
./ctc-finish.shApós baixar os resultados, rode o analyzer-py novamente para recalcular com os dados corrigidos:
./run_sample.sh sample_5
# ou, via Docker:
docker compose run --rm toolbox ./run_sample.sh sample_5Problemas mais comuns:
- Docker (Opção 1): garanta que o Docker Desktop/daemon esteja em execução antes de
docker compose build/run. No Windows, use o backend WSL2. - Instalação nativa (Opção 2): Rtree ou GDAL não instalados no sistema — use
./init.shpara instalar automaticamente - Conflito de versão entre o GDAL do sistema e o pacote Python — tanto o
init.shquanto oDockerfiledetectam a versão instalada e ajustamrequirements.txtautomaticamente - Arquivos
.shpsem o.prjcorrespondente — o CRS é obrigatório - Dado sem
.prjou com datum incorreto — verifique comogrinfo -al -so seu_arquivo.shp