diff --git a/observations.py b/observations.py new file mode 100644 index 0000000000000000000000000000000000000000..ea45957db8a9351d07ad5a60f5ea8a4e9cd6cd03 --- /dev/null +++ b/observations.py @@ -0,0 +1,44 @@ +#!/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')