Skip to content

Conversation

be-smith
Copy link
Contributor

@be-smith be-smith commented Aug 29, 2025

Adds the echem pathway for the XRD block (and updates it for the UV-Vis block to be able to handle multiple files). Paired with datalab-org/datalab#1287 for the block itself. Currently the test data I'm not sure can be added to GitHub pending permission from the owner so will send on slack

@be-smith be-smith marked this pull request as ready for review September 10, 2025 16:13
@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 16:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds electrochemical (echem) pathway support to the XRD in-situ block, allowing users to visualize XRD data against voltage/time instead of just temperature. It also updates the UV-Vis block to handle multiple electrochemical files.

  • Adds time_series_source parameter to switch between "log" (temperature) and "echem" (electrochemical) data sources
  • Enhances echem_utils.py to handle multiple electrochemical files with concatenation and deduplication
  • Updates plotting functions to support both pathways with appropriate axis labels and data handling

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_inisitu_xrd_block.py Sets time_series_source to "log" for testing the temperature pathway
src/datalab_app_plugin_insitu/plotting.py Adds conditional logic for echem vs log data handling in XRD plot preparation
src/datalab_app_plugin_insitu/echem_utils.py Enhanced to handle multiple echem files with proper validation and timestamp processing
src/datalab_app_plugin_insitu/blocks.py Improved max pooling implementation with better padding and error handling
src/datalab_app_plugin_insitu/apps/xrd/utils.py Major updates to support echem pathway including timestamp matching and data merging
src/datalab_app_plugin_insitu/apps/xrd/blocks.py Converts plotting_label_dict to property for dynamic labels based on data source
README.md Updated documentation to describe both temperature and electrochemical pathways

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +215 to +222
if self.data.get("time_series_source") == "log":
for folder in required_folders:
if not self.data.get(folder):
return
elif self.data.get("time_series_source") == "echem":
for folder in required_folders:
if not self.data.get(folder):
return
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The conditional logic for checking required folders is duplicated. This can be simplified to a single loop since both conditions perform the same validation.

Suggested change
if self.data.get("time_series_source") == "log":
for folder in required_folders:
if not self.data.get(folder):
return
elif self.data.get("time_series_source") == "echem":
for folder in required_folders:
if not self.data.get(folder):
return
for folder in required_folders:
if not self.data.get(folder):
return

Copilot uses AI. Check for mistakes.

for ext in accepted_extensions:
echem_files.extend(echem_folder.glob(f"*{ext}"))

# Sanity check to remove any duplicate files
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment mentions removing duplicates, but dict.fromkeys() preserves order while removing duplicates. Consider using set() if order doesn't matter, or clarify the comment to mention order preservation.

Suggested change
# Sanity check to remove any duplicate files
# Remove duplicate files while preserving order

Copilot uses AI. Check for mistakes.

Comment on lines +247 to +251
if set(new_two_theta_values) != set(two_theta):
missing_values = set(two_theta) - set(new_two_theta_values)
LOGGER.warning(
f"Inconsistent 2θ values found in file {file}: {missing_values}."
)
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Converting arrays to sets for comparison is inefficient for large arrays. Consider using np.array_equal() or np.allclose() for floating-point comparisons, which would be more appropriate for 2θ values.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

@BenjaminCharmes BenjaminCharmes left a comment

Choose a reason for hiding this comment

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

LGTM, everything works fine 👍

@ml-evs ml-evs moved this to Todo in merge stack Sep 23, 2025
@be-smith
Copy link
Contributor Author

The state of play here is that i think everything works - but the code is messy and still haven't unified NMR and UV-Vis/XRD plotting modules. So there will be another PR on top of this one where everything is tidied and plotting mofules are unified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants