Commit b1298078 authored by Marco Kurzynski's avatar Marco Kurzynski
Browse files

Revert "added pool"

This reverts commit 1e57ffb3.
parent 1b1b6d2d
......@@ -48,17 +48,12 @@ def interpolate(xin, yin, xout):
return val
def process(directory, records, NBBtemp=None, IBBtemp=None, abb_breakout=None, output_path=''):
return process_helper(1, directory, records, NBBtemp, IBBtemp, abb_breakout, output_path), process_helper(2, directory, records, NBBtemp, IBBtemp, abb_breakout, output_path)
def process(c1_file, c2_file, records, NBBtemp=None, IBBtemp=None, abb_breakout=None, output_path=''):
return process_helper(1, c1_file, records, NBBtemp, IBBtemp, abb_breakout, output_path), process_helper(2, c2_file, records, NBBtemp, IBBtemp, abb_breakout, output_path)
def process_helper(channel_number, directory, records, NBBtemp=None, IBBtemp=None, abb_breakout=None, output_path=''):
def process_helper(channel_number, channel_file, records, NBBtemp=None, IBBtemp=None, abb_breakout=None, output_path=''):
if isinstance(records, numbers.Number):
records = [records]
channel_file = os.path.join(directory, f"{os.path.basename(directory)[2:8]}C{channel_number}.RNC")
if not os.path.isfile(channel_file):
logger.error(f"Invalid input: {directory} -- There must be a YYMMDDC1.RNC and YYMMDDC2.RNC in the same directory")
exit(1)
# Maximun number of points
MAXPTS = 8192
......@@ -73,7 +68,7 @@ def process_helper(channel_number, directory, records, NBBtemp=None, IBBtemp=No
try:
LOGFILE = str.strip(os.environ.get(f'C{channel_number}_LOGFILE'))
except TypeError:
LOGFILE = f'bbcal3p_{os.path.basename(directory)[2:]}.lo{channel_number}'
LOGFILE = f'bbcal3p_{os.path.basename(channel_file)[:6]}.lo{channel_number}'
LOGFILE = os.path.join(output_path, LOGFILE)
# Open logfile
......@@ -167,7 +162,7 @@ def process_helper(channel_number, directory, records, NBBtemp=None, IBBtemp=No
try:
MLTFILE = str.strip(os.environ.get(f'C{channel_number}_MLTFILE'))
except TypeError:
MLTFILE = f'bbcal_{os.path.basename(directory)[2:]}.mlt{channel_number}'
MLTFILE = f'bbcal_{os.path.basename(channel_file)[:6]}.mlt{channel_number}'
MLTFILE = os.path.join(output_path, MLTFILE)
# Write MLT file to Log file
......@@ -177,7 +172,7 @@ def process_helper(channel_number, directory, records, NBBtemp=None, IBBtemp=No
try:
SUMFILE = str.strip(os.environ.get(f'C{channel_number}_SUMFILE'))
except TypeError:
SUMFILE = f'bbcal_{os.path.basename(directory)[2:]}.sum{channel_number}'
SUMFILE = f'bbcal_{os.path.basename(channel_file)[:6]}.sum{channel_number}'
SUMFILE = os.path.join(output_path, SUMFILE)
lf.write("TEXT OUTPUT (SUMMARY) file: %s\n" % SUMFILE)
......@@ -458,6 +453,13 @@ def process_helper(channel_number, directory, records, NBBtemp=None, IBBtemp=No
iUNCBTO[i], iUNCBTP[i]))
mlt.close()
# Read number of ranges
NRNGS = int(str.strip(os.environ.get('NRNGS')))
# FIXME: Do something in the future if there is more then 1 range
if NRNGS >= 2:
logger.error("Add more code :)")
WN = str.strip(os.environ.get(f'C{channel_number}_WN'))
# Lower bound of spectral range
WNLO = int(str.split(WN)[0])
......
......@@ -26,24 +26,6 @@ logger = logging.getLogger(__name__)
# NBBtemp=317.925
IBBtemp = 273.182
# used in processing pool
def process_record(record, directory, output_path, no_spectral, times, sceneMirrorPositions):
logger.info('Record {0} scene mirror position = {1}'.format(record, sceneMirrorPositions[record - 1]))
# Returns wavenumbers, obs_ice, pred_ice, obs_3body, pred_3body
logger.debug('Running bbcal')
lw,sw = bbcal.process(directory, record, IBBtemp=IBBtemp, output_path=output_path)
IBB = []
NBB = []
if sceneMirrorPositions[record - 1] == 83:
NBB = (record, times[record - 1], lw[5], sw[5])
if no_spectral is False:
make_NBB_plot(str(c1_file), lw, sw, record, output_path)
elif sceneMirrorPositions[record - 1] == 84:
IBB = (record, times[record - 1], lw[6], sw[6])
if no_spectral is False:
make_IBB_plot(str(c1_file), lw, sw, record, output_path)
return NBB,IBB
def to_int(arg):
try:
......@@ -528,10 +510,17 @@ def make_IBB_plot(c1_file, lw, sw, records, output_path):
def main(directory, output_dir=None, record_range=None, excluded_records=None, separate=None, no_spectral=None):
if output_dir is None:
logger.error('output_dir is None in main')
c1_file = os.path.join(directory, ( os.path.basename(directory)[2:8] + "C1.RNC" ))
c2_file = os.path.join(directory, ( os.path.basename(directory)[2:8] + "C2.RNC" ))
if not os.path.isfile(c1_file) or not os.path.isfile(c2_file):
logger.error(f"Invalid input: {directory} -- There must be a YYMMDDC1.RNC and YYMMDDC2.RNC in the same directory")
exit(1)
if output_dir is not None:
output_path = os.path.realpath(output_dir)
else:
output_path = directory
if not os.path.isdir(output_path):
logger.info('Creating directory: {0}'.format(output_path))
os.mkdir(output_path)
......@@ -596,16 +585,20 @@ def main(directory, output_dir=None, record_range=None, excluded_records=None, s
IBB = []
if separate is True:
from multiprocessing import Pool
with Pool(processes = int(str.strip(os.environ.get('NRNGS')))) as p:
from functools import partial
worker = partial(process_record, directory=directory, output_path=output_path, no_spectral=no_spectral, times=times, sceneMirrorPositions=sceneMirrorPositions)
data = p.map(worker, records)
for d in data:
if len(d[0]) > 0:
NBB.append(d[0])
if len(d[1]) > 0:
IBB.append(d[1])
for record in records:
logger.info('Record {0} scene mirror position = {1}'.format(record, sceneMirrorPositions[record - 1]))
# Returns wavenumbers, obs_ice, pred_ice, obs_3body, pred_3body
logger.debug('Running bbcal')
lw,sw = bbcal.process(str(c1_file), str(c2_file), record, IBBtemp=IBBtemp, output_path=output_path)
if sceneMirrorPositions[record - 1] == 83:
NBB.append((record, times[record - 1], lw[5], sw[5]))
if no_spectral is False:
make_NBB_plot(str(c1_file), lw, sw, record, output_path)
elif sceneMirrorPositions[record - 1] == 84:
IBB.append((record, times[record - 1], lw[6], sw[6]))
if no_spectral is False:
make_IBB_plot(str(c1_file), lw, sw, record, output_path)
if len(NBB) > 0:
with open(os.path.join(output_path, 'NBB.avg'), 'w') as file:
......@@ -625,7 +618,7 @@ def main(directory, output_dir=None, record_range=None, excluded_records=None, s
logger.info('Record {0} scene mirror position = {1}'.format(records[-1],
sceneMirrorPositions[records[-1] - 1]))
# Returns wavenumbers, obs_ice, pred_ice, obs_3body, pred_3body
lw,sw = bbcal.process(directory, records, IBBtemp=IBBtemp, output_path=output_path)
lw,sw = bbcal.process(str(c1_file), str(c2_file), records, IBBtemp=IBBtemp, output_path=output_path)
make_NBB_plot(str(c1_file), lw, sw, records, output_path)
make_IBB_plot(str(c1_file), lw, sw, records, output_path)
......@@ -664,7 +657,7 @@ if __name__ == '__main__':
parser.add_argument("input", help="Channel 1 input filename in HHMMSSC1.RNC format. Realtive or absolute path")
parser.add_argument("-o", '--output-dir',
help="Output file directory. It will be created if it does not exist. Defaults to input directory. Relative or absolute path")
help="Output file directory. It will be created if it does not exist. Defaults to current directory. Relative or absolute path")
parser.add_argument("-r", '--record-range',
help="Record range. Either a number or a string of two numbers separated by a space. Defaults to all records")
parser.add_argument('-e', '--excluded-records',
......@@ -695,6 +688,6 @@ if __name__ == '__main__':
exit(1)
for d in ae_dirs:
main(d, output_dir=args.input if args.output_dir is None else args.output_dir, record_range=args.record_range,
main(d, output_dir=args.output_dir, record_range=args.record_range,
excluded_records=args.excluded_records,
separate=args.separate, no_spectral=args.no_spectral)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment