Skip to content

Commit a428df7

Browse files
committed
Fixed bugs due to new echem file format having a column called index. Added support for timestamp column to be called "Data_Time"
1 parent 030c1dd commit a428df7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/datalab_app_plugin_insitu/apps/xrd/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,12 @@ def process_local_xrd_data(
170170

171171
df_echem = xrd_data["Time_series_data"]["data"]
172172

173+
# Rename timestamp column to echem_timestamp
174+
# Note: Timestamp column is already standardized in process_echem_data()
175+
# Note: elapsed_time_seconds and elapsed_time_hours are already calculated in process_echem_data()
173176
df_echem["Timestamp"] = pd.to_datetime(df_echem["Timestamp"])
174177
df_echem = df_echem.rename(columns={"Timestamp": "echem_timestamp"})
175-
time_deltas = df_echem.echem_timestamp - df_echem.echem_timestamp.iloc[0]
176-
df_echem["elapsed_time_hours"] = [
177-
delta.total_seconds() / 3600 for delta in time_deltas
178-
]
179-
df_echem["elapsed_time_seconds"] = [delta.total_seconds() for delta in time_deltas]
178+
180179
log_data.rename(columns={"start_time": "xrd_timestamp"}, inplace=True)
181180
log_data["xrd_timestamp"] = pd.to_datetime(log_data["xrd_timestamp"])
182181
df_merged = pd.merge_asof(
@@ -188,6 +187,7 @@ def process_local_xrd_data(
188187
)
189188

190189
# Adding scan_number to the echem data to be used for the lengend later.
190+
# Note: Timestamp column is already standardized to "Timestamp" in process_echem_data()
191191
echem_merged = pd.merge_asof(
192192
xrd_data["Time_series_data"]["data"],
193193
xrd_data["log data"][["xrd_timestamp", "scan_number"]],
@@ -205,6 +205,11 @@ def process_local_xrd_data(
205205
"elapsed_time_seconds": "time",
206206
}
207207
)
208+
209+
# Remove 'index' column if it exists in the data to avoid conflicts with pandas reset_index()
210+
if "index" in df_merged.columns:
211+
df_merged = df_merged.drop(columns=["index"])
212+
208213
xrd_data["index_df"] = df_merged
209214

210215
# Create a mapping from file_num to exp_num

src/datalab_app_plugin_insitu/echem_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@ def process_echem_data(echem_folder: Path) -> Dict:
3737
else:
3838
raise ValueError(f"Echem folder not found: {echem_folder}")
3939

40+
# Rename timestamp column to a consistent name
4041
if "Timestamp" in echem_data.columns:
42+
timestamp_col = "Timestamp"
43+
elif "Date_Time" in echem_data.columns:
44+
echem_data = echem_data.rename(columns={"Date_Time": "Timestamp"})
45+
timestamp_col = "Timestamp"
46+
else:
47+
timestamp_col = None
48+
49+
if timestamp_col:
4150
time_deltas = echem_data["Timestamp"] - echem_data["Timestamp"].iloc[0]
4251
echem_data["elapsed_time_seconds"] = [delta.total_seconds() for delta in time_deltas]
52+
echem_data["elapsed_time_hours"] = [delta.total_seconds() / 3600 for delta in time_deltas]
4353
echem_data["Time"] = echem_data["elapsed_time_seconds"]
4454

4555
min_time = echem_data["Time"].min()

src/datalab_app_plugin_insitu/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def _link_plots(
562562
echemplot_figure.add_tools(crosshair)
563563
hover = next((tool for tool in heatmap_figure.tools if isinstance(tool, HoverTool)), None)
564564
if hover:
565-
index_df_source = ColumnDataSource(plot_data["index_df"].reset_index())
565+
index_df_source = ColumnDataSource(plot_data["index_df"].reset_index(drop=True))
566566
hover.callback = CustomJS(
567567
args=dict(
568568
line_source=line_source,

0 commit comments

Comments
 (0)