{
    "sourceFile": "Tickets/ISSUE-013-plan.md",
    "activeCommit": 0,
    "commits": [
        {
            "activePatchIndex": 0,
            "patches": [
                {
                    "date": 1745348766875,
                    "content": "Index: \n===================================================================\n--- \n+++ \n"
                }
            ],
            "date": 1745348766875,
            "name": "Commit-0",
            "content": "# Plan to Resolve ISSUE-013: Merged Map Roughness Statistics\r\n\r\n**Objective:** Reimplement the calculation and inclusion of image statistics (Min/Max/Mean) for roughness data, covering both standalone roughness maps and roughness data used as a source channel in merged maps (specifically the green channel for NRMRGH), and ensure these statistics are present in the output `metadata.json` file.\r\n\r\n**Proposed Changes:**\r\n\r\n1.  **Modify `_merge_maps_from_source`:**\r\n    *   Within the loop that processes each resolution for a merge rule, after successfully loading and transforming the source images into `loaded_inputs_data`, iterate through the `inputs_mapping` for the current rule.\r\n    *   Identify if any of the source map types in the `inputs_mapping` is 'ROUGH'.\r\n    *   If 'ROUGH' is used as a source, retrieve the corresponding loaded image data from `loaded_inputs_data`.\r\n    *   Calculate image statistics (Min/Max/Mean) for this ROUGH source image data using the existing `_calculate_image_stats` helper function.\r\n    *   Store these calculated statistics temporarily, associated with the output merged map type (e.g., 'NRMRGH') and the target channel it's mapped to (e.g., 'G').\r\n\r\n2.  **Update Asset Metadata Structure:**\r\n    *   Introduce a new key in the asset's metadata dictionary (e.g., `merged_map_channel_stats`) to store statistics for specific channels within merged maps. This structure will hold the stats per merged map type, per channel, and per resolution (specifically the stats resolution defined in the config).\r\n\r\n3.  **Modify `_generate_metadata_file`:**\r\n    *   When generating the final `metadata.json` file, retrieve the accumulated `merged_map_channel_stats` from the asset's metadata dictionary.\r\n    *   Include these statistics under a dedicated section in the output JSON, alongside the existing `image_stats_1k` for individual maps.\r\n\r\n**Data Flow for Statistics Calculation:**\r\n\r\n```mermaid\r\ngraph TD\r\n    A[Source Image Files] --> B{_load_and_transform_source};\r\n    B --> C[Resized/Transformed Image Data (float32)];\r\n    C --> D{Is this source for a ROUGH map?};\r\n    D -- Yes --> E{_calculate_image_stats};\r\n    E --> F[Calculated Stats (Min/Max/Mean)];\r\n    F --> G[Store in merged_map_channel_stats (in asset metadata)];\r\n    C --> H{_merge_maps_from_source};\r\n    H --> I[Merged Image Data];\r\n    I --> J[_save_image];\r\n    J --> K[Saved Merged Map File];\r\n    G --> L[_generate_metadata_file];\r\n    L --> M[metadata.json];\r\n\r\n    subgraph Individual Map Processing\r\n        A --> B;\r\n        B --> C;\r\n        C --> N{Is this an individual map?};\r\n        N -- Yes --> E;\r\n        E --> O[Store in image_stats_1k (in asset metadata)];\r\n        C --> P[_save_image];\r\n        P --> Q[Saved Individual Map File];\r\n        O --> L;\r\n        Q --> S[Organize Output Files];\r\n    end\r\n\r\n    subgraph Merged Map Processing\r\n        A --> B;\r\n        B --> C;\r\n        C --> D;\r\n        D -- Yes --> E;\r\n        E --> G;\r\n        C --> H;\r\n        H --> I;\r\n        I --> J;\r\n        J --> K;\r\n        K --> S;\r\n    end\r\n\r\n    L --> M;\r\n    M --> S;\r\n```\r\n\r\nThis plan ensures that statistics are calculated for the roughness data at the appropriate stage (after loading and transformation, before merging) and correctly included in the metadata file, addressing the issue described in ISSUE-013."
        }
    ]
}