diff --git a/setup.py b/setup.py index 84808a3d..2f0a6ee2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pypromice", - version="1.3.0", + version="1.3.1", author="GEUS Glaciology and Climate", description="PROMICE/GC-Net data processing toolbox", long_description=long_description, @@ -19,7 +19,7 @@ keywords="promice gc-net aws climate glaciology greenland geus", classifiers=[ "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "Natural Language :: English", @@ -31,5 +31,15 @@ packages=setuptools.find_packages(where="src"), python_requires=">=3.8", install_requires=['numpy>=1.23.0', 'pandas>=1.5.0', 'xarray>=2022.6.0', 'toml', 'scipy>=1.9.0', 'scikit-learn>=1.1.0', 'Bottleneck', 'netcdf4', 'pyDataverse'], - scripts=['bin/getData', 'bin/getL0tx', 'bin/getL3', 'bin/joinL3', 'bin/getWatsontx', 'bin/getBUFR', 'bin/getMsg'], + entry_points={ + 'console_scripts': [ + 'get_promice_data = pypromice.get.get_promice_data:get_promice_data', + 'get_l0tx = pypromice.tx.get_l0tx:get_l0tx', + 'get_l3 = pypromice.process.get_l3:get_l3', + 'join_l3 = pypromice.process.join_l3:join_l3', + 'get_watsontx = pypromice.get.get_watsontx:get_watsontx', + 'get_bufr = pypromice.postprocess.get_bufr:get_bufr', + 'get_msg = pypromice.tx.get_msg:get_msg' + ], +}, ) diff --git a/src/pypromice/get/__init__.py b/src/pypromice/get/__init__.py new file mode 100644 index 00000000..8269abf2 --- /dev/null +++ b/src/pypromice/get/__init__.py @@ -0,0 +1 @@ +from pypromice.get.get import * diff --git a/src/pypromice/get.py b/src/pypromice/get/get.py similarity index 100% rename from src/pypromice/get.py rename to src/pypromice/get/get.py diff --git a/bin/getData b/src/pypromice/get/get_promice_data.py similarity index 67% rename from bin/getData rename to src/pypromice/get/get_promice_data.py index 7d59170b..29cf1f58 100755 --- a/bin/getData +++ b/src/pypromice/get/get_promice_data.py @@ -1,23 +1,25 @@ #!/usr/bin/env python from argparse import ArgumentParser -import os -from pypromice.get import aws_names, aws_data +import os, unittest +from pypromice.get.get import aws_data -def parse_arguments(): +def parse_arguments_data(): parser = ArgumentParser(description="PROMICE and GC-Net dataset fetcher") parser.add_argument('-n', '--awsname', default=None, type=str, required=True, help='AWS name') parser.add_argument('-f', '--format', default='csv', type=str, required=False, help='File format to save data as') parser.add_argument('-o', '--outpath', default=os.getcwd(), type=str, required=False, - help='Directory where file will be written to') + help='Directory where file will be written to') args = parser.parse_args() return args -if __name__ == '__main__': - args = parse_arguments() +def get_promice_data(): + '''Command line driver for fetching PROMICE and GC-Net datasets''' + + args = parse_arguments_data() # Construct AWS dataset name # n = aws_names() @@ -41,13 +43,21 @@ def parse_arguments(): # Save to file if f in 'csv': outfile = os.path.join(args.outpath, args.awsname.lower()) - data.to_csv(outfile) + if outfile is not None: + data.to_csv(outfile) elif f in 'nc': data.to_netcdf(outfile, mode='w', format='NETCDF4', compute=True) - outfile = os.path.join(args.outpath, args.awsname.lower().split('.csv')[0]+'.nc') + if outfile is not None: + outfile = os.path.join(args.outpath, args.awsname.lower().split('.csv')[0]+'.nc') print(f'File saved to {outfile}') -else: - """Executed on import""" - pass + +#class get_promice_data_test(unittest.TestCase): +# def get_test(self): +# '''Test get_promice_data''' +# d = os.system('get_promice_data -n KPC_U -f csv -o None') + +#if __name__ == "__main__": +# unittest.main() + diff --git a/bin/getBUFR b/src/pypromice/postprocess/get_bufr.py similarity index 98% rename from bin/getBUFR rename to src/pypromice/postprocess/get_bufr.py index 55befae4..bb687689 100644 --- a/bin/getBUFR +++ b/src/pypromice/postprocess/get_bufr.py @@ -18,7 +18,7 @@ # from IPython import embed -def parse_arguments(): +def parse_arguments_bufr(): parser = argparse.ArgumentParser() parser.add_argument('--dev', @@ -64,10 +64,8 @@ def parse_arguments(): args = parser.parse_args() return args -if __name__ == '__main__': - """Executed from the command line""" - - args = parse_arguments() +def get_bufr(): + args = parse_arguments_bufr() # Get list of relative file paths fpaths = glob.glob(args.l3_filepath) @@ -287,4 +285,11 @@ def parse_arguments(): print('no_entry_latest_timestamps: {}'.format(no_entry_latest_timestamps)) print('failed_min_data_wx: {}'.format(failed_min_data_wx)) print('failed_min_data_pos: {}'.format(failed_min_data_pos)) - print('--------------------------------') \ No newline at end of file + print('--------------------------------') + +if __name__ == '__main__': + """Executed from the command line""" + get_bufr() +else: + """Executed on import""" + pass diff --git a/bin/getL3 b/src/pypromice/process/get_l3.py similarity index 87% rename from bin/getL3 rename to src/pypromice/process/get_l3.py index 875fba13..0f4e241f 100755 --- a/bin/getL3 +++ b/src/pypromice/process/get_l3.py @@ -3,9 +3,9 @@ import os import sys from argparse import ArgumentParser -from pypromice.process import AWS +from pypromice.process.aws import AWS -def parse_arguments(): +def parse_arguments_l3(): parser = ArgumentParser(description="AWS L3 processor") parser.add_argument('-c', '--config_file', type=str, required=True, @@ -21,10 +21,8 @@ def parse_arguments(): args = parser.parse_args() return args - -if __name__ == '__main__': - """Executed from the command line""" - args = parse_arguments() +def get_l3(): + args = parse_arguments_l3() logging.basicConfig( format="%(asctime)s; %(levelname)s; %(name)s; %(message)s", @@ -40,9 +38,14 @@ def parse_arguments(): else: aws = AWS(args.config_file, args.inpath, args.variables, args.metadata) - aws.process() - aws.write(args.outpath) - + aws.process() + + if args.outpath is not None: + aws.write(args.outpath) + +if __name__ == '__main__': + """Executed from the command line""" + get_l3() else: """Executed on import""" pass diff --git a/bin/joinL3 b/src/pypromice/process/join_l3.py similarity index 98% rename from bin/joinL3 rename to src/pypromice/process/join_l3.py index 64b29285..28b8be6e 100644 --- a/bin/joinL3 +++ b/src/pypromice/process/join_l3.py @@ -7,7 +7,7 @@ roundValues, resampleL3, writeAll from pypromice.process.L1toL2 import correctPrecip -def parse_arguments(): +def parse_arguments_join(): parser = ArgumentParser(description="AWS L3 joiner for merging together two L3 products, for example an L3 RAW and L3 TX data product. An hourly, daily and monthly L3 data product is outputted to the defined output path") parser.add_argument('-s', '--file1', type=str, required=True, help='Path to source L3 file, which will be preferenced in merge process') @@ -41,9 +41,8 @@ def loadArr(infile): return ds, name -if __name__ == '__main__': - """Executed from the command line""" - args = parse_arguments() +def join_l3(): + args = parse_arguments_join() # Check files if os.path.isfile(args.file1) and os.path.isfile(args.file2): @@ -127,6 +126,11 @@ def loadArr(infile): writeAll(out, name, l3_h, l3_d, l3_m, col_names) print(f'Files saved to {os.path.join(out, name)}...') + + +if __name__ == '__main__': + """Executed from the command line""" + join_l3() else: """Executed on import""" pass diff --git a/bin/getL0tx b/src/pypromice/tx/get_l0tx.py old mode 100755 new mode 100644 similarity index 98% rename from bin/getL0tx rename to src/pypromice/tx/get_l0tx.py index e306a5ee..7b1f6959 --- a/bin/getL0tx +++ b/src/pypromice/tx/get_l0tx.py @@ -9,7 +9,7 @@ from pypromice.tx import getMail, L0tx, sortLines -def parse_arguments(): +def parse_arguments_l0tx(): parser = ArgumentParser(description="AWS L0 transmission fetcher") parser.add_argument('-a', '--account', default=None, type=str, required=True, help='Email account .ini file') parser.add_argument('-p', '--password', default=None, type=str, required=True, help='Email credentials .ini file') @@ -22,10 +22,8 @@ def parse_arguments(): args = parser.parse_args() return args - -if __name__ == '__main__': - """Executed from the command line""" - args = parse_arguments() +def get_l0tx(): + args = parse_arguments_l0tx() toml_path = os.path.join(args.config, args.name+'.toml') toml_list = glob(toml_path) @@ -173,7 +171,10 @@ def parse_arguments(): print(f'Could not write last uid {uid} to {uid_file}') print('Finished') - + +if __name__ == '__main__': + """Executed from the command line""" + get_l0tx() else: """Executed on import""" pass diff --git a/bin/getMsg b/src/pypromice/tx/get_msg.py old mode 100755 new mode 100644 similarity index 97% rename from bin/getMsg rename to src/pypromice/tx/get_msg.py index 74b1cf08..079897fa --- a/bin/getMsg +++ b/src/pypromice/tx/get_msg.py @@ -6,7 +6,7 @@ from pypromice.tx import getMail -def parse_arguments(): +def parse_arguments_msg(): parser = ArgumentParser(description="AWS message downloader") parser.add_argument('-a', '--account', default=None, type=str, required=True, help='Email account .ini file') @@ -21,10 +21,8 @@ def parse_arguments(): args = parser.parse_args() return args - -if __name__ == '__main__': - """Executed from the command line""" - args = parse_arguments() +def get_msg(): + args = parse_arguments_msg() # Set credential paths accounts_file = args.account @@ -100,7 +98,10 @@ def parse_arguments(): print('Finished') - + +if __name__ == '__main__': + """Executed from the command line""" + get_msg() else: """Executed on import""" pass diff --git a/bin/getWatsontx b/src/pypromice/tx/get_watsontx.py similarity index 97% rename from bin/getWatsontx rename to src/pypromice/tx/get_watsontx.py index ae9739a5..2689eebc 100644 --- a/bin/getWatsontx +++ b/src/pypromice/tx/get_watsontx.py @@ -18,7 +18,7 @@ from pypromice.tx import getMail, L0tx, sortLines -def parse_arguments(): +def parse_arguments_watson(): parser = ArgumentParser(description="AWS L0 transmission fetcher") parser.add_argument('-a', '--account', default=None, type=str, required=True, help='Email account .ini file') parser.add_argument('-p', '--password', default=None, type=str, required=True, help='Email credentials .ini file') @@ -30,9 +30,9 @@ def parse_arguments(): return args #------------------------------------------------------------------------------ -if __name__ == '__main__': +def get_watsontx(): """Executed from the command line""" - args = parse_arguments() + args = parse_arguments_watson() # Set payload formatter paths formatter_file = args.formats @@ -139,7 +139,9 @@ def parse_arguments(): print(f'Could not write last uid {uid} to {uid_file}') print('Finished') - + +if __name__ == '__main__': + get_watsontx() else: """Executed on import""" - pass \ No newline at end of file + pass