support gz
This commit is contained in:
		
							parent
							
								
									cd2c9e3df0
								
							
						
					
					
						commit
						7ae6f81e6d
					
				
					 2 changed files with 18 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
__version__ = '0.1.6.3'
 | 
			
		||||
__version__ = '0.1.6.4'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								labsw/io.py
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								labsw/io.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
import pandas as pd
 | 
			
		||||
import numpy as np
 | 
			
		||||
import yaml
 | 
			
		||||
import gzip
 | 
			
		||||
 | 
			
		||||
import os.path
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -11,12 +12,25 @@ def load_data_RH_logger(filepath, every=1):
 | 
			
		|||
    """
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    with open(filepath, 'r') as f:
 | 
			
		||||
        header = f.readline()
 | 
			
		||||
    # Read the header
 | 
			
		||||
    if filepath.endswith('gz'):
 | 
			
		||||
        with gzip.open(filepath, 'r') as f:
 | 
			
		||||
            header = f.readline()
 | 
			
		||||
    else:
 | 
			
		||||
        with open(filepath, 'r') as f:
 | 
			
		||||
            header = f.readline()
 | 
			
		||||
 | 
			
		||||
    # reorganize header
 | 
			
		||||
    header = header.strip('# ').rstrip('\n').split('|')
 | 
			
		||||
    header.append('X') # Empty col...
 | 
			
		||||
 | 
			
		||||
    df = pd.read_csv(filepath, sep=' ',  names=header, skiprows=1)
 | 
			
		||||
    # Load with pandas
 | 
			
		||||
    if filepath.endswith('gz'):
 | 
			
		||||
        df = pd.read_csv(filepath, sep=' ', compression='gzip', names=header, skiprows=1)
 | 
			
		||||
    else:
 | 
			
		||||
        df = pd.read_csv(filepath, sep=' ', names=header, skiprows=1)
 | 
			
		||||
 | 
			
		||||
    # Clean up
 | 
			
		||||
    df = df.drop(columns='X')
 | 
			
		||||
    df = df.drop(np.arange(1))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +38,6 @@ def load_data_RH_logger(filepath, every=1):
 | 
			
		|||
    df = df.reset_index()
 | 
			
		||||
    del df['index']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    return df.iloc[::every]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue