Commit 1b1b6d2d authored by Marco Kurzynski's avatar Marco Kurzynski
Browse files

WIP changing to directory

parent 1e57ffb3
......@@ -48,12 +48,17 @@ def interpolate(xin, yin, xout):
return val
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(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_helper(channel_number, channel_file, records, NBBtemp=None, IBBtemp=None, abb_breakout=None, output_path=''):
def process_helper(channel_number, directory, 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
......@@ -68,7 +73,7 @@ def process_helper(channel_number, channel_file, records, NBBtemp=None, IBBtemp
try:
LOGFILE = str.strip(os.environ.get(f'C{channel_number}_LOGFILE'))
except TypeError:
LOGFILE = f'bbcal3p_{os.path.basename(channel_file)[:6]}.lo{channel_number}'
LOGFILE = f'bbcal3p_{os.path.basename(directory)[2:]}.lo{channel_number}'
LOGFILE = os.path.join(output_path, LOGFILE)
# Open logfile
......@@ -162,7 +167,7 @@ def process_helper(channel_number, channel_file, records, NBBtemp=None, IBBtemp
try:
MLTFILE = str.strip(os.environ.get(f'C{channel_number}_MLTFILE'))
except TypeError:
MLTFILE = f'bbcal_{os.path.basename(channel_file)[:6]}.mlt{channel_number}'
MLTFILE = f'bbcal_{os.path.basename(directory)[2:]}.mlt{channel_number}'
MLTFILE = os.path.join(output_path, MLTFILE)
# Write MLT file to Log file
......@@ -172,7 +177,7 @@ def process_helper(channel_number, channel_file, records, NBBtemp=None, IBBtemp
try:
SUMFILE = str.strip(os.environ.get(f'C{channel_number}_SUMFILE'))
except TypeError:
SUMFILE = f'bbcal_{os.path.basename(channel_file)[:6]}.sum{channel_number}'
SUMFILE = f'bbcal_{os.path.basename(directory)[2:]}.sum{channel_number}'
SUMFILE = os.path.join(output_path, SUMFILE)
lf.write("TEXT OUTPUT (SUMMARY) file: %s\n" % SUMFILE)
......
......@@ -27,11 +27,11 @@ logger = logging.getLogger(__name__)
IBBtemp = 273.182
# used in processing pool
def process_record(record, c1_file, c2_file, output_path, no_spectral, times, sceneMirrorPositions):
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(str(c1_file), str(c2_file), record, IBBtemp=IBBtemp, output_path=output_path)
lw,sw = bbcal.process(directory, record, IBBtemp=IBBtemp, output_path=output_path)
IBB = []
NBB = []
......@@ -528,17 +528,10 @@ 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):
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")
if output_dir is None:
logger.error('output_dir is None in main')
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)
......@@ -606,7 +599,7 @@ def main(directory, output_dir=None, record_range=None, excluded_records=None, s
from multiprocessing import Pool
with Pool(processes = int(str.strip(os.environ.get('NRNGS')))) as p:
from functools import partial
worker = partial(process_record, c1_file=c1_file, c2_file=c2_file, output_path=output_path, no_spectral=no_spectral, times=times, sceneMirrorPositions=sceneMirrorPositions)
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:
......@@ -632,7 +625,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(str(c1_file), str(c2_file), records, IBBtemp=IBBtemp, output_path=output_path)
lw,sw = bbcal.process(directory, 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)
......@@ -671,7 +664,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 current directory. Relative or absolute path")
help="Output file directory. It will be created if it does not exist. Defaults to input 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',
......@@ -702,6 +695,6 @@ if __name__ == '__main__':
exit(1)
for d in ae_dirs:
main(d, output_dir=args.output_dir, record_range=args.record_range,
main(d, output_dir=args.input if args.output_dir is None else 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