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

Implement type command #39

Open
jrleeman opened this issue Jul 16, 2020 · 0 comments
Open

Implement type command #39

jrleeman opened this issue Jul 16, 2020 · 0 comments

Comments

@jrleeman
Copy link
Contributor

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')
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

1 participant