Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous fixes #42

Merged
merged 5 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/taskhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_tasks(self, tasks, dryrun=False):
self.qsub_args,
task.abrv,
task.exe,
task.cmd,
escape_problem_jobsubmit_chars(task.cmd),
self.qsubscript
)
if dryrun:
Expand Down Expand Up @@ -90,7 +90,7 @@ def run_tasks(self, tasks):
cmd = r'sbatch -J {} --export=p1="{} {}" "{}"'.format(
task.abrv,
task.exe,
task.cmd,
escape_problem_jobsubmit_chars(task.cmd),
self.qsubscript
)
subprocess.call(cmd, shell=True)
Expand Down Expand Up @@ -127,7 +127,6 @@ def _format_task(self, task):

def exec_cmd_mp(job):
job_name, cmd = job
cmd = codecs.decode(cmd, 'unicode-escape')
logger.info('Running job: %s', job_name)
logger.debug('Cmd: %s', cmd)
if platform.system() == "Windows":
Expand Down Expand Up @@ -168,17 +167,24 @@ def exec_cmd(cmd):

def argval2str(item):
if type(item) is str:
if item.startswith("'") and item.endswith("'"):
item_str = r"\'{}\'".format(item[1:-1])
elif item.startswith('"') and item.endswith('"'):
item_str = r'\"{}\"'.format(item[1:-1])
if ( (item.startswith("'") and item.endswith("'"))
or (item.startswith('"') and item.endswith('"'))):
item_str = item
else:
item_str = r'\"{}\"'.format(item)
item_str = '"{}"'.format(item)
else:
item_str = '{}'.format(item)
return item_str


def escape_problem_jobsubmit_chars(str_item):
str_item = str_item.replace("'", "\\'")
str_item = str_item.replace('"', '\\"')
# str_item = str_item.replace(',', '@COMMA@')
# str_item = str_item.replace(' ', '@SPACE@')
return str_item


def convert_optional_args_to_string(args, positional_arg_keys, arg_keys_to_remove):

args_dict = vars(args)
Expand Down
20 changes: 14 additions & 6 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import sys
import traceback
from datetime import datetime
from collections.abc import Collection
from io import StringIO
from xml.etree import cElementTree as ET

import numpy as np
from osgeo import gdal, ogr, osr

try:
import collections.abc as collectionsAbc
except ImportError:
import collections as collectionsAbc

gdal.SetConfigOption('GDAL_PAM_ENABLED', 'NO')

#### Create Loggers
Expand Down Expand Up @@ -484,9 +488,13 @@ def doesCross180(geom):
raise RuntimeError(err)

result = False
_mat = re.findall(r"-?\d+(?:\.\d+)?", geom.ExportToWkt())
if _mat:
x_coords = [float(lng) for (lng, lat) in [_mat[i:i+2] for i in range(0, len(_mat), 2)]]

# Get an array of the longitudes of all the points of all the rings in the polygon
x_coords = []
for ring in geom:
for pt in range(0, ring.GetPointCount()):
x_coords.append(ring.GetX(pt))
if x_coords:
result = (max(x_coords) - min(x_coords)) > 180.0

return result
Expand Down Expand Up @@ -651,7 +659,7 @@ def yield_task_args(task_list, script_args,
object, yielded for each task in `task_list`.
"""
test_task = task_list[0]
if isinstance(test_task, Collection) and not isinstance(test_task, str):
if isinstance(test_task, collectionsAbc.Iterable) and not isinstance(test_task, str):
test_task_nargs = len(test_task)
else:
test_task_nargs = 1
Expand Down Expand Up @@ -695,7 +703,7 @@ def yield_task_args(task_list, script_args,
# or could be a 2D list or NumPy array of argument values.
# Convert 1D single-argument task to the multiple-argument
# structure (a list with a single argument) for code simplicity.
if isinstance(task, Collection) and not isinstance(task, str):
if isinstance(task, collectionsAbc.Iterable) and not isinstance(task, str):
task_arg_list = task
else:
task_arg_list = [task]
Expand Down
2 changes: 1 addition & 1 deletion pgc_ortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def main():
dem_filesz_gb = total_dem_filesz_gb
else:
dem_filesz_gb = os.path.getsize(args.dem) / 1024.0 / 1024 / 1024
pbs_req_mem_gb = int(min(50, max(4, math.ceil(dem_filesz_gb) + 2)))
pbs_req_mem_gb = int(min(50, max(8, math.ceil(dem_filesz_gb) + 2)))
args.l = 'mem={}gb'.format(pbs_req_mem_gb)

## Group Ikonos
Expand Down
3 changes: 1 addition & 2 deletions pgc_pansharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def main():
dem_filesz_gb = total_dem_filesz_gb
else:
dem_filesz_gb = os.path.getsize(args.dem) / 1024.0 / 1024 / 1024

pbs_req_mem_gb = int(max(math.ceil(dem_filesz_gb) + 4, 8))
pbs_req_mem_gb = int(min(50, max(8, math.ceil(dem_filesz_gb) + 2)))
args.l = 'mem={}gb'.format(pbs_req_mem_gb)

## Check GDAL version (2.1.0 minimum)
Expand Down
1 change: 1 addition & 0 deletions qsub_mosaic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#PBS -m n
#PBS -k oe
#PBS -j oe
#PBS -q batch

echo ________________________________________________________
echo
Expand Down
1 change: 1 addition & 0 deletions qsub_ndvi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#PBS -m n
#PBS -k oe
#PBS -j oe
#PBS -q batch

echo ________________________________________________________
echo
Expand Down
1 change: 1 addition & 0 deletions qsub_ortho.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#PBS -m n
#PBS -k oe
#PBS -j oe
#PBS -q batch

echo ________________________________________________________
echo
Expand Down
1 change: 1 addition & 0 deletions qsub_pansharpen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#PBS -m n
#PBS -k oe
#PBS -j oe
#PBS -q batch

echo ________________________________________________________
echo
Expand Down