Skip to content

Commit

Permalink
Merge branch 'sandialabs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tnelson-integral authored Aug 28, 2024
2 parents 80d0914 + 02a5668 commit 82d6042
Show file tree
Hide file tree
Showing 58 changed files with 6,741 additions and 146 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: QGIS Plugin CI

on:
pull_request:
branches:
- main
push:
branches:
- main
- workflow

jobs:
test-seat-package:
runs-on: ubuntu-latest
services:
docker:
image: qgis/qgis:latest
options: --user root
ports:
- 99:99

steps:
- name: Checkout qgis-plugin
uses: actions/checkout@v4

- name: Run QGIS Docker container
run: |
docker run -d --name qgis-testing-environment \
-v ${GITHUB_WORKSPACE}:/tests_directory \
-e DISPLAY=:99 qgis/qgis:latest tail -f /dev/null
- name: Wait for Docker to be ready
run: |
until docker exec qgis-testing-environment sh -c "ls /"; do sleep 1; done
- name: Install plugin by manually via Copy
run: |
docker exec qgis-testing-environment sh -c '
PLUGIN_SRC_PATH=/tests_directory/seat
PLUGIN_DEST_DIR=/usr/share/qgis/python/plugins/seat
mkdir -p $PLUGIN_DEST_DIR
cp -r $PLUGIN_SRC_PATH/* $PLUGIN_DEST_DIR/
'
- name: Install Dependencies
run: |
docker exec qgis-testing-environment sh -c "python3 /tests_directory/tests/install_dependencies.py"
docker exec qgis-testing-environment sh -c "apt-get update && apt-get install -y python3-pandas python3-netcdf4 python3-pytest"
- name: List installed packages
run: |
docker exec qgis-testing-environment sh -c "pip list"
- name: Run Pytest
run: |
docker exec qgis-testing-environment pytest /tests_directory/tests
- name: Clean up Docker container
if: always()
run: |
docker stop qgis-testing-environment
docker rm qgis-testing-environment
23 changes: 23 additions & 0 deletions create_zip.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@echo off

set TIMESLOT=%date%
echo [%TIMESLOT%] START ...................... create_zip

echo [%TIMESLOT%] COPY ....................... .\seat -> .\seat_qgis_plugin
xcopy ".\seat" ".\seat_qgis_plugin" /E /I

set RELEASE=%TIMESLOT%
echo [%TIMESLOT%] ZIP ........................ %cd%\seat_qgis_plugin_%RELEASE%.zip

:: Requires PowerShell for zip functionality
powershell.exe -Command "Compress-Archive -Path '.\seat_qgis_plugin\*' -DestinationPath '.\seat_qgis_plugin_%RELEASE%.zip'"

echo [%TIMESLOT%] RM ......................... .\seat_qgis_plugin
if exist ".\seat_qgis_plugin" (
rmdir /s /q ".\seat_qgis_plugin"
) else (
echo Directory not found: .\seat_qgis_plugin
)

set ENDTIME=%YEAR%_%MONTH%_%DAY%.%HOUR%_%MIN%
echo [%TIMESLOT%] END ........................ create_release
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sphinx_rtd_theme
sphinx_rtd_dark_mode
sphinx_copybutton
sphinx_autodoc_typehints
sphinx_autodoc_typehints
18 changes: 6 additions & 12 deletions seat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************.
StressorReceptorCalc
A QGIS plugin
This calculates a response layer from stressor and receptor layers
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-04-19
copyright : (C) 2021 by Integral Consultsing
email : [email protected]
git sha : $Format:%H$
Name : seat
Date : 2021-04-19
Contact : https://github.com/sandialabs/seat-qgis-plugin
***************************************************************************/
/***************************************************************************
Expand All @@ -25,9 +18,10 @@
"""


# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load StressorReceptorCalc class from file StressorReceptorCalc.
"""
Load StressorReceptorCalc class from file StressorReceptorCalc.
A QGIS plugin calculates a response layer from stressor and receptor layers
:param iface: A QGIS interface instance.
:type iface: QgsInterface
Expand Down
42 changes: 21 additions & 21 deletions seat/modules/acoustics_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
acoustics_module.py
Copyright 2023, Integral Consulting Inc. All rights reserved.
PURPOSE: module for calcualting acoustic signal change from paracousti files
PROJECT INFORMATION:
Expand All @@ -14,7 +14,7 @@
Eben Pendelton
Timothy Nelson ([email protected])
Sam McWilliams ([email protected])
NOTES (Data descriptions and any script specific notes)
1. called by stressor_receptor_calc.py
"""
Expand All @@ -41,7 +41,7 @@ def create_species_array(species_filename, x, y, variable='percent', latlon=Fals
Interpolates or creates an array of percent or density of species
Parameters
----------
-----------
species_filename : str
File path to species files.
x : array
Expand Down Expand Up @@ -117,7 +117,7 @@ def calculate_acoustic_stressors(fpath_dev,
fpath_nodev : str, optional
Directory path to the baseline/no device model run netcdf files. The default is None.
species_folder : str, optional
Directory path to the species files in the probabilities_file. The default is None.
Directory path to the species files in the probabilities_file. The default is None.
latlon : Bool, optional
True is coordinates are lat/lon. The default is True.
Expand Down Expand Up @@ -147,7 +147,7 @@ def calculate_acoustic_stressors(fpath_dev,
raise FileNotFoundError(f"The file {probabilities_file} does not exist.")
if not os.path.exists(receptor_filename):
raise FileNotFoundError(f"The file {receptor_filename} does not exist.")

paracousti_files = [os.path.join(fpath_dev, i)
for i in os.listdir(fpath_dev) if i.endswith('.nc')]
boundary_conditions = pd.read_csv(
Expand Down Expand Up @@ -189,7 +189,7 @@ def calculate_acoustic_stressors(fpath_dev,

if not ((fpath_nodev is None) or (fpath_nodev == "")): # Assumes same grid as paracousti_files
if not os.path.exists(fpath_nodev):
raise FileNotFoundError(f"The directory {fpath_nodev} does not exist.")
raise FileNotFoundError(f"The directory {fpath_nodev} does not exist.")
baseline_files = [os.path.join(fpath_nodev, i) for i in os.listdir(
fpath_nodev) if i.endswith('.nc')]
for ic, baseline_file in enumerate(baseline_files):
Expand Down Expand Up @@ -246,7 +246,7 @@ def calculate_acoustic_stressors(fpath_dev,

if not ((species_folder is None) or (species_folder == "")):
if not os.path.exists(species_folder):
raise FileNotFoundError(f"The directory {species_folder} does not exist.")
raise FileNotFoundError(f"The directory {species_folder} does not exist.")
species_percent_filename = boundary_conditions.loc[os.path.basename(
paracousti_file)]['Species Percent Occurance File']
species_density_filename = boundary_conditions.loc[os.path.basename(
Expand Down Expand Up @@ -275,8 +275,8 @@ def calculate_acoustic_stressors(fpath_dev,
'paracousti_stressor': stressor,
'species_threshold_exceeded': threshold_exceeded,
'species_percent': percent_scaled,
'species_density': density_scaled}
'species_density': density_scaled}

dx = np.nanmean(np.diff(rx[0, :]))
dy = np.nanmean(np.diff(ry[:, 0]))
return dict_of_arrays, rx, ry, dx, dy
Expand Down Expand Up @@ -310,7 +310,7 @@ def run_acoustics_stressor(
receptor_filename : str
File path to the recetptor file (*.csv or *.tif).
species_folder : str, optional
Directory path to the species files in the probabilities_file. The default is None.
Directory path to the species files in the probabilities_file. The default is None.
Returns
Expand All @@ -325,7 +325,7 @@ def run_acoustics_stressor(
[4] 'species_density.tif'
"""

os.makedirs(output_path, exist_ok=True) # create output directory if it doesn't exist

dict_of_arrays, rx, ry, dx, dy = calculate_acoustic_stressors(fpath_dev=dev_present_file,
Expand Down Expand Up @@ -357,7 +357,7 @@ def run_acoustics_stressor(
use_numpy_arrays.append('paracousti_risk_layer')

numpy_array_names = [i + '.tif' for i in use_numpy_arrays]

output_rasters = []
for array_name, use_numpy_array in zip(numpy_array_names, use_numpy_arrays):
numpy_array = np.flip(dict_of_arrays[use_numpy_array], axis=0)
Expand Down Expand Up @@ -395,7 +395,7 @@ def run_acoustics_stressor(

bin_layer(os.path.join(output_path, "paracousti_without_devices.tif"),
latlon=crs == 4326).to_csv(os.path.join(output_path, "paracousti_without_devices.csv"), index=False)

bin_layer(os.path.join(output_path, "paracousti_with_devices.tif"),
latlon=crs == 4326).to_csv(os.path.join(output_path, "paracousti_with_devices.csv"), index=False)

Expand All @@ -406,7 +406,7 @@ def run_acoustics_stressor(
# threshold exeeded Area
bin_layer(os.path.join(output_path, "species_threshold_exceeded.tif"),
latlon=crs == 4326).to_csv(os.path.join(output_path, "species_threshold_exceeded.csv"), index=False)

if not ((secondary_constraint_filename is None) or (secondary_constraint_filename == "")):
bin_layer(os.path.join(output_path, 'paracousti_stressor.tif'),
receptor_filename=os.path.join(output_path, "paracousti_risk_layer.tif"),
Expand All @@ -421,30 +421,30 @@ def run_acoustics_stressor(

bin_layer(os.path.join(output_path, "species_density.tif"),
latlon=crs == 4326).to_csv(os.path.join(output_path, "species_density.csv"), index=False)

if not ((secondary_constraint_filename is None) or (secondary_constraint_filename == "")):
bin_layer(os.path.join(output_path, 'species_threshold_exceeded.tif'),
receptor_filename=os.path.join(output_path, "paracousti_risk_layer.tif"),
receptor_names=None,
limit_receptor_range=[0, np.inf],
latlon=crs == 4326,
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_threshold_exceeded_at_paracousti_risk_layer.csv"), index=False)
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_threshold_exceeded_at_paracousti_risk_layer.csv"), index=False)

bin_layer(os.path.join(output_path, 'species_percent.tif'),
receptor_filename=os.path.join(output_path, "paracousti_risk_layer.tif"),
receptor_names=None,
limit_receptor_range=[0, np.inf],
latlon=crs == 4326,
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_percent_at_paracousti_risk_layer.csv"), index=False)
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_percent_at_paracousti_risk_layer.csv"), index=False)

bin_layer(os.path.join(output_path, 'species_density.tif'),
receptor_filename=os.path.join(output_path, "paracousti_risk_layer.tif"),
receptor_names=None,
limit_receptor_range=[0, np.inf],
latlon=crs == 4326,
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_density_at_paracousti_risk_layer.csv"), index=False)
receptor_type='risk layer').to_csv(os.path.join(output_path, "species_density_at_paracousti_risk_layer.csv"), index=False)

OUTPUT = {}
for val in output_rasters:
OUTPUT[os.path.basename(os.path.normpath(val)).split('.')[0]] = val
OUTPUT[os.path.basename(os.path.normpath(val)).split('.')[0]] = val
return OUTPUT
Loading

0 comments on commit 82d6042

Please sign in to comment.