Skip to content
Snippets Groups Projects
Commit db26d3fc authored by Stefano Serafin's avatar Stefano Serafin
Browse files

added small module to decode observations from sets of csv files

parent 0085e8f3
Branches
Tags
No related merge requests found
#!/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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment