From c48a6483d9a8c4c5985aa891b44055b65bacf5d1 Mon Sep 17 00:00:00 2001 From: Stefano Serafin <serafin@jet01.img.univie.ac.at> Date: Fri, 24 Jan 2025 10:05:17 +0100 Subject: [PATCH] added ability to sort shuffled observations before plotting --- observations.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/observations.py b/observations.py index f2f9cbe..dc8e6a7 100644 --- a/observations.py +++ b/observations.py @@ -7,6 +7,8 @@ import os import glob import pandas as pd +is_sorted = lambda a: np.all(a[:-1] <= a[1:]) + def decode_observations(observation_files): # Read set of CSV files into a pandas dataframe. @@ -98,19 +100,30 @@ if __name__ == '__main__': makeplots = True # Make plots if makeplots: + + # If observations are shuffled, sort them again + ntimes = ocoords.shape[0] + for k in range(ntimes): + if is_sorted(ocoords[k,:]): + pass + else: + indices = np.argsort(ocoords[k,:]) + ocoords[k,:] = ocoords[k,indices] + observations[k,:] = observations[k,indices] + fig, ax1 = p.subplots(1,1,constrained_layout=True) fig.set_size_inches(4,3) tint = 300 t = np.linspace(0,tint*(ocoords.shape[0]-1),ocoords.shape[0])[:,None]+np.zeros(ocoords.shape) t = t/3600. - c = ax1.scatter(t,ocoords,s=5,c=observations,vmin=290,vmax=296) - #c = ax1.pcolormesh(t,ocoords,observations,vmin=290,vmax=296) - #ax1.contour(t,ocoords,observations, - # np.linspace(290,290+0.003*2000,13), - # colors='white', - # linestyles='--', - # linewidths=0.75) + #c = ax1.scatter(t,ocoords,s=5,c=observations,vmin=290,vmax=296) + c = ax1.pcolormesh(t,ocoords,observations,vmin=290,vmax=296) + ax1.contour(t,ocoords,observations, + np.linspace(290,290+0.003*2000,13), + colors='white', + linestyles='--', + linewidths=0.75) ax1.set_ylim([0,2000]) ax1.set_ylabel(r'Height (m)') ax1.set_xlabel(r'Time (s)') -- GitLab