Skip to content

Implement type command #39

@jrleeman

Description

@jrleeman

In XLook the type command (and type_p) produced ascii output. A rough prototype is:

    def command_type(self, command):
        """
        Produce an ASCII output of the reduced data matching the XLook type format.
        """
        if not self._check_number_of_arguments(command, 6):
            return
        (_, start_row_idx, stop_row_idx,
         start_col_idx, stop_col_idx, fname) = command.split(' ')
        start_row_idx = int(start_row_idx)
        stop_row_idx = int(stop_row_idx)
        start_col_idx = int(start_col_idx)
        stop_col_idx = int(stop_col_idx) + 1
        fname = Path(fname.strip())
        
        # Trim the data to the range we want to write out - rows and columns
        write_data = [self.data[col_idx][start_row_idx: stop_row_idx] for col_idx in range(start_col_idx, stop_col_idx)]
        write_names = self.data_names[start_col_idx: stop_col_idx]
        write_units = self.data_units[start_col_idx: stop_col_idx]
        write_col_numbers = list(range(start_col_idx, stop_col_idx))
        
        n_recs = np.shape(self.data[0])[0]
        
        # Add something here to pull out cols with None and the name and unit
        
        with open(fname, 'w') as f:
            # Header
            f.write(f'number of records = {n_recs}\n     ')
            for col_num in write_col_numbers:
                f.write(f'       col {col_num:>1}')
            f.write('\n     ')
            for col_name in write_names:
                f.write(f'{col_name:>12}')
            f.write('\n     ')
            for col_unit in write_units:
                f.write(f'{col_unit:>12}')
            f.write('\n     ')
            for col_unit in write_units:
                f.write(f'{n_recs:>7} recs')
            f.write('\n')
            
            # Data
            for row_idx in list(range(len(self.data[0]))):
                #f.write(f'{row_idx:10}')
                f.write(f'{row_idx}\t')
                for col in write_col_numbers:
                    #f.write(f'{self.data[col][row_idx]:10.6}')
                    # Hack to read 
                    f.write(f'{self.data[col][row_idx]:.6}\t')
                f.write('\n')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions