def lookup_trim(tank, ull, trim_index): log.info('Starting lookup_trim') # Called by calc trim corr # Takes input as tank no /15, ullage, trim, trim index. # Only deals with 1 trim index, can take mid ullage. # Negative trim is by the head. ull_high = [] ull_low = 0 corr_high = [] corr_low = 0 # print('func ~ lookup_trim') log.debug(('Working with a trim_index of ', trim_index)) log.debug(('Working with a ullage of ', ull)) file = 'tables/trim' + str(tank) + '.csv' with open(file) as trim_table: table = csv.reader(trim_table) for row in table: index = float(row[0]) # Does the current ullage match the ullage in table. if index == ull: log.debug('Ullage is exact match to index collumn') # Exact ullage match with first column. # print('Ullage is an exact match.') x = [row[trim_index]] x = float(x[0]) return x else: log.debug('Ullage is not an exact match') # Looking for bounding ullages. if index < ull: ull_low = index corr_low = row[trim_index] log.debug((ull_low, ' < ull_low')) log.debug((corr_low, ' < corr_low')) else: # Higher values than the ullage, adds to list, only takes first value. ull_high.append(index) corr_high.append(row[trim_index]) log.debug((ull_high, ' < ull_high')) log.debug((corr_high, ' , < corr_high')) corr_low = float(corr_low) corr_high = float(corr_high[0]) log.debug('Interpolating between corr_high & corr_low') x = interpolate(ull_low, ull_high[0], corr_low, corr_high, ull) log.debug(('Interpolated value > ', x)) return x
def calc_trim_corr(tank, ull, trm, trim_index): log.info('Starting calc_trim_corr') # Called by __init__ # Rx trim index 1 or 2 figures. 1 is exact match with trim value. if len(trim_index) == 1: log.info('Trim is exact match to trim index: Only need to lookup temp_1_t collumn') trim_index = int(trim_index[0]) corr = lookup_trim(tank, ull, trim_index) return corr elif len(trim_index) > 1: log.info('Trim is not an exact match to trim : Need to interpolate between') trim_low = trim_index[0] trim_index_low = trim_index[1] trim_high = trim_index[2] trim_index_high = trim_index[3] corr_low = lookup_trim(tank, ull, trim_index_low) corr_high = lookup_trim(tank, ull, trim_index_high) log.debug(('lower index is > %s < high index is > %s <' % (trim_index_low, trim_index_high))) log.debug(('lower trim is > %s < higher trim is > %s <' % (trim_low, trim_high))) log.debug(('lower corr is > %s < high corr is > %s <' % (corr_low, corr_high))) corr = float(interpolate(trim_low, trim_high, corr_low, corr_high, trm)) log.info(('Trim correction calculated at > ', corr)) return corr