Beispiel #1
0
    def _create_guess_datasets(self):
        """
        Creates the h5 group, guess dataset, corresponding spectroscopic datasets and also
        links the guess dataset to the spectroscopic datasets.
        """
        self.h5_results_grp = create_results_group(
            self.h5_main,
            self.process_name,
            h5_parent_group=self._h5_target_group)
        write_simple_attrs(self.h5_results_grp, self.parms_dict)

        # If writing to a new HDF5 file:
        # Add back the data_type attribute - still being used in the visualizer
        if self.h5_results_grp.file != self.h5_main.file:
            write_simple_attrs(
                self.h5_results_grp.file,
                {'data_type': get_attr(self.h5_main.file, 'data_type')})

        ret_vals = write_reduced_anc_dsets(self.h5_results_grp,
                                           self.h5_main.h5_spec_inds,
                                           self.h5_main.h5_spec_vals,
                                           self._fit_dim_name,
                                           verbose=self.verbose)

        h5_sho_inds, h5_sho_vals = ret_vals

        self._h5_guess = write_main_dataset(
            self.h5_results_grp, (self.h5_main.shape[0], self.num_udvs_steps),
            'Guess',
            'SHO',
            'compound',
            None,
            None,
            h5_pos_inds=self.h5_main.h5_pos_inds,
            h5_pos_vals=self.h5_main.h5_pos_vals,
            h5_spec_inds=h5_sho_inds,
            h5_spec_vals=h5_sho_vals,
            chunks=(1, self.num_udvs_steps),
            dtype=sho32,
            main_dset_attrs=self.parms_dict,
            verbose=self.verbose)

        # Does not make sense to propagate region refs - nobody uses them
        # copy_region_refs(self.h5_main, self._h5_guess)

        self._h5_guess.file.flush()

        if self.verbose and self.mpi_rank == 0:
            print('Finished creating Guess dataset')
Beispiel #2
0
    def _create_guess_datasets(self):
        """
        Creates the h5 group, guess dataset, corresponding spectroscopic datasets and also
        links the guess dataset to the spectroscopic datasets.
        """
        self.h5_results_grp = create_results_group(self.h5_main, self.process_name)
        write_simple_attrs(self.h5_results_grp, self.parms_dict)

        h5_sho_inds, h5_sho_vals = write_reduced_anc_dsets(self.h5_results_grp, self.h5_main.h5_spec_inds,
                                                            self.h5_main.h5_spec_vals, self._fit_dim_name)

        self._h5_guess = write_main_dataset(self.h5_results_grp, (self.h5_main.shape[0], self.num_udvs_steps), 'Guess', 'SHO',
                                           'compound', None, None, h5_pos_inds=self.h5_main.h5_pos_inds,
                                           h5_pos_vals=self.h5_main.h5_pos_vals, h5_spec_inds=h5_sho_inds,
                                           h5_spec_vals=h5_sho_vals, chunks=(1, self.num_udvs_steps), dtype=sho32,
                                           main_dset_attrs=self.parms_dict, verbose=self.verbose)
        
        copy_region_refs(self.h5_main, self._h5_guess)
        
        self._h5_guess.file.flush()
        
        if self.verbose and self.mpi_rank == 0:
            print('Finished creating Guess dataset')
