EasyScience / EasyReflectometryApp

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

Loading of comma and tab separated 3 column ascii files #97

Closed jfkcooper closed 2 years ago

jfkcooper commented 2 years ago

This fixes #94 by trying to load 3 column ascii files both with tab and comma separators. No tests added, but can be written if required.

arm61 commented 2 years ago

I changed the base to develop instead of main. Will look at this first thing tomorrow morning. I suggest that I write the test afterward (I suspect this is good practice so that we actually test what we think we are testing you know?)

arm61 commented 2 years ago

I know this is more of a comment on my older code, but I was thinking that we could move towards something like (starting at line 210):

        else:
            try:
                data = np.loadtxt(file_path, unpack=True)
            except ValueError:
                data = np.loadtxt(file_path, unpack=True, delimiter=',')
            if data.shape[0] == 4:
                x, y, ye, xe = data
            elif data.shape[0] == 3:
                x, y, ye = data
                xe = np.zeros_like(ye)
            else:
                raise ValueError("The data must have at either 3 or 4 columns if not in the ORSO format")

            name = path.split(file_path)[-1].split('.')[0]
            ds = DataSet1D(name=name, x=x, y=y, ye=ye, xe=xe, 
                           model=self.parent._model_proxy._model[0], 
                           x_label='q (1/angstrom)', 
                           y_label='Reflectivity')
            self._data.append(ds)

Thoughts?

jfkcooper commented 2 years ago

Yeah, this is much neater

arm61 commented 2 years ago

Does it run successfully?

jfkcooper commented 2 years ago

yes, though I dont have 4 column data to hand to test it, can you send me some?

arm61 commented 2 years ago

Additionally can you rebase against the latest develop

git fetch upstream
git rebase upstream/develop
git push

(I think)

This will let the tests run.