EasyScience / EasyReflectometryApp

Reflectometry data analysis application
https://easyreflectometry.org
BSD 3-Clause "New" or "Revised" License
7 stars 2 forks source link

Can't load data #94

Closed jfkcooper closed 2 years ago

jfkcooper commented 2 years ago

Trying to load a .dat file in csv format using the Import data from local drive button, nothing appears to happen and no data is loaded. Data looks like: image 60_61.txt changed extension to .txt to upload here

jfkcooper commented 2 years ago

This probably arises from np.loadtxt needing delimiter="," in https://github.com/easyScience/EasyReflectometryApp/blob/552edd51d66331eae1fbd939aef91958d3bcb38d/EasyReflectometryApp/Logic/Proxies/Data.py#L195

arm61 commented 2 years ago

I was about to say this exactly. I would suggest this:

else:
    try:
        x, y, ye, xe = np.loadtxt(file_path, unpack=True)
    except ValueError:
        x, y, ye = np.loadtxt(file_path, unpack=True)
        xe = np.zeros_like(ye)

becomes something like

else:
    if file_path[-3:] == 'csv':
        try:
            x, y, ye, xe = np.loadtxt(file_path, delimiter=',', unpack=True)
        except ValueError:
            x, y, ye = np.loadtxt(file_path, delimiter=',', unpack=True)
            xe = np.zeros_like(ye)
    else:
        try:
            x, y, ye, xe = np.loadtxt(file_path, unpack=True)
        except ValueError:
            x, y, ye = np.loadtxt(file_path, unpack=True)
            xe = np.zeros_like(ye)

Thoughts?

jfkcooper commented 2 years ago

Hmm, tricky since I don't think there is a "standard" where comma separated values are definitely called .CSV. Mine were .dat, and I'm sure .txt are also common, but comma and tab separators are both possible in all types (at least in my experience). Could go with insisting, or have more checks (does no throw an error if you assign three variables to a single valued array?)

arm61 commented 2 years ago

Ideally, we can throw away all of the file reading code and just rely on ORSO... 🙏

I think the most friendly option will be to have some rather ugly checking code. Let me have a look today/tomorrow.

arm61 commented 2 years ago

@jfkcooper do you fancy having a bash at something that would be friendly for this? (if you are too busy/don't care then I can have a go later in the week)

arm61 commented 2 years ago

@jfkcooper you happy to close this issue now?