Beispiel #3
0
    def _setup_h5(self, data_gen_parms):
        """
        Setups up the hdf5 file structure before doing the actual generation

        Parameters
        ----------
        data_gen_parms : dict
            Dictionary containing the parameters to write to the Measurement Group as attributes

        Returns
        -------

        """
        '''
        Build the group structure down to the channel group
        '''
        # Set up the basic group structure
        root_parms = dict()
        root_parms['translator'] = 'FAKEBEPS'
        root_parms['data_type'] = data_gen_parms['data_type']

        # Write the file
        self.h5_f = h5py.File(self.h5_path, 'w')
        write_simple_attrs(self.h5_f, root_parms)

        meas_grp = create_indexed_group(self.h5_f, 'Measurement')
        chan_grp = create_indexed_group(meas_grp, 'Channel')

        write_simple_attrs(meas_grp, data_gen_parms)

        # Create the Position and Spectroscopic datasets for the Raw Data
        h5_pos_dims, h5_spec_dims = self._build_ancillary_datasets()

        h5_raw_data = write_main_dataset(chan_grp,
                                         (self.n_pixels, self.n_spec_bins),
                                         'Raw_Data',
                                         'Deflection',
                                         'Volts',
                                         h5_pos_dims,
                                         h5_spec_dims,
                                         slow_to_fast=True,
                                         dtype=np.complex64,
                                         verbose=True)
        '''
        Build the SHO Group
        '''
        sho_grp = create_results_group(h5_raw_data, 'SHO_Fit')

        # Build the Spectroscopic datasets for the SHO Guess and Fit
        h5_sho_spec_inds, h5_sho_spec_vals = write_reduced_anc_dsets(
            sho_grp,
            h5_raw_data.h5_spec_inds,
            h5_raw_data.h5_spec_vals,
            'Frequency',
            is_spec=True)

        h5_sho_fit = write_main_dataset(
            sho_grp, (self.n_pixels, int(self.n_spec_bins // self.n_bins)),
            'Fit',
            'SHO Parameters',
            'a.u.',
            None,
            None,
            h5_pos_inds=h5_raw_data.h5_pos_inds,
            h5_pos_vals=h5_raw_data.h5_pos_vals,
            h5_spec_inds=h5_sho_spec_inds,
            h5_spec_vals=h5_sho_spec_vals,
            slow_to_fast=True,
            dtype=sho32)

        h5_sho_guess = copy_dataset(h5_sho_fit, sho_grp, alias='Guess')
        '''
        Build the loop group
        '''

        loop_grp = create_results_group(h5_sho_fit, 'Loop_Fit')

        # Build the Spectroscopic datasets for the loops

        h5_loop_spec_inds, h5_loop_spec_vals = write_reduced_anc_dsets(
            loop_grp,
            h5_sho_fit.h5_spec_inds,
            h5_sho_fit.h5_spec_vals,
            'DC_Offset',
            is_spec=True)

        h5_loop_fit = write_main_dataset(loop_grp,
                                         (self.n_pixels, self.n_loops),
                                         'Fit',
                                         'Loop Fitting Parameters',
                                         'a.u.',
                                         None,
                                         None,
                                         h5_pos_inds=h5_raw_data.h5_pos_inds,
                                         h5_pos_vals=h5_raw_data.h5_pos_vals,
                                         h5_spec_inds=h5_loop_spec_inds,
                                         h5_spec_vals=h5_loop_spec_vals,
                                         slow_to_fast=True,
                                         dtype=loop_fit32)

        h5_loop_guess = copy_dataset(h5_loop_fit, loop_grp, alias='Guess')
        copy_all_region_refs(h5_loop_guess, h5_loop_fit)

        self.h5_raw = h5_raw_data
        self.h5_sho_guess = h5_sho_guess
        self.h5_sho_fit = h5_sho_fit
        self.h5_loop_guess = h5_loop_guess
        self.h5_loop_fit = h5_loop_fit
        self.h5_spec_vals = h5_raw_data.h5_spec_vals
        self.h5_spec_inds = h5_raw_data.h5_spec_inds
        self.h5_sho_spec_inds = h5_sho_fit.h5_spec_inds
        self.h5_sho_spec_vals = h5_sho_fit.h5_spec_vals
        self.h5_loop_spec_inds = h5_loop_fit.h5_spec_inds
        self.h5_loop_spec_vals = h5_loop_fit.h5_spec_vals
        self.h5_file = h5_raw_data.file

        return
Beispiel #4
0
    def _create_results_datasets(self):
        """
        Setup the Loop_Fit Group and the loop projection datasets

        """
        # First grab the spectroscopic indices and values and position indices
        # TODO: Avoid unnecessary namespace pollution
        # self._sho_spec_inds = self.h5_main.h5_spec_inds
        # self._sho_spec_vals = self.h5_main.h5_spec_vals
        # self._sho_pos_inds = self.h5_main.h5_pos_inds

        # Which row in the spec datasets is DC offset?
        self._fit_spec_index = self.h5_main.spec_dim_labels.index(
            self._fit_dim_name)

        # TODO: Unkown usage of variable. Waste either way
        # self._fit_offset_index = 1 + self._fit_spec_index

        # Calculate the number of loops per position
        cycle_start_inds = np.argwhere(
            self.h5_main.h5_spec_inds[self._fit_spec_index, :] == 0).flatten()
        tot_cycles = cycle_start_inds.size
        if self.verbose:
            print('Found {} cycles starting at indices: {}'.format(
                tot_cycles, cycle_start_inds))

        # Make the results group
        self.h5_results_grp = create_results_group(self.h5_main,
                                                   self.process_name)
        write_simple_attrs(self.h5_results_grp, self.parms_dict)

        # Write datasets
        self.h5_projected_loops = create_empty_dataset(
            self.h5_main,
            np.float32,
            'Projected_Loops',
            h5_group=self.h5_results_grp)

        h5_loop_met_spec_inds, h5_loop_met_spec_vals = write_reduced_anc_dsets(
            self.h5_results_grp,
            self.h5_main.h5_spec_inds,
            self.h5_main.h5_spec_vals,
            self._fit_dim_name,
            basename='Loop_Metrics',
            verbose=self.verbose)

        self.h5_loop_metrics = write_main_dataset(
            self.h5_results_grp, (self.h5_main.shape[0], tot_cycles),
            'Loop_Metrics',
            'Metrics',
            'compound',
            None,
            None,
            dtype=loop_metrics32,
            h5_pos_inds=self.h5_main.h5_pos_inds,
            h5_pos_vals=self.h5_main.h5_pos_vals,
            h5_spec_inds=h5_loop_met_spec_inds,
            h5_spec_vals=h5_loop_met_spec_vals)

        # Copy region reference:
        # copy_region_refs(self.h5_main, self.h5_projected_loops)
        # copy_region_refs(self.h5_main, self.h5_loop_metrics)

        self.h5_main.file.flush()
        self._met_spec_inds = self.h5_loop_metrics.h5_spec_inds

        if self.verbose and self.mpi_rank == 0:
            print('Finished creating Guess dataset')