def do_stage(self, image: NRESObservationFrame): if image.profile is None: logger.error('Profile missing. Rejecting image.', image=image) return None image.add_or_update( ArrayData(np.zeros_like(image.data, dtype=float), name='WEIGHTS')) trace_ids = np.arange(1, image.num_traces + 1) for trace_id in trace_ids: yx = get_trace_region(np.isclose(image.traces, trace_id)) image.weights[yx] = self.weights(image.profile[yx], image.uncertainty[yx]**2, image.mask[yx]) return image
def test_to_fits(): data = np.ones((2, 2)) spec = Spectrum1D({ 'fiber': [0], 'order': [1], 'flux': [np.arange(10)], 'wavelength': [np.arange(10)] }) image = NRESObservationFrame([ CCDData(data=data, uncertainty=2 * data, name='SCI', meta={ 'OBJECTS': 'tung&tung&none', 'EXTNAME': '' }) ], 'foo.fits') image.add_or_update(ArrayData(3 * data, name='TRACES')) image.add_or_update(ArrayData(4 * data, name='WEIGHTS')) image.add_or_update(ArrayData(5 * data, name='BACKGROUND')) image.add_or_update(DataTable(spec.table, name='SPECTRUM')) hdulist = image.to_fits( context.Context({ 'EXTENSION_NAMES_TO_CONDENSE': ['SCI'], 'REDUCED_DATA_EXTENSION_TYPES': {}, 'fpack': True, 'LOSSLESS_EXTENSIONS': [] })) hdu_ext_names = [ hdulist[i].header.get('EXTNAME') for i in range(len(hdulist)) if hdulist[i].header.get('EXTNAME') is not None ] for name in [ 'SCI', 'BPM', 'ERR', 'TRACES', 'WEIGHTS', 'BACKGROUND', 'SPECTRUM' ]: assert name in hdu_ext_names