kammerje / spaceKLIP

Pipeline for reducing JWST high-contrast imaging data. Published in Kammerer et al. 2022 and Carter et al. 2022.
https://ui.adsabs.harvard.edu/abs/2022SPIE12180E..3NK/abstract
MIT License
16 stars 9 forks source link

Unable to insert row because of exception in column 'MSTAR_ERR' #193

Closed strampelligiovanni closed 6 days ago

strampelligiovanni commented 2 weeks ago

TypeError Traceback (most recent call last) File ~/miniconda3/envs/spaceklip/lib/python3.11/site-packages/astropy/table/table.py:3350, in Table.insert_row(self, index, vals, mask) 3348 col = col_cls(col, copy=False) -> 3350 newcol = col.insert(index, val, axis=0) 3352 if len(newcol) != N + 1:

File ~/miniconda3/envs/spaceklip/lib/python3.11/site-packages/astropy/table/column.py:1418, in Column.insert(self, obj, values, axis) 1417 self_for_insert = _expand_string_array_for_values(self, values) -> 1418 data = np.insert(self_for_insert, obj, values, axis=axis) 1420 out = data.view(self.class)

File ~/miniconda3/envs/spaceklip/lib/python3.11/site-packages/numpy/lib/function_base.py:5513, in insert(arr, obj, values, axis) 5511 # There are some object array corner cases here, but we cannot avoid 5512 # that: -> 5513 values = array(values, copy=False, ndmin=arr.ndim, dtype=arr.dtype) 5514 if indices.ndim == 0: 5515 # broadcasting is very different here, since a[:,0,:] = ... behaves 5516 # very different from a[:,[0],:] = ...! This changes values so that 5517 # it works likes the second case. (here a[:,0:1,:])

TypeError: float() argument must be a string or a real number, not 'dict'

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last) Cell In[9], line 1 ----> 1 Analysis.extract_companions(companions.tolist(), 2 starfile, 3 mstar_err, 4 # klmode=5, 5 spectral_type=spt, 6 fitmethod='mcmc', 7 fitkernel='matern32' 8 )

File ~/spaceKLIP/spaceKLIP/analysistools.py:1406, in AnalysisTools.extract_companions(self, companions, starfile, mstar_err, spectral_type, klmode, date, use_fm_psf, highpass, fitmethod, fitkernel, subtract, inject, overwrite, subdir, kwargs) 1404 appmag_err = np.sqrt(mstar_err_temp2 + delmag_err*2) 1405 fitsfile = os.path.join(output_dir_kl, key + '-fitpsf_c%.0f' % (k + 1) + '.fits') -> 1406 tab.add_row((k + 1, 1407 fma.raw_RA_offset.bestfit pxsc_arcsec, # arcsec 1408 fma.raw_RA_offset.error pxsc_arcsec, # arcsec 1409 fma.raw_Dec_offset.bestfit pxsc_arcsec, # arcsec 1410 fma.raw_Dec_offset.error pxsc_arcsec, # arcsec 1411 flux_jy, 1412 flux_jy_err, 1413 flux_si, 1414 flux_si_err, 1415 flux_si_alt, 1416 flux_si_alt_err, 1417 fma.raw_flux.bestfit guess_flux, 1418 fma.raw_flux.error * guess_flux, 1419 delmag, # mag 1420 delmag_err, # mag 1421 appmag, # mag 1422 appmag_err, # mag 1423 mstar[filt], # mag 1424 mstar_err, # mag 1425 np.nan, 1426 np.nan, 1427 scale_factor_avg, 1428 tp_comsubst, 1429 fitsfile)) 1431 # Write the FM PSF to a file for future plotting. 1432 ut.write_fitpsf_images(fma, fitsfile, tab[-1])

File ~/miniconda3/envs/spaceklip/lib/python3.11/site-packages/astropy/table/table.py:3217, in Table.add_row(self, vals, mask) 3166 def add_row(self, vals=None, mask=None): 3167 """Add a new row to the end of the table. 3168 3169 The vals argument can be: (...) 3215 3 6 9 3216 """ -> 3217 self.insert_row(len(self), vals, mask)

File ~/miniconda3/envs/spaceklip/lib/python3.11/site-packages/astropy/table/table.py:3372, in Table.insert_row(self, index, vals, mask) 3369 columns[name] = newcol 3371 except Exception as err: -> 3372 raise ValueError( 3373 f"Unable to insert row because of exception in column '{name}':\n{err}" 3374 ) from err 3376 for table_index in self.indices: 3377 table_index.insert_row(index, vals, self.columns.values())

ValueError: Unable to insert row because of exception in column 'MSTAR_ERR': float() argument must be a string or a real number, not 'dict'

kammerje commented 2 weeks ago

Can you try setting mstar_err=0. (or any other float) in AnalysisTools.extract_companions? It seems like you have entered a dictionary there.

strampelligiovanni commented 1 week ago

So I think I solved this problem,

In the extract_companions you allow for a dictionary to be parsed, and define mstar_err_temp as:

 if isinstance(mstar_err, dict):
      mstar_err_temp = mstar_err[filt]
 else:
      mstar_err_temp = mstar_err

but later on in the the tab.add_row, mstar_err is parsed instead of mstar_err_temp (In both istances). I changed mstar_err with mstar_err_temp and now it works.