Skip to content
Snippets Groups Projects
Select Git revision
  • db26d3fc5a70db42ee7b2e44366dc59a59f7b002
  • master default protected
  • new_cbl_models
  • 0.99
4 results

observations.py

Blame
  • observations.py 1.26 KiB
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    import numpy as np
    from matplotlib import pyplot as p
    import pickle
    import os
    import glob
    import pandas as pd
    
    def decode_observations(observation_files):
    
        # Read set of CSV files into a pandas dataframe.
        # Based on:
        # https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe    
    
        # Create a list of dataframes, one per file
        all_files = glob.glob(observation_files)
        li = []
        for filename in all_files:
            df = pd.read_csv(filename, index_col=None, header=0)
            li.append(df)
        nassim = len(li)
    
        # Browse through all dataframes and get the maximum
        # number of observation records
        nobs = 0
        for i in li:
            nobs = max(i.shape[0],nobs)
    
        # Create observation and coordinate arrays
        observations = np.zeros((nassim,nobs))+np.nan
        ocoords = np.zeros((nassim,nobs))+np.nan
    
        # Reading from the dataframes and
        # populate observation and coordinate arrays
        for i in range(nassim):
            ocoords[i,:] = li[i].get("z (m)")
            observations[i,:] = li[i].get("theta (K)")
    
        return observations,ocoords
    
    if __name__ == '__main__':
    
        observations,ocoords = decode_observations('./LES_data/Theta/*csv')