diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5c725e4..39806a7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,20 +10,23 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] - os: [windows-latest, ubuntu-latest, macos-latest] + python-version: ["3.9", "3.10", "3.11"] + os: [windows-latest, ubuntu-latest] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: ${{ matrix.os }} python ${{ matrix.python-version }} + - name: Install Python dependencies shell: bash -l {0} run: | python3 -m pip install -r requirements.txt python3 -m pip install -e . --no-deps --force-reinstall + + - name: Run tests + run: | python3 -m unittest diff --git a/CHANGELOG.md b/CHANGELOG.md index 9376cc6..35a1726 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All significant changes to the software will be documented here. -## [0.3.30-dev] - LIVE +## [0.3.31-dev] - LIVE ### TODO - implement different analyte lists for different stages (raw, ratios, mass_fractions), OR improve analyte_checker functionality. This has to propagate throught to filter assignment. diff --git a/latools/__init__.py b/latools/__init__.py index b64e39d..008ad64 100644 --- a/latools/__init__.py +++ b/latools/__init__.py @@ -17,7 +17,7 @@ from .helpers import chemistry from . import preprocessing -VERSION = '0.3.30' +VERSION = '0.3.31' def cite(output='text'): """ diff --git a/latools/latools.py b/latools/latools.py index 6e7d3a8..65855ba 100644 --- a/latools/latools.py +++ b/latools/latools.py @@ -67,7 +67,11 @@ # TODO: Add 'smooth all' function. class analyse(object): - """ + def __init__(self, data_path, errorhunt=False, config='DEFAULT', + dataformat=None, extension='.csv', srm_identifier='STD', + cmap=None, time_format=None, internal_standard='Ca43', + file_structure='multi', names='file_names', srm_file=None, pbar=None, split_kwargs={}): + """ For processing and analysing whole LA - ICPMS datasets. Parameters @@ -156,14 +160,6 @@ class analyse(object): cmaps : dict An analyte - specific colour map, used for plotting. """ - - def __init__(self, data_path, errorhunt=False, config='DEFAULT', - dataformat=None, extension='.csv', srm_identifier='STD', - cmap=None, time_format=None, internal_standard='Ca43', - file_structure='multi', names='file_names', srm_file=None, pbar=None, split_kwargs={}): - """ - For processing and analysing whole LA - ICPMS datasets. - """ # initialise log params = {k: v for k, v in locals().items() if k not in ['self', 'pbar']} self.log = ['__init__ :: args=() kwargs={}'.format(str(params))] @@ -279,7 +275,9 @@ def __init__(self, data_path, errorhunt=False, config='DEFAULT', data.sort(key=lambda d: d.uTime[0]) # process sample names - if (names == 'file_names') | (names == 'metadata_names'): + if file_structure == 'long': + samples = np.array([s.sample for s in data], dtype=object) + elif (names == 'file_names') | (names == 'metadata_names'): samples = np.array([s.sample.replace(' ', '') for s in data], dtype=object) # get all sample names # if duplicates, rename them usamples, ucounts = np.unique(samples, return_counts=True) @@ -292,8 +290,6 @@ def __init__(self, data_path, errorhunt=False, config='DEFAULT', samples[ind] = new # rename in samples for s, ns in zip([data[i] for i in np.where(ind)[0]], new): s.sample = ns # rename in D objects - elif file_structure == 'long': - samples = np.array([s.sample for s in data], dtype=object) else: samples = np.arange(len(data)) # assign a range of numbers for i, s in enumerate(samples): diff --git a/latools/preprocessing/split.py b/latools/preprocessing/split.py index 5e472a5..ed6f6d2 100644 --- a/latools/preprocessing/split.py +++ b/latools/preprocessing/split.py @@ -185,7 +185,7 @@ def long_file(data_file, dataformat, sample_list, analyte='total_counts', savedi srm_replace.append(s) sample_list = srm_replace - dataformat = read_dataformat(dataformat, silent=False) + dataformat = read_dataformat(dataformat, silent=True) _, _, dat, meta = read_data(data_file, dataformat=dataformat, name_mode='file') @@ -211,6 +211,10 @@ def long_file(data_file, dataformat, sample_list, analyte='total_counts', savedi n = int(max(ns)) nsamples = len(sample_list) + + print('\n*** Starting Long File Split ***') + print(f'There are {nsamples} in the sample list.') + print(f'With initial settings, we have found {n} ablations in the data.') # deal with wildcards if nsamples <= n and mode != 'strict': @@ -249,12 +253,13 @@ def long_file(data_file, dataformat, sample_list, analyte='total_counts', savedi ns[sig] = np.cumsum((sig ^ np.roll(sig, 1)) & sig)[sig] n = int(max(ns)) print(' (Removed data fragments < {} points long)'.format(min_points)) - elif isinstance(min_points, (int, float)): - # minimum point filter - sig = sig & np.roll(sig, min_points) - ns = np.zeros(sig.size) - ns[sig] = np.cumsum((sig ^ np.roll(sig, 1)) & sig)[sig] - n = int(max(ns)) + # elif isinstance(min_points, (int, float)): + # print(' -> There are more ablations than samples...') + # # minimum point filter + # sig = sig & np.roll(sig, min_points) + # ns = np.zeros(sig.size) + # ns[sig] = np.cumsum((sig ^ np.roll(sig, 1)) & sig)[sig] + # n = int(max(ns)) else: print(' -> There are more samples than ablations...') print(' Check your sample list is correct. If so, consider') @@ -262,7 +267,7 @@ def long_file(data_file, dataformat, sample_list, analyte='total_counts', savedi return minn = min([len(sample_list), n]) - + # calculate split boundaries bounds = [] lower = 0 @@ -307,7 +312,7 @@ def long_file(data_file, dataformat, sample_list, analyte='total_counts', savedi # save output if passthrough: - print(f"Success! {n} ablations identified.") + print(f"*** Success! {n} ablations identified. ***\n") for sample, sdat in sections.items(): sanalytes = list(sdat['rawdata'].keys()) diff --git a/old_setup.py b/old_setup.py new file mode 100644 index 0000000..bd32616 --- /dev/null +++ b/old_setup.py @@ -0,0 +1,45 @@ +from setuptools import setup, find_packages + +# bcause TravisCI was being a jerK +try: + from latools import __version__ +except: + __version__ = "version_missing" + +with open("README.md", "r") as fh: + long_description = fh.read() + +setup(name='latools', + version=__version__, + description='Tools for LA-ICPMS data analysis.', + long_description=long_description, + long_description_content_type="text/markdown", + url='https://github.com/oscarbranson/latools', + author='Oscar Branson', + author_email='oscarbranson@gmail.com', + license='MIT', + packages=find_packages(), + classifiers=['Development Status :: 4 - Beta', + 'Intended Audience :: Science/Research', + 'Topic :: Scientific/Engineering', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + ], + python_requires='>3.6', + install_requires=['numpy', + 'pandas', + 'matplotlib', + 'uncertainties', + 'scikit-learn', + 'scipy', + 'Ipython', + 'configparser', + 'tqdm' + ], + package_data={ + 'latools': ['latools.cfg', + 'resources/*', + 'resources/data_formats/*', + 'resources/test_data/*'], + }, + zip_safe=False)