pb-process-tools 1.4.0__tar.gz → 3.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. pb_process_tools-3.1.7/PKG-INFO +27 -0
  2. pb_process_tools-3.1.7/README.md +30 -0
  3. pb_process_tools-3.1.7/bin/pbpt_gen_template.py +576 -0
  4. pb_process_tools-3.1.7/pb_process_tools.egg-info/PKG-INFO +27 -0
  5. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pb_process_tools.egg-info/SOURCES.txt +3 -6
  6. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pb_process_tools.egg-info/requires.txt +0 -1
  7. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pbprocesstools/__init__.py +29 -21
  8. pb_process_tools-3.1.7/pbprocesstools/pbpt_process.py +445 -0
  9. pb_process_tools-3.1.7/pbprocesstools/pbpt_q_process.py +1367 -0
  10. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pbprocesstools/pbpt_utils.py +109 -86
  11. pb_process_tools-3.1.7/setup.py +71 -0
  12. pb_process_tools-3.1.7/test/test_pbpt_utils.py +65 -0
  13. pb_process_tools-1.4.0/PKG-INFO +0 -20
  14. pb_process_tools-1.4.0/README.md +0 -95
  15. pb_process_tools-1.4.0/bin/genslurmsub.py +0 -63
  16. pb_process_tools-1.4.0/bin/prefixcmdslst.py +0 -61
  17. pb_process_tools-1.4.0/bin/splitcmdslist.py +0 -147
  18. pb_process_tools-1.4.0/bin/subcmdslurm.py +0 -48
  19. pb_process_tools-1.4.0/pb_process_tools.egg-info/PKG-INFO +0 -20
  20. pb_process_tools-1.4.0/pbprocesstools/pbpt_process.py +0 -868
  21. pb_process_tools-1.4.0/pbprocesstools/pbpt_q_process.py +0 -901
  22. pb_process_tools-1.4.0/pbprocesstools/pbpt_sbatch.py +0 -199
  23. pb_process_tools-1.4.0/setup.py +0 -63
  24. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/LICENSE.txt +0 -0
  25. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/MANIFEST.in +0 -0
  26. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pb_process_tools.egg-info/dependency_links.txt +0 -0
  27. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/pb_process_tools.egg-info/top_level.txt +0 -0
  28. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/setup.cfg +0 -0
  29. {pb_process_tools-1.4.0 → pb_process_tools-3.1.7}/share/loggingconfig.json +0 -0
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: pb_process_tools
3
+ Version: 3.1.7
4
+ Summary: Tools for batch processing data, including on HPC cluster with slurm.
5
+ Home-page: https://github.com/remotesensinginfo/pb_process_tools
6
+ Author: Pete Bunting
7
+ Author-email: petebunting@mac.com
8
+ License: LICENSE.txt
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ License-File: LICENSE.txt
18
+ Requires-Dist: sqlalchemy
19
+ Requires-Dist: tqdm
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: summary
@@ -0,0 +1,30 @@
1
+ # PB Process Tools
2
+
3
+ ![example workflow](https://github.com/remotesensinginfo/pb_process_tools/actions/workflows/main.yml/badge.svg)
4
+
5
+ Tools for batch processing workflows as a set of jobs. Can either be used on a HPC with
6
+ slurm or on a single workstation using GNU parallel.
7
+
8
+ To install
9
+
10
+ To install pb_process_tools to the default location, the following command is to be used from within the pb_process_tools source directory (i.e., where setup.py is located):
11
+
12
+ ``
13
+ pip install .
14
+ ``
15
+
16
+
17
+ if you want to install into another location using the --prefix option.
18
+
19
+ ``
20
+ pip install . --prefix=/to/install/path
21
+ ``
22
+
23
+ ## Get Started ##
24
+
25
+ Run the command line function to generate a set of template functions:
26
+
27
+ ``
28
+ pbpt_gen_template.py --output /path/to/out/dir --dbfile path/to/db/config/file.txt
29
+ ``
30
+
@@ -0,0 +1,576 @@
1
+ #! /usr/bin/env python
2
+
3
+ ############################################################################
4
+ # pbpt_gen_template.py
5
+ #
6
+ # Copyright 2023 ARCSI.
7
+ #
8
+ # Purpose: A script generate a template for running pb_process_tools
9
+ #
10
+ # Author: Pete Bunting
11
+ # Email: pfb@aber.ac.uk
12
+ # Date: 6/1/2023
13
+ # Version: 1.0
14
+ #
15
+ # History:
16
+ # Version 1.0 - Created.
17
+ #
18
+ ############################################################################
19
+
20
+ import argparse
21
+ import os
22
+
23
+ import jinja2
24
+ import rsgislib.tools.filetools
25
+ import rsgislib.tools.utils
26
+
27
+ BLACK_AVAIL = True
28
+ try:
29
+ import black
30
+ except ImportError:
31
+ BLACK_AVAIL = False
32
+
33
+ pbpt_process_cmd_code_tmplt = """
34
+ import logging
35
+ import os
36
+
37
+ from pbprocesstools.pbpt_q_process import PBPTQProcessTool
38
+
39
+ logger = logging.getLogger(__name__)
40
+
41
+ class ProcessCmd(PBPTQProcessTool):
42
+ def __init__(self):
43
+ super().__init__(cmd_name="{{ ana_py_file }}", descript=None)
44
+
45
+ def do_processing(self, **kwargs):
46
+ print("** Implemented your analysis here **")
47
+ # You can access the input parameters from within the self.params dict
48
+ # For example: self.params["input1"]
49
+
50
+ def required_fields(self, **kwargs):
51
+ # Return a list of the required fields which will be checked
52
+ return [
53
+ "input1",
54
+ "input2",
55
+ "input3",
56
+ "output1",
57
+ ]
58
+
59
+ def outputs_present(self, **kwargs):
60
+ # Check the output files are as expected - called with --check option
61
+ # the function expects a tuple with the first item a list of booleans
62
+ # specifying whether the file is OK and secondly a dict with outputs
63
+ # as keys and any error message as the value
64
+
65
+ # A function (self.check_files) has been provided to do the work for
66
+ # you which takes a dict of inputs which will do the work for you in
67
+ # most cases. The supported file types are: gdal_image, gdal_vector,
68
+ # hdf5, file (checks present) and filesize (checks present and size > 0)
69
+
70
+ files_dict = dict()
71
+ files_dict[self.params["output1"]] = "gdal_image"
72
+ return self.check_files(files_dict)
73
+
74
+ def remove_outputs(self, **kwargs):
75
+ # Remove the output files and reset anything
76
+ # else which might need to be reset if re-running the job.
77
+ if os.path.exists(self.params["output1"]):
78
+ os.remove(self.params["output1"])
79
+
80
+
81
+ if __name__ == "__main__":
82
+ ProcessCmd().std_run()
83
+
84
+ """
85
+
86
+
87
+ pbpt_gen_cmds_cls_slurm_sing_tmplt = """
88
+ import logging
89
+ import os
90
+ import glob
91
+ import rsgislib.tools.filetools
92
+
93
+ from pbprocesstools.pbpt_q_process import PBPTGenQProcessToolCmds
94
+
95
+ logger = logging.getLogger(__name__)
96
+
97
+ class GenCmds(PBPTGenQProcessToolCmds):
98
+ def gen_command_info(self, **kwargs):
99
+ print("** This function needs implementing! **")
100
+
101
+ # Create output directory if it doesn't exist.
102
+ if not os.path.exists(kwargs["out_dir"]):
103
+ os.mkdir(kwargs["out_dir"])
104
+
105
+ # Get the list of input images
106
+ ref_imgs = glob.glob(kwargs["ref_imgs"])
107
+
108
+ # Loop through the reference images to create the jobs
109
+ for ref_img in ref_imgs:
110
+ # Get the basename of the input file to make the output file name
111
+ basename = rsgislib.tools.filetools.get_file_basename(ref_img)
112
+
113
+ # Create the output file name
114
+ output_file = os.path.join(kwargs["out_dir"], f"{basename}.tif")
115
+ # Check if the output file exists.
116
+ if not os.path.exists(output_file):
117
+ # You will probably have a loop here:
118
+ # Within the loop create a dict with the parameters for each
119
+ # job which will be added to the self.params list.
120
+ c_dict = dict()
121
+ c_dict["input1"] = ""
122
+ c_dict["input2"] = ""
123
+ c_dict["input3"] = ""
124
+ c_dict["output1"] = ""
125
+ self.params.append(c_dict)
126
+
127
+ def run_gen_commands(self):
128
+ # Could Pass info to gen_command_info function
129
+ # (e.g., input / output directories)
130
+ self.gen_command_info(ref_imgs="path/to/inputs/*.kea",
131
+ out_dir="/path/to/outputs")
132
+
133
+ self.pop_params_db()
134
+
135
+ self.create_slurm_sub_sh(
136
+ "job name", # Provide a name for the job
137
+ 16448, # Specify the memory which should be requested from slurm
138
+ "/path/to/logs", # Specify a path where slurm console logs will be written
139
+ run_script="run_exe_analysis.sh", # The file to call to run analysis
140
+ job_dir="job_scripts", # Directory will all the slurm files
141
+ db_info_file="pbpt_lcl_db_info.txt",
142
+ #account_name="", # Optionally provide an account name
143
+ n_cores_per_job=5, # The number of cores per job
144
+ n_xtr_cmds=5, # Number of extra commands - allows for jobs crashes.
145
+ n_jobs=5, # the number of jobs to run in slurm
146
+ job_time_limit="2-23:59", # Time limit for the jobs.
147
+ module_load="module load parallel singularity", # modules to load
148
+ )
149
+
150
+ if __name__ == "__main__":
151
+ py_script = os.path.abspath("{{ ana_py_file }}")
152
+ script_cmd = f"{{ sing_cmd }} python {py_script}"
153
+
154
+ process_tools_mod = "{{ ana_py_mod }}"
155
+ process_tools_cls = "ProcessCmd"
156
+
157
+ create_tools = GenCmds(
158
+ cmd=script_cmd,
159
+ db_conn_file="{{ dbfile }}",
160
+ lock_file_path="./pbpt_lock_file.txt",
161
+ process_tools_mod=process_tools_mod,
162
+ process_tools_cls=process_tools_cls,
163
+ )
164
+ create_tools.parse_cmds()
165
+
166
+ """
167
+
168
+ pbpt_gen_cmds_cls_slurm_tmplt = """
169
+ import logging
170
+ import os
171
+ import glob
172
+ import rsgislib.tools.filetools
173
+
174
+ from pbprocesstools.pbpt_q_process import PBPTGenQProcessToolCmds
175
+
176
+ logger = logging.getLogger(__name__)
177
+
178
+ class GenCmds(PBPTGenQProcessToolCmds):
179
+ def gen_command_info(self, **kwargs):
180
+ print("** This function needs implementing! **")
181
+
182
+ # Create output directory if it doesn't exist.
183
+ if not os.path.exists(kwargs["out_dir"]):
184
+ os.mkdir(kwargs["out_dir"])
185
+
186
+ # Get the list of input images
187
+ ref_imgs = glob.glob(kwargs["ref_imgs"])
188
+
189
+ # Loop through the reference images to create the jobs
190
+ for ref_img in ref_imgs:
191
+ # Get the basename of the input file to make the output file name
192
+ basename = rsgislib.tools.filetools.get_file_basename(ref_img)
193
+
194
+ # Create the output file name
195
+ output_file = os.path.join(kwargs["out_dir"], f"{basename}.tif")
196
+ # Check if the output file exists.
197
+ if not os.path.exists(output_file):
198
+ # You will probably have a loop here:
199
+ # Within the loop create a dict with the parameters for each
200
+ # job which will be added to the self.params list.
201
+ c_dict = dict()
202
+ c_dict["input1"] = ""
203
+ c_dict["input2"] = ""
204
+ c_dict["input3"] = ""
205
+ c_dict["output1"] = ""
206
+ self.params.append(c_dict)
207
+
208
+ def run_gen_commands(self):
209
+ # Could Pass info to gen_command_info function
210
+ # (e.g., input / output directories)
211
+ self.gen_command_info(ref_imgs="path/to/inputs/*.kea",
212
+ out_dir="/path/to/outputs")
213
+
214
+ self.pop_params_db()
215
+
216
+ self.create_slurm_sub_sh(
217
+ "job name", # Provide a name for the job
218
+ 16448, # Specify the memory which should be requested from slurm
219
+ "/path/to/logs", # Specify a path where slurm console logs will be written
220
+ run_script="run_exe_analysis.sh", # The file to call to run analysis
221
+ job_dir="job_scripts", # Directory will all the slurm files
222
+ db_info_file="pbpt_lcl_db_info.txt",
223
+ #account_name="", # Optionally provide an account name
224
+ n_cores_per_job=5, # The number of cores per job
225
+ n_xtr_cmds=5, # Number of extra commands - allows for jobs crashes.
226
+ n_jobs=5, # the number of jobs to run in slurm
227
+ job_time_limit="2-23:59", # Time limit for the jobs.
228
+ module_load="module load parallel", # modules to load
229
+ )
230
+
231
+ if __name__ == "__main__":
232
+ py_script = os.path.abspath("{{ ana_py_file }}")
233
+ script_cmd = f"python {py_script}"
234
+
235
+ process_tools_mod = "{{ ana_py_mod }}"
236
+ process_tools_cls = "ProcessCmd"
237
+
238
+ create_tools = GenCmds(
239
+ cmd=script_cmd,
240
+ db_conn_file="{{ dbfile }}",
241
+ lock_file_path="./pbpt_lock_file.txt",
242
+ process_tools_mod=process_tools_mod,
243
+ process_tools_cls=process_tools_cls,
244
+ )
245
+ create_tools.parse_cmds()
246
+
247
+ """
248
+
249
+ pbpt_gen_cmds_cls_parallel_sing_tmplt = """
250
+ import logging
251
+ import os
252
+ import glob
253
+ import rsgislib.tools.filetools
254
+
255
+ from pbprocesstools.pbpt_q_process import PBPTGenQProcessToolCmds
256
+
257
+ logger = logging.getLogger(__name__)
258
+
259
+ class GenCmds(PBPTGenQProcessToolCmds):
260
+ def gen_command_info(self, **kwargs):
261
+ print("** This function needs implementing! **")
262
+
263
+ # Create output directory if it doesn't exist.
264
+ if not os.path.exists(kwargs["out_dir"]):
265
+ os.mkdir(kwargs["out_dir"])
266
+
267
+ # Get the list of input images
268
+ ref_imgs = glob.glob(kwargs["ref_imgs"])
269
+
270
+ # Loop through the reference images to create the jobs
271
+ for ref_img in ref_imgs:
272
+ # Get the basename of the input file to make the output file name
273
+ basename = rsgislib.tools.filetools.get_file_basename(ref_img)
274
+
275
+ # Create the output file name
276
+ output_file = os.path.join(kwargs["out_dir"], f"{basename}.tif")
277
+ # Check if the output file exists.
278
+ if not os.path.exists(output_file):
279
+ # You will probably have a loop here:
280
+ # Within the loop create a dict with the parameters for each
281
+ # job which will be added to the self.params list.
282
+ c_dict = dict()
283
+ c_dict["input1"] = ""
284
+ c_dict["input2"] = ""
285
+ c_dict["input3"] = ""
286
+ c_dict["output1"] = ""
287
+ self.params.append(c_dict)
288
+
289
+ def run_gen_commands(self):
290
+ # Could Pass info to gen_command_info function
291
+ # (e.g., input / output directories)
292
+ self.gen_command_info(ref_imgs="path/to/inputs/*.kea",
293
+ out_dir="/path/to/outputs")
294
+
295
+ self.pop_params_db()
296
+
297
+ self.create_shell_exe(
298
+ run_script="run_exe_analysis.sh", # The file to call to run analysis
299
+ cmds_sh_file="pbpt_cmds_lst.sh", # The list of commands to be run.
300
+ n_cores=10, # The number of cores to use for analysis.
301
+ db_info_file="pbpt_lcl_db_info.json",
302
+ )
303
+
304
+ if __name__ == "__main__":
305
+ py_script = os.path.abspath("{{ ana_py_file }}")
306
+ script_cmd = f"{{ sing_cmd }} python {py_script}"
307
+
308
+ process_tools_mod = "{{ ana_py_mod }}"
309
+ process_tools_cls = "ProcessCmd"
310
+
311
+ create_tools = GenCmds(
312
+ cmd=script_cmd,
313
+ db_conn_file="{{ dbfile }}",
314
+ lock_file_path="./pbpt_lock_file.txt",
315
+ process_tools_mod=process_tools_mod,
316
+ process_tools_cls=process_tools_cls,
317
+ )
318
+ create_tools.parse_cmds()
319
+
320
+ """
321
+
322
+ pbpt_gen_cmds_cls_parallel_tmplt = """
323
+ import logging
324
+ import os
325
+ import glob
326
+ import rsgislib.tools.filetools
327
+
328
+ from pbprocesstools.pbpt_q_process import PBPTGenQProcessToolCmds
329
+
330
+ logger = logging.getLogger(__name__)
331
+
332
+ class GenCmds(PBPTGenQProcessToolCmds):
333
+ def gen_command_info(self, **kwargs):
334
+ print("** This function needs implementing! **")
335
+
336
+ # Create output directory if it doesn't exist.
337
+ if not os.path.exists(kwargs["out_dir"]):
338
+ os.mkdir(kwargs["out_dir"])
339
+
340
+ # Get the list of input images
341
+ ref_imgs = glob.glob(kwargs["ref_imgs"])
342
+
343
+ # Loop through the reference images to create the jobs
344
+ for ref_img in ref_imgs:
345
+ # Get the basename of the input file to make the output file name
346
+ basename = rsgislib.tools.filetools.get_file_basename(ref_img)
347
+
348
+ # Create the output file name
349
+ output_file = os.path.join(kwargs["out_dir"], f"{basename}.tif")
350
+ # Check if the output file exists.
351
+ if not os.path.exists(output_file):
352
+ # You will probably have a loop here:
353
+ # Within the loop create a dict with the parameters for each
354
+ # job which will be added to the self.params list.
355
+ c_dict = dict()
356
+ c_dict["input1"] = ""
357
+ c_dict["input2"] = ""
358
+ c_dict["input3"] = ""
359
+ c_dict["output1"] = ""
360
+ self.params.append(c_dict)
361
+
362
+ def run_gen_commands(self):
363
+ # Could Pass info to gen_command_info function
364
+ # (e.g., input / output directories)
365
+ self.gen_command_info(ref_imgs="path/to/inputs/*.kea",
366
+ out_dir="/path/to/outputs")
367
+
368
+ self.pop_params_db()
369
+
370
+ self.create_shell_exe(
371
+ run_script="run_exe_analysis.sh", # The file to call to run analysis
372
+ cmds_sh_file="pbpt_cmds_lst.sh", # The list of commands to be run.
373
+ n_cores=10, # The number of cores to use for analysis.
374
+ db_info_file="pbpt_lcl_db_info.json",
375
+ )
376
+
377
+ if __name__ == "__main__":
378
+ py_script = os.path.abspath("{{ ana_py_file }}")
379
+ script_cmd = f"python {py_script}"
380
+
381
+ process_tools_mod = "{{ ana_py_mod }}"
382
+ process_tools_cls = "ProcessCmd"
383
+
384
+ create_tools = GenCmds(
385
+ cmd=script_cmd,
386
+ db_conn_file="{{ dbfile }}",
387
+ lock_file_path="./pbpt_lock_file.txt",
388
+ process_tools_mod=process_tools_mod,
389
+ process_tools_cls=process_tools_cls,
390
+ )
391
+ create_tools.parse_cmds()
392
+
393
+ """
394
+
395
+
396
+ def gen_pb_process_tools_template(
397
+ output_dir,
398
+ dbfile,
399
+ out_file_prefix="",
400
+ use_slurm=False,
401
+ singularity=False,
402
+ singularity_paths=None,
403
+ overwrite=False,
404
+ ):
405
+ if not os.path.exists(output_dir):
406
+ raise Exception("Specified output directory does not exist.")
407
+
408
+ sing_cmd = ""
409
+ use_singularity = False
410
+ if (singularity is not None) and (singularity != ""):
411
+ sing_paths_bind = ""
412
+ if singularity_paths is not None:
413
+ for sing_path in singularity_paths:
414
+ sing_paths_bind += f" --bind {sing_path}"
415
+ sing_cmd = f"singularity exec {sing_paths_bind} {singularity}"
416
+ use_singularity = True
417
+
418
+ gen_py_file_base = "gen_cmds.py"
419
+ ana_py_file_base = "perform_analysis.py"
420
+ run_gen_sh_base = "run_gen_cmds.sh"
421
+ run_report_sh_base = "run_report.sh"
422
+ run_reset_errs_sh_base = "run_reset_errs.sh"
423
+ run_check_sh_base = "run_checks.sh"
424
+
425
+ if (out_file_prefix is not None) and (out_file_prefix != ""):
426
+ gen_py_file_base = f"{out_file_prefix}_{gen_py_file_base}"
427
+ ana_py_file_base = f"{out_file_prefix}_{ana_py_file_base}"
428
+ run_gen_sh_base = f"{out_file_prefix}_{run_gen_sh_base}"
429
+ run_report_sh_base = f"{out_file_prefix}_{run_report_sh_base}"
430
+ run_reset_errs_sh_base = f"{out_file_prefix}_{run_reset_errs_sh_base}"
431
+ run_check_sh_base = f"{out_file_prefix}_{run_check_sh_base}"
432
+
433
+ gen_py_file = os.path.join(output_dir, gen_py_file_base)
434
+ ana_py_file = os.path.join(output_dir, ana_py_file_base)
435
+ ana_py_mod = rsgislib.tools.filetools.get_file_basename(ana_py_file)
436
+ run_gen_sh_file = os.path.join(output_dir, run_gen_sh_base)
437
+ run_report_sh_file = os.path.join(output_dir, run_report_sh_base)
438
+ run_reset_errs_sh_file = os.path.join(output_dir, run_reset_errs_sh_base)
439
+ run_check_sh_file = os.path.join(output_dir, run_check_sh_base)
440
+
441
+ out_files = [
442
+ gen_py_file,
443
+ ana_py_file,
444
+ run_gen_sh_file,
445
+ run_report_sh_file,
446
+ run_reset_errs_sh_file,
447
+ run_check_sh_file,
448
+ ]
449
+
450
+ for out_file in out_files:
451
+ if os.path.exists(out_file) and (not overwrite):
452
+ raise Exception(
453
+ f"File already exists, select --overwrite if you "
454
+ f"wish to over write: {out_file}"
455
+ )
456
+ elif os.path.exists(out_file) and overwrite:
457
+ os.remove(out_file)
458
+
459
+ py_cmd = f"{sing_cmd}python"
460
+
461
+ if use_singularity and use_slurm:
462
+ pbpt_gen_cmds_cls_tmplt_jj = jinja2.Template(pbpt_gen_cmds_cls_slurm_sing_tmplt)
463
+ pbpt_gen_cmds_cls_code = pbpt_gen_cmds_cls_tmplt_jj.render(
464
+ ana_py_file=ana_py_file_base,
465
+ dbfile=dbfile,
466
+ ana_py_mod=ana_py_mod,
467
+ sing_cmd=sing_cmd,
468
+ )
469
+ elif use_slurm:
470
+ pbpt_gen_cmds_cls_tmplt_jj = jinja2.Template(pbpt_gen_cmds_cls_slurm_tmplt)
471
+ pbpt_gen_cmds_cls_code = pbpt_gen_cmds_cls_tmplt_jj.render(
472
+ ana_py_file=ana_py_file_base, dbfile=dbfile, ana_py_mod=ana_py_mod
473
+ )
474
+ elif use_singularity:
475
+ pbpt_gen_cmds_cls_tmplt_jj = jinja2.Template(
476
+ pbpt_gen_cmds_cls_parallel_sing_tmplt
477
+ )
478
+ pbpt_gen_cmds_cls_code = pbpt_gen_cmds_cls_tmplt_jj.render(
479
+ ana_py_file=ana_py_file_base,
480
+ dbfile=dbfile,
481
+ ana_py_mod=ana_py_mod,
482
+ sing_cmd=sing_cmd,
483
+ )
484
+ else:
485
+ pbpt_gen_cmds_cls_tmplt_jj = jinja2.Template(pbpt_gen_cmds_cls_parallel_tmplt)
486
+ pbpt_gen_cmds_cls_code = pbpt_gen_cmds_cls_tmplt_jj.render(
487
+ ana_py_file=ana_py_file_base, dbfile=dbfile, ana_py_mod=ana_py_mod
488
+ )
489
+
490
+ pbpt_process_cmd_code_tmplt_jj = jinja2.Template(pbpt_process_cmd_code_tmplt)
491
+ pbpt_process_cmd_code = pbpt_process_cmd_code_tmplt_jj.render(
492
+ ana_py_file=ana_py_file_base
493
+ )
494
+
495
+ if BLACK_AVAIL:
496
+ pbpt_gen_cmds_cls_code = black.format_str(
497
+ pbpt_gen_cmds_cls_code, mode=black.FileMode()
498
+ )
499
+ pbpt_process_cmd_code = black.format_str(
500
+ pbpt_process_cmd_code, mode=black.FileMode()
501
+ )
502
+
503
+ rsgislib.tools.utils.write_data_to_file(pbpt_gen_cmds_cls_code, gen_py_file)
504
+ rsgislib.tools.utils.write_data_to_file(pbpt_process_cmd_code, ana_py_file)
505
+
506
+ run_gen_cmd = f"{py_cmd} {gen_py_file} --gen"
507
+ rsgislib.tools.utils.write_data_to_file(run_gen_cmd, run_gen_sh_file)
508
+
509
+ run_report_cmd = f"{py_cmd} {gen_py_file} --report | more"
510
+ rsgislib.tools.utils.write_data_to_file(run_report_cmd, run_report_sh_file)
511
+
512
+ run_reset_errs_cmd = f"{py_cmd} {gen_py_file} --error --rmouts"
513
+ rsgislib.tools.utils.write_data_to_file(run_reset_errs_cmd, run_reset_errs_sh_file)
514
+
515
+ run_check_cmd = f"{py_cmd} {gen_py_file} --check"
516
+ rsgislib.tools.utils.write_data_to_file(run_check_cmd, run_check_sh_file)
517
+
518
+
519
+ if __name__ == "__main__":
520
+
521
+ parser = argparse.ArgumentParser(
522
+ prog="pbpt_gen_template.py",
523
+ description="Create template files using pb_process_tools",
524
+ )
525
+ parser.add_argument(
526
+ "-o",
527
+ "--output",
528
+ type=str,
529
+ required=True,
530
+ help="Output directory within which the files will be created",
531
+ )
532
+ parser.add_argument(
533
+ "-d",
534
+ "--dbfile",
535
+ type=str,
536
+ required=True,
537
+ help="A path to a file with the database connection string",
538
+ )
539
+ parser.add_argument(
540
+ "-p", "--prefix", type=str, default="", help="Prefix for the output files",
541
+ )
542
+ parser.add_argument(
543
+ "--slurm",
544
+ action="store_true",
545
+ default=False,
546
+ help="Setup template to use slurm",
547
+ )
548
+ parser.add_argument(
549
+ "--singularity", type=str, help="Setup template to use singularity",
550
+ )
551
+ parser.add_argument(
552
+ "--sing_paths",
553
+ nargs="*",
554
+ type=str,
555
+ help="If using singularity then provide the paths "
556
+ "to be mounted (e.g., /home/user:/data)",
557
+ )
558
+ parser.add_argument(
559
+ "--overwrite",
560
+ action="store_true",
561
+ default=False,
562
+ help="Overwrite files if they already exists",
563
+ )
564
+
565
+ # Call the parser to parse the arguments.
566
+ args = parser.parse_args()
567
+
568
+ gen_pb_process_tools_template(
569
+ args.output,
570
+ args.dbfile,
571
+ out_file_prefix=args.prefix,
572
+ use_slurm=args.slurm,
573
+ singularity=args.singularity,
574
+ singularity_paths=args.sing_paths,
575
+ overwrite=args.overwrite,
576
+ )
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: pb_process_tools
3
+ Version: 3.1.7
4
+ Summary: Tools for batch processing data, including on HPC cluster with slurm.
5
+ Home-page: https://github.com/remotesensinginfo/pb_process_tools
6
+ Author: Pete Bunting
7
+ Author-email: petebunting@mac.com
8
+ License: LICENSE.txt
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ License-File: LICENSE.txt
18
+ Requires-Dist: sqlalchemy
19
+ Requires-Dist: tqdm
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: summary
@@ -2,10 +2,7 @@ LICENSE.txt
2
2
  MANIFEST.in
3
3
  README.md
4
4
  setup.py
5
- bin/genslurmsub.py
6
- bin/prefixcmdslst.py
7
- bin/splitcmdslist.py
8
- bin/subcmdslurm.py
5
+ bin/pbpt_gen_template.py
9
6
  pb_process_tools.egg-info/PKG-INFO
10
7
  pb_process_tools.egg-info/SOURCES.txt
11
8
  pb_process_tools.egg-info/dependency_links.txt
@@ -14,6 +11,6 @@ pb_process_tools.egg-info/top_level.txt
14
11
  pbprocesstools/__init__.py
15
12
  pbprocesstools/pbpt_process.py
16
13
  pbprocesstools/pbpt_q_process.py
17
- pbprocesstools/pbpt_sbatch.py
18
14
  pbprocesstools/pbpt_utils.py
19
- share/loggingconfig.json
15
+ share/loggingconfig.json
16
+ test/test_pbpt_utils.py