Plotting diurnal variation of temperature and pressure

8 views (last 30 days)
I have some .csv files containing the temperature and pressure from local time 00.00 to local tiime 23.59. I want to plot the diurnal variation of these parameters but I want to take the avearge of them for 5-10 days to cover the possible gaps in measurement. I am attaching a few such .csv files here.
Can anyone tell me how to do this?

Accepted Answer

Cris LaPierre
Cris LaPierre on 30 Dec 2021
Edited: Cris LaPierre on 30 Dec 2021
Interesting data. It makes it a litte more challenging, but not impossible.
First, I would look into using a datastore to load the data. See our Importing Multiple Data Files video from our Practical Data Science with MATLAB series on Coursera for how to set this up.
Your day cycles are based on the LMST variable. Since this is Local Mean Solar Time, you have to do a little special handling of this data to correctly capture the time as a duration, which allows MATLAB to correctly interpret the timing of your data. I had to import the data as a string first, then extract everything to the right of the 'M', and then turn that into a duration.
Your timing is different in each file, so you will have to use binning to average the data. However, once you have the times, it's just a matter of using groupsummary to bin and average the data. Groupsummary allows you to specify a grouping bin. Since LMST is now a duration, some of the options include second, minute, and hour. You didn't specify what time span you wanted, so I went with minute. You do have to specify which variables with numeric data you want it to average or you'll get an error (can't take average of non-numeric data types).
The output table has 1440 rows (60 mins*24 hours). You can now pick a variable and plot it. I found it helpful to create an x variable that was also a duration. If you are unfamiliar with tables, you might find the Access Data in Tables page helpful.
Below is my code. You can add additional formatting if you want, but this should be enough to get you started.
% Use a datastore to load all the csv files
fd = datastore("*.csv","TextType","string");
data1 = readall(fd);
% convert LMST to duration
data1.LMST = duration(extractAfter(data1.LMST,'M'),"InputFormat","hh:mm:ss.SSS",'Format',"hh:mm:ss.SSS")
data1 = 86471×25 table
AOBT SCLK LMST LTST UTC BMY_HORIZONTAL_WIND_SPEED BMY_VERTICAL_WIND_SPEED BMY_WIND_DIRECTION BMY_WIND_FREQUENCY BMY_WS_OPERATIONAL_FLAGS BMY_BASE_ROD_TEMP BMY_MID_ROD_TEMP BMY_TIP_ROD_TEMP BMY_AIR_TEMP_FREQUENCY BMY_AIR_TEMP_OPERATIONAL_FLAGS BPY_HORIZONTAL_WIND_SPEED BPY_VERTICAL_WIND_SPEED BPY_WIND_DIRECTION BPY_WIND_FREQUENCY BPY_WS_OPERATIONAL_FLAGS BPY_BASE_ROD_TEMP BPY_MID_ROD_TEMP BPY_TIP_ROD_TEMP BPY_AIR_TEMP_FREQUENCY BPY_AIR_TEMP_OPERATIONAL_FLAGS __________ __________ ____________ ________________ ________________________ _________________________ _______________________ __________________ __________________ ________________________ _________________ ________________ ________________ ______________________ ______________________________ _________________________ _______________________ __________________ __________________ ________________________ _________________ ________________ ________________ ______________________ ______________________________ 6.0048e+08 6.0048e+08 00:00:01.460 "00044 23:08:08" "2019-011T10:52:17.815Z" 4.612 NaN 300.47 0.1 101 202 199.36 196.12 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:06.326 "00044 23:08:12" "2019-011T10:52:22.815Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.317 NaN 315.4 0.1 100 200.19 199.1 197.09 0.1 1000 6.0048e+08 6.0048e+08 00:00:11.192 "00044 23:08:17" "2019-011T10:52:27.815Z" 3.624 NaN 300.47 0.1 101 202.09 199.34 196.14 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:16.058 "00044 23:08:22" "2019-011T10:52:32.815Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.482 NaN 320.35 0.1 100 200.08 199.07 197.11 0.1 1000 6.0048e+08 6.0048e+08 00:00:20.925 "00044 23:08:27" "2019-011T10:52:37.815Z" 4.611 NaN 300.47 0.1 101 202.14 199.35 196.11 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:25.791 "00044 23:08:32" "2019-011T10:52:42.815Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.164 NaN 320.4 0.1 100 200.12 199.14 197.16 0.1 1000 6.0048e+08 6.0048e+08 00:00:30.656 "00044 23:08:37" "2019-011T10:52:47.814Z" 3.953 NaN 305.45 0.1 101 202.1 199.36 196.12 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:35.522 "00044 23:08:42" "2019-011T10:52:52.814Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.151 NaN 315.4 0.1 100 200.2 199.09 197.08 0.1 1000 6.0048e+08 6.0048e+08 00:00:40.389 "00044 23:08:46" "2019-011T10:52:57.814Z" 5.273 NaN 300.47 0.1 101 202.09 199.33 196.18 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:45.255 "00044 23:08:51" "2019-011T10:53:02.814Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.15 NaN 315.4 0.1 100 200.08 199.04 197.08 0.1 1000 6.0048e+08 6.0048e+08 00:00:50.121 "00044 23:08:56" "2019-011T10:53:07.814Z" 5.274 NaN 300.47 0.1 101 202.07 199.34 196.21 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:00:54.987 "00044 23:09:01" "2019-011T10:53:12.814Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.162 NaN 320.4 0.1 100 200.14 199.08 197.08 0.1 1000 6.0048e+08 6.0048e+08 00:00:59.853 "00044 23:09:06" "2019-011T10:53:17.814Z" 4.944 NaN 300.47 0.1 101 202.08 199.36 196.2 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:01:04.720 "00044 23:09:11" "2019-011T10:53:22.814Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.496 NaN 325.38 0.1 100 200.07 199.05 197.14 0.1 1000 6.0048e+08 6.0048e+08 00:01:09.586 "00044 23:09:16" "2019-011T10:53:27.814Z" 4.121 NaN 300.47 0.1 101 202.09 199.32 196.23 0.1 1000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.0048e+08 6.0048e+08 00:01:14.452 "00044 23:09:21" "2019-011T10:53:32.814Z" NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.979 NaN 320.35 0.1 100 200.05 199.1 197.14 0.1 1000
% average the data into 1-minute intervals of variables (columns) 6-25.
minAvg = groupsummary(data1,"LMST","minute","mean",6:25)
minAvg = 1440×22 table
minute_LMST GroupCount mean_BMY_HORIZONTAL_WIND_SPEED mean_BMY_VERTICAL_WIND_SPEED mean_BMY_WIND_DIRECTION mean_BMY_WIND_FREQUENCY mean_BMY_WS_OPERATIONAL_FLAGS mean_BMY_BASE_ROD_TEMP mean_BMY_MID_ROD_TEMP mean_BMY_TIP_ROD_TEMP mean_BMY_AIR_TEMP_FREQUENCY mean_BMY_AIR_TEMP_OPERATIONAL_FLAGS mean_BPY_HORIZONTAL_WIND_SPEED mean_BPY_VERTICAL_WIND_SPEED mean_BPY_WIND_DIRECTION mean_BPY_WIND_FREQUENCY mean_BPY_WS_OPERATIONAL_FLAGS mean_BPY_BASE_ROD_TEMP mean_BPY_MID_ROD_TEMP mean_BPY_TIP_ROD_TEMP mean_BPY_AIR_TEMP_FREQUENCY mean_BPY_AIR_TEMP_OPERATIONAL_FLAGS ____________________________ __________ ______________________________ ____________________________ _______________________ _______________________ _____________________________ ______________________ _____________________ _____________________ ___________________________ ___________________________________ ______________________________ ____________________________ _______________________ _______________________ _____________________________ ______________________ _____________________ _____________________ ___________________________ ___________________________________ [00:00:00.000, 00:01:00.000) 63 3.7485 NaN 300.44 0.1 101 202.23 199.4 195.48 0.1 1000 2.1564 NaN 319.82 0.1 100 200.52 199.41 196.98 0.1 1000 [00:01:00.000, 00:02:00.000) 61 3.5774 NaN 301.12 0.1 101 202.2 199.4 195.46 0.1 1000 2.2539 NaN 317.74 0.1 100 200.5 199.4 196.98 0.1 1000 [00:02:00.000, 00:03:00.000) 61 3.7848 NaN 300.03 0.1 101 202.13 199.32 195.42 0.1 1000 2.2083 NaN 315.99 0.1 100 200.44 199.33 196.95 0.1 1000 [00:03:00.000, 00:04:00.000) 62 3.9228 NaN 299.35 0.1 101 202.15 199.35 195.44 0.1 1000 2.2017 NaN 319.46 0.1 100 200.41 199.31 196.96 0.1 1000 [00:04:00.000, 00:05:00.000) 62 3.9234 NaN 299.77 0.1 101 202.09 199.3 195.32 0.1 1000 2.2984 NaN 311.92 0.1 100 200.33 199.24 196.86 0.1 1000 [00:05:00.000, 00:06:00.000) 61 4.0185 NaN 298.36 0.1 101 202.08 199.26 195.24 0.1 1000 2.177 NaN 311.96 0.1 100 200.24 199.15 196.76 0.1 1000 [00:06:00.000, 00:07:00.000) 63 4.0029 NaN 298.2 0.1 101 202.01 199.16 195.13 0.1 1000 2.2227 NaN 310.6 0.1 100 200.21 199.11 196.69 0.1 1000 [00:07:00.000, 00:08:00.000) 61 4.0374 NaN 298.41 0.1 101 202 199.13 195.05 0.1 1000 2.1808 NaN 312.06 0.1 100 200.2 199.09 196.64 0.1 1000 [00:08:00.000, 00:09:00.000) 61 3.9425 NaN 298.67 0.1 101 201.95 199.05 194.87 0.1 1000 2.3024 NaN 307.26 0.1 100 200.11 199.01 196.52 0.1 1000 [00:09:00.000, 00:10:00.000) 62 3.8869 NaN 298 0.1 101 201.93 199.06 194.9 0.1 1000 2.1853 NaN 307.29 0.1 100 200.12 199 196.51 0.1 1000 [00:10:00.000, 00:11:00.000) 62 3.7788 NaN 298.26 0.1 101 201.83 199 194.78 0.1 1000 2.2095 NaN 307.52 0.1 100 200.01 198.9 196.39 0.1 1000 [00:11:00.000, 00:12:00.000) 61 3.8721 NaN 298.91 0.1 101 201.81 198.98 194.83 0.1 1000 2.2203 NaN 305.65 0.1 100 199.95 198.84 196.34 0.1 1000 [00:12:00.000, 00:13:00.000) 62 3.8293 NaN 299.9 0.1 101 201.75 198.93 194.83 0.1 1000 2.205 NaN 306.7 0.1 100 199.94 198.81 196.35 0.1 1000 [00:13:00.000, 00:14:00.000) 62 4.0356 NaN 299.38 0.1 101 201.77 198.94 194.86 0.1 1000 2.2491 NaN 301.68 0.1 100 199.94 198.81 196.35 0.1 1000 [00:14:00.000, 00:15:00.000) 61 4.0792 NaN 299.21 0.1 101 201.68 198.84 194.73 0.1 1000 2.2245 NaN 305.35 0.1 100 199.85 198.73 196.28 0.1 1000 [00:15:00.000, 00:16:00.000) 61 4.2118 NaN 299.9 0.1 101 201.69 198.87 194.82 0.1 1000 2.3558 NaN 301.51 0.1 100 199.82 198.71 196.3 0.1 1000
% Plot the first variable, BMY_HORIZONTAL_WIND_SPEED
t = minutes(0:height(minAvg)-1);
plot(t,minAvg.mean_BMY_HORIZONTAL_WIND_SPEED)
xtickformat("h")

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!