Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acoustics module update #34

Open
wants to merge 142 commits into
base: main
Choose a base branch
from

Conversation

tnelson-integral
Copy link
Collaborator

Start of Acoustics Module update for weighting and exposure level.

@tnelson-integral
Copy link
Collaborator Author

Just starting this. Still have work to do on updating the calculations, but this will be the next large update.

@tnelson-integral tnelson-integral added the enhancement New feature or request label Jul 30, 2024
@tnelson-integral tnelson-integral self-assigned this Jul 30, 2024
@ssolson
Copy link
Collaborator

ssolson commented Jan 10, 2025

This is still undergoing review. I will send you an email once this is ready.

Hey @tnelson-integral I hope you had great holidays. How are we doing over here and do you need any help?

@tnelson-integral
Copy link
Collaborator Author

tnelson-integral commented Jan 10, 2025 via email

@tnelson-integral
Copy link
Collaborator Author

Hi @ssolson. Everything is updated on our end. Let us know if you have any other recommendations. -Tim

@ssolson
Copy link
Collaborator

ssolson commented Feb 3, 2025

Hi @ssolson. Everything is updated on our end. Let us know if you have any other recommendations. -Tim

Thanks Tim. I'll take a look this week.

@ssolson
Copy link
Collaborator

ssolson commented Feb 4, 2025

@tnelson-integral

Why have you created a "seat-qgis-plugin[]" folder in addition to the "seat" folder? There should only be one folder and the canonical folder is "seat".

Please update all of the changes you are proposing into the correct folder. Please be careful to only update your changes into the correct folder. I am worried you are working off some old files and I am going to have to redo all the linting work I did if you simply copy paste one folder into the other.

Why are you trying to commit 3 different zip files to the main?

@tnelson-integral
Copy link
Collaborator Author

tnelson-integral commented Feb 4, 2025 via email

@ssolson
Copy link
Collaborator

ssolson commented Feb 4, 2025

Fantastic. Thanks Tim.

@tnelson-integral
Copy link
Collaborator Author

tnelson-integral commented Feb 4, 2025 via email

Comment on lines +15 to +16
paracousti_directory = r"C:\Users\aellenson\OneDrive - Integral Consulting Inc\C1308 Sandia\Tutorial_Files\Development\DEMO Files Tabbed GUI - Acoustics\pacwave\paracousti_files\\"
save_directory = r"C:\Users\aellenson\OneDrive - Integral Consulting Inc\C1308 Sandia\Tutorial_Files\Development\DEMO Files Tabbed GUI - Acoustics\pacwave\paracousti_files_with_metrics_TU\\"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tim what do you think the best way to clean this up would be?

We shouldn't be pushing hardcoded local paths into a public tool.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about setting up the file to take sysargs?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ParAcousti pre-processing routine.

This module processes parAcousti files, which can be resource intensive depending on
grid resolution and weights selected. Processing may take several hours to complete.

Required packages:
    - xarray with netCDF4 (pip install "xarray[io]")
    - scipy (included with xarray[io])
    - tqdm (pip install tqdm)
"""

import argparse
from pathlib import Path
from . import utils.paracousti_fxns as paracousti_fxns


def process_paracousti_files(input_dir: str, output_dir: str, weights: str = "TU") -> bool:
    """
    Process parAcousti files and calculate metrics.

    Args:
        input_dir: Directory containing parAcousti files
        output_dir: Directory to save processed files
        weights: Weight type to use ("TU" or "All")

    Returns:
        bool: True if processing successful, False otherwise
    """
    input_path = Path(input_dir)
    output_path = Path(output_dir)
    
    if not input_path.exists():
        raise FileNotFoundError(f"Input directory not found: {input_dir}")
    
    output_path.mkdir(parents=True, exist_ok=True)
    
    return paracousti_fxns.calc_paracousti_metrics(
        str(input_path),
        str(output_path),
        weights=weights
    )

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Process parAcousti files.')
    parser.add_argument('input_dir', help='Directory containing parAcousti files')
    parser.add_argument('output_dir', help='Directory to save processed files')
    parser.add_argument('--weights', default="TU", choices=['TU', 'All'],
                      help='Weight type to use (default: TU)')
    
    args = parser.parse_args()
    
    try:
        status = process_paracousti_files(
            args.input_dir,
            args.output_dir,
            weights=args.weights
        )
        print(f"Processing {'successful' if status else 'failed'}")
    except Exception as e:
        print(f"Error processing files: {e}")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a great idea. I like the code. I must have missed this before but let's make the default 'LFC' as opposed to 'TU'.

Comment on lines 453 to +461
root: Optional[QgsLayerTreeGroup] = None,
group: Optional[QgsLayerTreeGroup] = None,
) -> None: # , ranges=True):
subgroup: Optional[QgsLayerTreeGroup] = None,
) -> None:
"""Style and add the result layer to map."""
basename = os.path.splitext(os.path.basename(fpath))[0]
if group is not None:
vlayer = QgsRasterLayer(fpath, basename)
QgsProject.instance().addMapLayer(vlayer)
root = QgsProject.instance().layerTreeRoot()
if stylepath is not None:
vlayer.loadNamedStyle(stylepath)
vlayer.triggerRepaint()
vlayer.reload()
layer = root.findLayer(vlayer.id())
vlayer = QgsRasterLayer(fpath, basename)
QgsProject.instance().addMapLayer(vlayer)
root = QgsProject.instance().layerTreeRoot()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tnelson-integral this root definition is overwriting any root passed to the function should this be:

        if root is None:
            root = QgsProject.instance().layerTreeRoot()

@ssolson
Copy link
Collaborator

ssolson commented Feb 12, 2025

@tnelson-integral can you review and if everything looks good to you merge IntegralEnvision#18 so that all the tests on this PR will pass.

@tnelson-integral
Copy link
Collaborator Author

tnelson-integral commented Feb 13, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants