Skip to content

Commit 6750f26

Browse files
author
Filippo Ballerini
committed
Changes to read .xy files
1 parent bd896d9 commit 6750f26

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/diffpy/snmf/io.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,45 @@ def load_input_signals(file_path=None):
9999
directory_path = Path.cwd()
100100
else:
101101
directory_path = Path(file_path)
102+
if not directory_path.is_dir():
103+
raise ValueError(f"The provided file_path '{file_path}' is not a valid directory.")
102104

103105
values_list = []
104106
grid_list = []
105-
current_grid = []
107+
#current_grid = []
108+
current_grid = None # Initialize as None
106109
for item in directory_path.iterdir():
107110
if item.is_file():
108-
data = loadData(item.resolve())
109-
if current_grid and current_grid != data[:, 0]:
110-
print(f"{item.name} was ignored as it is not on a compatible grid.")
111-
continue
111+
data = loadData(item.resolve()) # Assuming loadData reads the XY data correctly
112+
x_values = data[:, 0] # First column as X values
113+
y_values = data[:, 1] # Second column as Y values
114+
115+
#data = loadData(item.resolve())
116+
#if current_grid is not None and not np.array_equal(current_grid, data[:, 0]):
117+
#print(f"{item.name} was ignored as it is not on a compatible grid.")
118+
#continue
119+
#if current_grid is not None and not np.array_equal(current_grid, x_values):
120+
#print(f"{item.name} was ignored as it is not on a compatible grid.")
121+
if current_grid is not None:
122+
if not np.array_equal(current_grid, x_values):
123+
print(f"{item.name} has incompatible grid: {x_values}")
124+
continue
112125
else:
113-
grid_list.append(data[:, 0])
114-
current_grid = grid_list[-1]
115-
values_list.append(data[:, 1])
116-
117-
grid_array = np.column_stack(grid_list)
118-
grid_vector = np.unique(grid_array, axis=1)
126+
#grid_list.append(data[:, 0])
127+
#current_grid = grid_list[-1]
128+
#values_list.append(data[:, 1])
129+
current_grid = x_values # Update the current grid
130+
values_list.append(y_values) # Store the Y values
131+
132+
if not grid_list:
133+
print("No compatible grid found.")
134+
return None, None
135+
136+
# Stack Y values and create a unique grid array
119137
values_array = np.column_stack(values_list)
138+
139+
#grid_array = np.column_stack(grid_list)
140+
#grid_vector = np.unique(grid_array, axis=1)
141+
#values_array = np.column_stack(values_list)
142+
print(f"Grid vector shape: {grid_vector.shape}, Values array shape: {values_array.shape}")
120143
return grid_vector, values_array

src/diffpy/snmf/stretchednmfapp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def create_parser():
4040
help="The lifting factor. Data will be lifted by lifted_data = data + abs(min(data) * lift). Default 1.",
4141
)
4242
parser.add_argument(
43-
"number-of-components",
43+
"-n",
44+
"--number-of-components",
4445
type=int,
4546
help="The number of component signals for the NMF decomposition. Must be an integer greater than 0",
4647
)
@@ -54,6 +55,9 @@ def main():
5455
if args.input_directory is None:
5556
args.input_directory = Path.cwd()
5657
grid, input_data = load_input_signals(args.input_directory)
58+
if input_data is None:
59+
print("No valid input data found. Please check your input directory.")
60+
return
5761
lifted_input_data = lift_data(input_data, args.lift_factor)
5862
variables = initialize_variables(lifted_input_data, args.number_of_components, args.data_type)
5963
components = initialize_components(variables["number_of_components"], variables["number_of_signals"], grid)

0 commit comments

Comments
 (0)