Skip to content
Snippets Groups Projects
Commit cea74775 authored by David Rafferty's avatar David Rafferty
Browse files

Merge branch 'fix_spec' into 'master'

Fix issues with concatenating two models

See merge request !41
parents a039e363 faaa6527
No related branches found
No related tags found
1 merge request!41Fix issues with concatenating two models
Pipeline #38802 passed
......@@ -223,23 +223,29 @@ def createTable(outlines, metaDict, colNames, colDefaults):
maxLen = len(specEntry)
except:
pass
defSpeclen = len(colDefaults[colNames.index('SpectralIndex')])
if defSpeclen > maxLen:
maxLen = defSpeclen
log.debug('Maximum number of spectral-index terms in model: {0}'.format(maxLen))
for l in specOld:
try:
# Take existing entry and fix type
if type(l) is float or type(l) is int:
specEntry = [float(l)]
specMask = [False]
else:
specEntry = [float(f) for f in l.split(';')]
specMask = [False] * len(specEntry)
except:
# No entry in table, so use default value
specEntry = colDefaults[colNames.index('SpectralIndex')]
specMask = [False] * len(specEntry)
while len(specEntry) < maxLen:
# Add masked values to any entries that are too short
specEntry.append(0.0)
specMask.append(True)
specVec.append(specEntry)
maskVec.append(specMask)
except:
specVec.append([0.0]*maxLen)
maskVec.append([True]*maxLen)
specCol = MaskedColumn(name='SpectralIndex', data=np.array(specVec, dtype=float))
specCol.mask = maskVec
specIndx = table.keys().index('SpectralIndex')
......@@ -282,12 +288,12 @@ def createTable(outlines, metaDict, colNames, colDefaults):
if hasattr(table.columns[colName], 'filled') and colDefaults[i] is not None:
fillVal = colDefaults[i]
if colName == 'SpectralIndex':
while len(fillVal) < maxLen:
fillVal.append(0.0)
log.debug("Setting default value for column '{0}' to {1}".
format(colName, fillVal))
table.columns[colName].filled(fillVal)
if colName == 'SpectralIndex':
# We cannot set the fill value to a list/array, so just use a float
fillVal = 0.0
table.columns[colName].set_fill_value(fillVal)
table.meta = metaDict
return table
......@@ -1130,12 +1136,12 @@ def convertExternalTable(table, columnMapping, fluxUnits='mJy'):
# Note: we used deepcopy() here to ensure that the original
# is not altered by later changes to fillVal
fillVal = deepcopy(allowedColumnDefaults)[colName.lower()]
if colName == 'SpectralIndex':
while len(fillVal) < 1:
fillVal.append(0.0)
log.debug("Setting default value for column '{0}' to {1}".
format(colName, fillVal))
table.columns[colName].filled(fillVal)
if colName == 'SpectralIndex':
# We cannot set the fill value to a list/array, so just use a float
fillVal = 0.0
table.columns[colName].set_fill_value(fillVal)
return table
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment