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

function load_input_signal refactor #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 8 additions & 5 deletions diffpy/snmf/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from pathlib import Path
from diffpy.utils.parsers.loaddata import loadData

PDF_FILE_EXTENSIONS = {'.gr', '.cgr'}
DIFFRACTION_FILE_EXTENSIONS = {'.chi', 'iq', 'xye', '.xrd', '.xy'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a much earlier comment, you mentioned that finding the file type by the file extension may not be a good idea. Do you know of any libraries that can do this (such as in diffpy.utils).

Copy link
Contributor

@sbillinge sbillinge Aug 2, 2023

Choose a reason for hiding this comment

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

it looks to me as if you are trying to find the data_type from the extension. Is that right or is it teh file-type you are after? LoadData is pretty flexible, it should successfully read all the file extensions you put up there (I am not familiar with .xrd)

Copy link
Contributor

Choose a reason for hiding this comment

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

in other words, I don;t think you need to do this.



def initialize_variables(data_input, component_amount, data_type, sparsity=1, smoothness=1e18):
"""Determines the variables and initial values used in the SNMF algorithm.
Expand Down Expand Up @@ -91,18 +94,18 @@ def load_input_signals(file_path=None):

"""

if file_path is None:
directory_path = Path.cwd()
else:
directory_path = Path(file_path)
directory_path = Path(file_path)

values_list = []
grid_list = []
current_grid = []
file_extension = ""
data_type = ""
for item in directory_path.iterdir():
if item.is_file():
file_extension = Path(item).suffix
data = loadData(item.resolve())
if current_grid and current_grid != data[:, 0]:
if len(current_grid) != 0 and (current_grid != data[:, 0]).any():
print(f"{item.name} was ignored as it is not on a compatible grid.")
continue
else:
Expand Down