Without this metadata, specialized analysis software may reject the file or fail to calculate background noise, peak positions, and phase identification accurately. Step 1: Preparing Your Excel Data for High-Quality Output
import pandas as pd import xml.etree.ElementTree as ET from xml.dom import minidom def excel_to_xrdml(excel_path, output_xrdml_path, sample_name="Unknown Sample"): # 1. Read the Excel file df = pd.read_excel(excel_path) # Assume Column 0 is 2Theta and Column 1 is Intensity angles = df.iloc[:, 0].tolist() intensities = df.iloc[:, 1].tolist() start_angle = angles[0] end_angle = angles[-1] num_points = len(angles) # Convert lists to space-separated strings required by XML arrays intensities_str = " ".join(map(str, [int(x) for x in intensities])) # 2. Build the XRDML XML structure root = ET.Element("xrdMeasurement", "xmlns": "http://panalytical.com", "status": "Completed" ) # Add Sample Metadata sample = ET.SubElement(root, "sample") id_elem = ET.SubElement(sample, "id") id_elem.text = sample_name # Add Scan Metadata xrd_scan = ET.SubElement(root, "scan", "scanAxis": "Gonio", "status": "Completed" ) data_points = ET.SubElement(xrd_scan, "dataPoints") # Add 2Theta Positions positions = ET.SubElement(data_points, "positions", "axis": "2Theta", "unit": "deg") start_elem = ET.SubElement(positions, "startPosition") start_elem.text = f"start_angle:.4f" end_elem = ET.SubElement(positions, "endPosition") end_elem.text = f"end_angle:.4f" # Add Intensities Array intensities_elem = ET.SubElement(data_points, "intensities", "unit": "counts") intensities_elem.text = intensities_str # 3. Pretty print and save the XML file to maintain high-quality encoding xml_string = ET.tostring(root, encoding="utf-8") parsed_xml = minidom.parseString(xml_string) pretty_xml = parsed_xml.toprettyxml(indent=" ") with open(output_xrdml_path, "w", encoding="utf-8") as f: f.write(pretty_xml) print(f"Successfully converted excel_path to high-quality XRDML at output_xrdml_path") # Example Usage: # excel_to_xrdml("diffraction_data.xlsx", "output_result.xrdml", "Catalyst_Batch_A") Use code with caution. Step 4: Validating Your Converted File
Save the following script as excel_to_xrdml.py . It reads structured Excel data, validates the step increments, and exports a fully compliant XRDML file. convert excel to xrdml high quality
Quick Convert
Converting XY data from Excel to the XML-based XRDML format requires strict adherence to the schema definitions. To achieve a high-quality conversion, the process involves mapping spreadsheet columns to specific XML nodes (Start/End positions, Step size, and Intensities). Our method eliminates the common pitfalls of data truncation and header corruption, producing a robust XRDML file that retains the original resolution and provenance of your experiment. Build the XRDML XML structure root = ET
Once imported, the data can be saved out as a high-quality , effectively bridging the gap between a basic spreadsheet and a professional crystallographic tool. Why High Quality Matters
In this post, we’ll explore the best tools and methods to ensure your conversion is high-quality, traceable, and ready for publication. Why Convert to XRDML? Unlike flat files, the XRDML (XML-based) format provides: Complete Traceability It reads structured Excel data, validates the step
: Open HighScore Plus, go to Customize > Program Settings > Automatic Processing .
Here are the best methods to convert Excel to XRDML, ranging from user-friendly software to automated scripting. 1. Using Dedicated Software Tools (Recommended)
To achieve a high-quality XRDML file, your source Excel file must be structured correctly. Garbage in, garbage out.