Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in jwst-data-products-part2-solutions datamodels.MultiSpecModel() method #114

Open
bucweat opened this issue May 11, 2022 · 1 comment

Comments

@bucweat
Copy link

bucweat commented May 11, 2022

Thanks for putting these webinars together...you don't really know how much work and complexity goes into space telescope images you just see the final image...just poking through the notebooks here just starts to touch the tip of the iceberg.

Anyway, in the 4.2.-Spectroscopy section of jwst-data-products-part2-solutions, I'm getting an error on the following cell:

# Open the same file using a MultiSpecModel (use: spec)
spec = datamodels.MultiSpecModel(wfss_x1d_file[1])

It has been almost a year since the webbinar, and the version numbers of the modules I have loaded are all a fair amount higher. Maybe the data schemas have change and so this is OBE, but figured I'd point it out in case someone else runs into this problem.

The trace is

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [36], in <cell line: 2>()
      1 # Open the same file using a MultiSpecModel (use: spec)
----> 2 spec = datamodels.MultiSpecModel(wfss_x1d_file[1])

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/jwst/datamodels/multispec.py:59, in MultiSpecModel.__init__(self, init, **kwargs)
     56     self.spec[0].spec_table = init.spec_table
     57     return
---> 59 super(MultiSpecModel, self).__init__(init=init, **kwargs)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/model_base.py:244, in DataModel.__init__(self, init, schema, memmap, pass_invalid_values, strict_validation, validate_on_assignment, cast_fits_arrays, validate_arrays, ignore_missing_extensions, **kwargs)
    241         init_fitsopen = init
    243     hdulist = fits.open(init_fitsopen, memmap=memmap)
--> 244     asdffile = fits_support.from_fits(
    245         hdulist, self._schema, self._ctx, **kwargs
    246     )
    247     self._file_references.append(_FileReference(hdulist))
    249 elif file_type == "asdf":

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:628, in from_fits(hdulist, schema, context, skip_fits_update, **kwargs)
    623 # Determine whether skipping the FITS loading can be done.
    624 skip_fits_update = _verify_skip_fits_update(
    625     skip_fits_update, hdulist, ff, context
    626 )
--> 628 known_keywords, known_datas = _load_from_schema(
    629     hdulist, schema, ff.tree, context, skip_fits_update=skip_fits_update
    630 )
    631 if not skip_fits_update:
    632     _load_extra_fits(hdulist, known_keywords, known_datas, ff.tree)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:548, in _load_from_schema(hdulist, schema, tree, context, skip_fits_update)
    542                 recurse(schema['items'],
    543                         path + [i],
    544                         combiner,
    545                         {'hdu_index': i})
    546             return True
--> 548 mschema.walk_schema(schema, callback)
    549 return known_keywords, known_datas

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/schema.py:149, in walk_schema(schema, callback, ctx)
    147 if ctx is None:
    148     ctx = {}
--> 149 recurse(schema, [], None, ctx)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/schema.py:137, in walk_schema.<locals>.recurse(schema, path, combiner, ctx)
    135 if schema.get('type') == 'object':
    136     for key, val in schema.get('properties', {}).items():
--> 137         recurse(val, path + [key], combiner, ctx)
    139 if schema.get('type') == 'array':
    140     items = schema.get('items', {})

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/schema.py:124, in walk_schema.<locals>.recurse(schema, path, combiner, ctx)
    123 def recurse(schema, path, combiner, ctx):
--> 124     if callback(schema, path, combiner, ctx, recurse):
    125         return
    127     for c in ['allOf', 'not']:

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:542, in _load_from_schema.<locals>.callback(schema, path, combiner, ctx, recurse)
    540 if has_fits_hdu:
    541     for i in range(max_extver):
--> 542         recurse(schema['items'],
    543                 path + [i],
    544                 combiner,
    545                 {'hdu_index': i})
    546     return True

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/schema.py:137, in walk_schema.<locals>.recurse(schema, path, combiner, ctx)
    135 if schema.get('type') == 'object':
    136     for key, val in schema.get('properties', {}).items():
--> 137         recurse(val, path + [key], combiner, ctx)
    139 if schema.get('type') == 'array':
    140     items = schema.get('items', {})

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/schema.py:124, in walk_schema.<locals>.recurse(schema, path, combiner, ctx)
    123 def recurse(schema, path, combiner, ctx):
--> 124     if callback(schema, path, combiner, ctx, recurse):
    125         return
    127     for c in ['allOf', 'not']:

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:526, in _load_from_schema.<locals>.callback(schema, path, combiner, ctx, recurse)
    522             properties.put_value(path, result, tree)
    524 elif 'fits_hdu' in schema and (
    525         'max_ndim' in schema or 'ndim' in schema or 'datatype' in schema):
--> 526     result = _fits_array_loader(
    527         hdulist, schema, ctx.get('hdu_index'), known_datas, context)
    529     if result is None and context._validate_on_assignment:
    530         validate.value_change(path, result, schema, context)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:478, in _fits_array_loader(hdulist, schema, hdu_index, known_datas, context)
    475     return None
    477 known_datas.add(hdu)
--> 478 return from_fits_hdu(hdu, schema, context._cast_fits_arrays)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/fits_support.py:667, in from_fits_hdu(hdu, schema, cast_arrays)
    664     listeners = None
    666 # Cast array to type mentioned in schema
--> 667 data = properties._cast(data, schema)
    669 # Casting a table loses the column listeners, so restore them
    670 if listeners is not None:

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/properties.py:84, in _cast(val, schema)
     81             t['shape'] = shape
     83 dtype = ndarray.asdf_datatype_to_numpy_dtype(schema['datatype'])
---> 84 val = util.gentle_asarray(val, dtype)
     86 if dtype.fields is not None:
     87     val = _as_fitsrec(val)

File ~/miniconda3/envs/jwst/lib/python3.10/site-packages/stdatamodels/util.py:59, in gentle_asarray(a, dtype)
     57     out_dtype.names = in_dtype.names
     58 else:
---> 59     raise ValueError(
     60         "Column names don't match schema. "
     61         "Schema has {0}. Data has {1}".format(
     62             str(out_names.difference(in_names)),
     63             str(in_names.difference(out_names))))
     65 new_dtype = []
     66 for i in range(len(out_dtype.fields)):

ValueError: Column names don't match schema. Schema has {'bkgd_var_flat', 'flux_var_rnoise', 'flux_var_poisson', 'sb_var_flat', 'bkgd_var_rnoise', 'sb_var_rnoise', 'bkgd_error', 'flux_var_flat', 'flux_error', 'bkgd_var_poisson', 'sb_var_poisson'}. Data has {'berror', 'error'}
@camipacifici
Copy link
Collaborator

Apologies for not addressing this months ago!
The notebooks have been all updated (version in main) around July to comply with the newest version of the JWST calibration pipeline. I will test on my side too, but in principle the version of that notebook in main should work. Please refer to the instructions here: https://github.com/spacetelescope/jwebbinar_prep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants