From 25d09ee315bc9b44f90e80c60117b71043c7e04a Mon Sep 17 00:00:00 2001 From: Andreas Hellerschmied <--local> Date: Fri, 30 Dec 2022 09:45:41 +0100 Subject: [PATCH] Minor changs for release 0.0.3: code cleanup, file headers, command line help for ls2csv, etc. --- README.md | 22 +++++++++++++++++-- lifescale/command_line/__init__.py | 18 ++++++++++++++++ lifescale/command_line/command_line.py | 29 ++++++++++++++++++++++---- lifescale/models/__init__.py | 18 ++++++++++++++++ lifescale/models/ls_data.py | 27 ++++++++++++++++++------ lifescale/scripts/__init__.py | 18 ++++++++++++++++ lifescale/scripts/ls2csv.py | 20 +++++++++++++++--- 7 files changed, 137 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e702bcb..790f669 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,26 @@ files (where `[run-name]` is the name from the settings sheet): * `SampleSummary_[run-name].csv`: Data from the sheet IntervalAnalysis plus sample related data from AcquisitionIntervals. ### Usage: - * Conversion: `ls2csv -i [path and nale of xlsm file] -o [outpur directory] [-s] [-nv]` - * Help: `ls2csv -h` +``` +ls2csv -i [path and nale of xlsm file] -o [outpur directory] [-s] [-nv] + +options: + -h, --help show this help message and exit + -i INPUT_XLSM, --input-xlsm INPUT_XLSM + Path and name of the input xlsm file created by + lifescale. (default: None) + -o OUT_DIR, --out-dir OUT_DIR + Output directory for the CSV files. (default: None) + -nv, --not-verbose Disable command line status messages. (default: False) + -s, --sample-stats Calculate sample statistics of masses (median, std. + deviation, quartiles, interquartile range) and add + them to the SampleSummary output CSV file (columns: + Mass_median, Mass_std, Mass_q25, Mass_q75,Mass_iqr). + (default: False) + -t, --sort-masses-by-time + Sort data in the Masses CSV file by acquisition time. + (default: False) +``` # License and copyright diff --git a/lifescale/command_line/__init__.py b/lifescale/command_line/__init__.py index e69de29..522bb39 100644 --- a/lifescale/command_line/__init__.py +++ b/lifescale/command_line/__init__.py @@ -0,0 +1,18 @@ +"""LifeScale utils command line interface module. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +:Authors: + Andreas Hellerschmied (heller182@gmx.at) +""" \ No newline at end of file diff --git a/lifescale/command_line/command_line.py b/lifescale/command_line/command_line.py index ea86d34..86eff8c 100644 --- a/lifescale/command_line/command_line.py +++ b/lifescale/command_line/command_line.py @@ -1,6 +1,19 @@ """Command line interface of lifescale utils. Copyright (C) 2022 Andreas Hellerschmied <heller182@gmx.at> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. """ from lifescale.scripts.ls2csv import ls2csv as ls2csv_main @@ -36,19 +49,27 @@ def ls2csv(): parser.add_argument("-o", "--out-dir", type=is_dir, required=True, help="Output directory for the CSV files.") parser.add_argument("-nv", "--not-verbose", required=False, help="Disable command line status messages.", action='store_true') - parser.add_argument("-s", "--sample-stats", required=False, help="Calculate sample statistics (mean, median, IQR, " - "StDev.) and add it to the output CSV files.", + parser.add_argument("-s", "--sample-stats", required=False, help="Calculate sample statistics of masses (median, " + "std. deviation, quartiles, interquartile range) " + "and add them to the " + "SampleSummary output CSV file (columns: " + "Mass_median, Mass_std, Mass_q25, Mass_q75," + "Mass_iqr).", action='store_true') - # parser.add_argument("--out-dir", type=is_dir, required=False, - # help="path to output directory", default=OUT_PATH) + parser.add_argument("-t", "--sort-masses-by-time", required=False, help="Sort data in the Masses CSV file by " + "acquisition time.", + action='store_true') + args = parser.parse_args() verbose = not args.not_verbose return ls2csv_main(xlsm_filename=args.input_xlsm, output_dir=args.out_dir, sample_stats=args.sample_stats, + sort_by_time=args.sort_masses_by_time, verbose=verbose) if __name__ == '__main__': + """Main function for debugging and testing.""" ls2csv() diff --git a/lifescale/models/__init__.py b/lifescale/models/__init__.py index e69de29..c91b869 100644 --- a/lifescale/models/__init__.py +++ b/lifescale/models/__init__.py @@ -0,0 +1,18 @@ +"""LifeScale utils objects module. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +:Authors: + Andreas Hellerschmied (heller182@gmx.at) +""" \ No newline at end of file diff --git a/lifescale/models/ls_data.py b/lifescale/models/ls_data.py index 73c1cb0..f60d18a 100644 --- a/lifescale/models/ls_data.py +++ b/lifescale/models/ls_data.py @@ -132,7 +132,7 @@ class LSData: input_xlsm_filename : str Filename and path of the xlsm file written by LifeScale. verbose : bool, optional (default = `True`) - If `True`. status messages are written to the command line. + If `True`, status messages are written to the command line. Returns ------- @@ -140,7 +140,7 @@ class LSData: Contains all LS output data loaded from the given xlsm file. """ - REQUIRED_XLSM_SHEET_NAMES = [ + REQUIRED_XLSM_SHEET_NAMES = [ # Raise an exception if they are not present in the input xlsm file. 'AcquisitionIntervals', 'IntervalAnalysis', 'PanelData', @@ -412,8 +412,24 @@ class LSData: df_masses=df_masses, ) - def export_csv_files(self, output_filepath, verbose=True, sort_by_time=False): - """Write CSV files to output directory""" + def export_csv_files(self, output_filepath, sort_by_time=False, verbose=True): + """Write CSV files to output directory + + Parameters + ---------- + output_filepath : str + Path to the output directory. + sort_by_time : bool, optional (default=`False`) + Sort data in the Masses CSV file by the observation time. + verbose : bool, optional (default = `True`) + If `True`, status messages are written to the command line. + + Returns + ------- + :py:obj:`.LSData` + Contains all LS output data loaded from the given xlsm file. + + """ if verbose: print('Write output') @@ -453,7 +469,6 @@ class LSData: # TODO: Output format (number of digits) # TODO: Select columns for output (settable as parameter + default settings for each csv file) - # TODO: Optionally order data series by time (parameter)?! def calc_sample_statistics(self, verbose=True): """Calculate statistical values for each sample and add it to the self.df_interval_analysis.""" @@ -534,4 +549,4 @@ if __name__ == '__main__': ls_data = LSData.from_xlsm_file(input_xlsm_filename=xlsm_filename) ls_data.export_csv_files(output_directory) - print('test') + print('End') diff --git a/lifescale/scripts/__init__.py b/lifescale/scripts/__init__.py index e69de29..5ba464a 100644 --- a/lifescale/scripts/__init__.py +++ b/lifescale/scripts/__init__.py @@ -0,0 +1,18 @@ +"""LifeScale utils scripts module. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +:Authors: + Andreas Hellerschmied (heller182@gmx.at) +""" \ No newline at end of file diff --git a/lifescale/scripts/ls2csv.py b/lifescale/scripts/ls2csv.py index 92f4bd1..55c902b 100644 --- a/lifescale/scripts/ls2csv.py +++ b/lifescale/scripts/ls2csv.py @@ -1,13 +1,27 @@ """Conversion program from xlsm to csv. -Copyright (C) 2022 Andreas Hellerschmied <heller182@gmx.at>""" +Copyright (C) 2022 Andreas Hellerschmied <heller182@gmx.at> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. +""" from lifescale.models.ls_data import LSData -def ls2csv(xlsm_filename, output_dir, sample_stats=True, verbose=True): +def ls2csv(xlsm_filename, output_dir, sample_stats=True, sort_by_time=False, verbose=True): """Convert lifescale output file (xlsm) to csv files.""" ls_data = LSData.from_xlsm_file(input_xlsm_filename=xlsm_filename, verbose=verbose) if sample_stats: ls_data.calc_sample_statistics(verbose=verbose) - ls_data.export_csv_files(output_dir, verbose=verbose) + ls_data.export_csv_files(output_dir, sort_by_time=sort_by_time, verbose=verbose) -- GitLab