Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc #125

Closed
wants to merge 5 commits into from
Closed

Doc #125

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ on the independent variable axis. For example, for powder diffraction data taken
chemical phases where the measurements were done at different temperatures and the materials were undergoing thermal
expansion.

I think it is not very clear here what the package does and how it can be used to solve the example problem. You are talking about VT-PXRD experiment of samples with different phases which undergo a termal expansion, so a modification of unit cell parameters, each phase independently with respect to the other in the same sample?

For more information about the diffpy.snmf library, please consult our `online documentation <https://diffpy.github.io/diffpy.snmf>`_.

Citation
Expand Down
43 changes: 33 additions & 10 deletions src/diffpy/snmf/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,45 @@ def load_input_signals(file_path=None):
directory_path = Path.cwd()
else:
directory_path = Path(file_path)
if not directory_path.is_dir():
raise ValueError(f"The provided file_path '{file_path}' is not a valid directory.")

values_list = []
grid_list = []
current_grid = []
# current_grid = []
current_grid = None # Initialize as None
for item in directory_path.iterdir():
if item.is_file():
data = loadData(item.resolve())
if current_grid and current_grid != data[:, 0]:
print(f"{item.name} was ignored as it is not on a compatible grid.")
continue
data = loadData(item.resolve()) # Assuming loadData reads the XY data correctly
x_values = data[:, 0] # First column as X values
y_values = data[:, 1] # Second column as Y values

# data = loadData(item.resolve())
# if current_grid is not None and not np.array_equal(current_grid, data[:, 0]):
# print(f"{item.name} was ignored as it is not on a compatible grid.")
# continue
# if current_grid is not None and not np.array_equal(current_grid, x_values):
# print(f"{item.name} was ignored as it is not on a compatible grid.")
if current_grid is not None:
if not np.array_equal(current_grid, x_values):
print(f"{item.name} has incompatible grid: {x_values}")
continue
else:
grid_list.append(data[:, 0])
current_grid = grid_list[-1]
values_list.append(data[:, 1])
# grid_list.append(data[:, 0])
# current_grid = grid_list[-1]
# values_list.append(data[:, 1])
current_grid = x_values # Update the current grid
values_list.append(y_values) # Store the Y values

grid_array = np.column_stack(grid_list)
grid_vector = np.unique(grid_array, axis=1)
if not grid_list:
print("No compatible grid found.")
return None, None

# Stack Y values and create a unique grid array
values_array = np.column_stack(values_list)

# grid_array = np.column_stack(grid_list)
# grid_vector = np.unique(grid_array, axis=1)
# values_array = np.column_stack(values_list)
print(f"Grid vector shape: {grid_vector.shape}, Values array shape: {values_array.shape}")
return grid_vector, values_array
6 changes: 5 additions & 1 deletion src/diffpy/snmf/stretchednmfapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def create_parser():
help="The lifting factor. Data will be lifted by lifted_data = data + abs(min(data) * lift). Default 1.",
)
parser.add_argument(
"number-of-components",
"-n",
"--number-of-components",
type=int,
help="The number of component signals for the NMF decomposition. Must be an integer greater than 0",
)
Expand All @@ -54,6 +55,9 @@ def main():
if args.input_directory is None:
args.input_directory = Path.cwd()
grid, input_data = load_input_signals(args.input_directory)
if input_data is None:
print("No valid input data found. Please check your input directory.")
return
lifted_input_data = lift_data(input_data, args.lift_factor)
variables = initialize_variables(lifted_input_data, args.number_of_components, args.data_type)
components = initialize_components(variables["number_of_components"], variables["number_of_signals"], grid)
Expand Down
8 changes: 4 additions & 4 deletions src/diffpy/snmf/subroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def construct_component_matrix(components):
def construct_weight_matrix(components):
"""Constructs the weights matrix.

Constructs a Ķ x M matrix where K is the number of components and M is the
Constructs a K x M matrix where K is the number of components and M is the
number of signals. Each element is the stretching factor for a specific
weights for a specific signal from the data input.
weight factor for a specific signal from the data input.

Parameters
----------
Expand Down Expand Up @@ -359,10 +359,10 @@ def update_weights_matrix(
The length of the experimental signal patterns

stretching_factor_matrix: 2d array like
The matrx containing the stretching factors of the calculated component signals. Has dimensions K x M
The matrix containing the stretching factors of the calculated component signals. Has dimensions K x M
where K is the number of component signals and M is the number of XRD/PDF patterns.

component_matrix: 2d array lik
component_matrix: 2d array like
The matrix containing the unstretched calculated component signals. Has dimensions N x K where N is the
length of the signals and K is the number of component signals.

Expand Down
Loading