This document describes the refactoring changes made to the ARM Diagnostics package to modernize the codebase and improve usability. The primary goals were:
- Remove the hard-coded path dependency (
armdiags_path) - Improve the package structure and resource handling
- Create a more user-friendly run interface
- Update the documentation to reflect these changes
- Before: Users needed to define an
armdiags_pathvariable pointing to the code repository. - After: The package uses Python's resource system (importlib.resources) to access internal files.
- Benefits: Allows users to install the package properly without needing to know where the code is located.
- Created a dedicated
configdirectory for standard configuration files - Moved JSON configuration files to the appropriate directories
- Updated resource discovery code to search in multiple locations for configs
- Created a new
run_arm_diags.pyscript as the main entry point - Added support for command-line arguments with descriptive help
- Added support for parameter files with the
-poption - The script can now be run in two ways:
- With a parameter file:
./run_arm_diags.py -p examples/arm_diags_params.py - With command-line arguments:
./run_arm_diags.py --base-path /path/to/data
- With a parameter file:
- Fixed relative imports to work correctly as an installed package
- Updated all import statements to use proper relative imports
- Created proper
__init__.pywith version and exported functions - Made resources accessible through importlib.resources
- Updated README.rst with new installation and usage instructions
- Created example parameter file in examples directory
- Documented both command-line and parameter file approaches
- Preserved the old basicparameter.py as reference in the examples directory
For users of the previous version:
- Create a new parameter file based on examples/arm_diags_params.py
- Set the same values you were using in basicparameter.py
- Remove the armdiags_path parameter (it's no longer needed)
- Run with
./run_arm_diags.py -p your_params.py
- Switch to using run_arm_diags.py
- Your configuration will be easier to manage and reproduce
/arm_diags/config/- New directory containing default configuration files/examples/- Contains example parameter files and reference filesrun_arm_diags.py- New main entry point for running the diagnostics
- Resource Access: Used Python's importlib.resources to locate and access package resources
- Parameter Handling: Created a flexible system that can load parameters from files or command-line
- Modular Design: Split the functionality to make it more maintainable
- Improved Error Messages: Added clearer error messages when resources cannot be found
- Keyboard interrupts (Ctrl+C) might not work reliably when the diagnostic computations are running
- This is likely due to the underlying scientific libraries (cdms2, matplotlib, etc.)
Potential future enhancements to consider:
- Further reduce dependencies on legacy packages (cdms2, cdutil)
- Add support for more data formats (NetCDF4, xarray as primary tools)
- Implement proper logging system
- Add more comprehensive test suite