Function for finding duration where wave height <3m where time is between 5:00am and 6:00PM - excel

I am trying to find duration for time where wave height is under 3m and time period is between 5:00am and 6:00pm. Trying to find this duration for a month of tidal data.
I have raw data for wave height and timestamps when it is high and low.
eg.
Timestamp Wave_Height
1/01/2022 3:16 0.68
1/01/2022 9:37 6.62
1/01/2022 16:14 1.07
1/01/2022 21:54 5.37
2/01/2022 4:06 0.59
etc…
So far I have got linear interpolation to find points where wave height=3. I am struggling to get a function to find the durations for my limits on time.
Included a picture to explain
Graph of wave data over time
The timestamps occur over different days in the month so difference between times must consider the changed dates in some cases(see rev 2 errors ####### where errors occur for changing of dates)
rev 2 error

The following should work. I have added some columns to avoid complicated formulas.
interpolate when the wave_height = 3 (column G)
add column H which is True when wave_height increases and False if it decreases (at the time in column G):
so cell H6 = F7<3 gives TRUE
add column E to limit the time window to 5:00-18:00.
E7 is =IF(D7<$G$2;$G$2;IF(D7>$H$2;$H$2;D7))
Added column I to calculate the time during wich wave_height < 3. The sum of that column is what you need.
I8 is =H8*(G8-E7)+NOT(H8)*(D8-G8)

Related

Resample a distribution conditional on another value

I would like to create a series of simulated values by resampling from empirical observations. The data I have are time series of 1-minute frequency. The simulations should be made on an arbitrary number of days with the same times each day. The twist is, that I need to sample conditional on the time, i.e. when sampling for a time of 8:00, it should be more probable to sample a value around 8:00 (but not limited to 8:00) from the original serie.
I have made a small sketch to show, how the draw-distribution changes depending on which time the a value is simulated for:
I.e. for T=0 it is more probable to draw a value from the actual distribution where the time of day is close to 0 and not probable to draw a value from the original distribution at the time of day of T=n/2 or later, where n is the number of unique timestamps in a day.
Here is a code snippet to generate sample data (I am aware that there is no need to sample conditional on this test data, but it is just to show the structure of the data)
import numpy as np
import pandas as pd
# Create a test data frame (only for illustration)
df = pd.DataFrame(index=pd.date_range(start='2020-01-01', end='2020-12-31', freq='T'))
df['MyValue'] = np.random.normal(0, scale=1, size=len(df))
print(df)
MyValue
2020-01-01 00:00:00 0.635688
2020-01-01 00:01:00 0.246370
2020-01-01 00:02:00 1.424229
2020-01-01 00:03:00 0.173026
2020-01-01 00:04:00 -1.122581
...
2020-12-30 23:56:00 -0.331882
2020-12-30 23:57:00 -2.463465
2020-12-30 23:58:00 -0.039647
2020-12-30 23:59:00 0.906604
2020-12-31 00:00:00 -0.912604
[525601 rows x 1 columns]
# Objective: Create a new time series, where each time the values are
# drawn conditional on the time of the day
I have not been able to find an answer on here, that fits my requirements. All help are appreciated.
I consider this sentence:
need to sample conditional on the time, i.e. when sampling for a time of 8:00, it should be more probable to sample a value around 8:00 (but not limited to 8:00) from the original serie.
Then, assuming the standard deviation is one sixth of the day (given your drawing)
value = np.random.normal(loc=current_time_sample, scale=total_samples/6)

Convert Text to Time and Calculate Difference Excel

I have a text as 00:02:02:22 where the syntax is hh:mm:ss:ff (hours:minutes:seconds:frames)
I have tried changing the format to time so that I can calculate the difference between two values but I keep getting #VALUE.
I would like the answer in decimal places as 2.43 seconds...
The decimal value is frames which divided by 24. So e.g.
So the difference between 00:02:02:22 and 00:02:05:18 would be 2.83 seconds
There are a number of frame codes:
Film (24 frames per second)
PAL (25 fps)
NTSC (29.97 fps)
NTSC Drop-Frame
Digital Video (30 fps)
50 fps
60 fps
Assuming yours is the first.
With data in A1 like:
11:11:11:10
In another cell enter:
=LEFT(A1,2)/24+MID(A1,4,2)/(24*60)+MID(A1,7,2)/(24*60*60)+RIGHT(A1,2)/(24*60*60*24)
and format this cell as:
[ss].00
Once the values are converted to true times, values can be subtracted and the differences formatted as you like.

Find a temperature and work out how long it remained >= this temperature

I have an excel sheet with times in one column and temperatures in another. I'm trying to work out a formula that will find a certain temperature and measure how long it remained at that temperature.
11:25:29 AM 69.3°C
11:26:29 AM 69.6°C
11:27:29 AM 69.8°C
11:28:29 AM 70.0°C
11:29:29 AM 70.2°C
11:35:29 AM 70.8°C
11:36:29 AM 70.3°C
11:37:29 AM 69.5°C
11:38:29 AM 68.5°C
11:39:29 AM 67.5°C
12:39:29 PM 66.3°C
1:39:29 PM 52.1°C
2:39:29 PM 12.1°C
3:39:29 PM 5.0°C
In this example, I would like to find when it hit 70.0°C and how long it stayed above 70.0°C.
This is a bit of a tough problem because you might have multiple occasions where you go above 70 degrees. In that case, do you want the total time spent above 70 in the entire dataset, or do you want the total time spent above 70 consecutively? And then, how are you determining which of these potential multiple nonconsecutive periods you are talking about?
That said, you can try this. If column A is your datetime, and column B is your temp reading, specify another cell as your temperature reference value ($D$1 here), and in column C starting in row 2 do this:
=(A2-A1)*IF(B2>=$D$1,1,0)
and then copy that all the way down. What that does is it calculates the time difference between measurements and then if the temperature at that time is greater than your reference, it multiplies it by 1, otherwise it multiplies by 0. Because a date/time in Excel is really just a number, what you get is an interval of a day between measurements in each cell of column C. In other words, .25 = 6 hours.
Now that you have that data in column C, you are free to further parse it. You can use a simple SUM(C:C) formula in a cell, or you can go back and sum up individual ranges. I hope this helps.

Excel - Find max value in a 2D array with logic

I'm trying to find the maximum value from the 15 minute interval data that has dates associated with each row seen below:
DATE UOM 00:01-00:15 kW 00:16-00:30 kW 00:31-00:45 kW 00:46-01:00 kW
7/1/2010 KW 907.2 892.8 883.2 883.2
7/2/2010 KW 907.2 849.6 859.2 825.6
7/3/2010 KW 811.2 806.4 806.4 801.6
7/4/2010 KW 763.2 768 758.4 772.8
This data is electrical demands for my school's campus, and I'm trying to find peak, partial peak, and off peak maximum demands. There are approximately 4 years of data with each row consisting of a single data.
Peak hours occur during 12:00 - 18:00 hours
Partial Peak occurs during 08:31 - 11:59 & 18:00 21:30
Off Peak occurs during 21:30 - 08:30
I'd like to be able to get those values for each month of each year. But so far the logic isn't coming to me, and everything I'm looking up just shows me index-match tutorials. Any help would be greatly appreciated.
Simply use MAX or a combination of two MAX functions in order to determine maximums for any given timespan.
In my screenshot, you can see how the ranges are defined by the columns. Therefore you may have to adjust the ranges to correspond to your actual spreadsheet.
For example, for cell CW1 it uses the formula =MAX($AY2:$BV2). This determines the value of the maximum value for all 15-minute time spans within that range. Because 12:01 occurs in column AY, and 18:00 ends in column BV, it's possible to find the maximum between 12:01 - 18:00 by using the MAX function.
For time spans that are not continuous, we can split them into multiple ranges. For CX and CY we do this by using two MAX functions. So a maximum value is retrieved for each continuous time span, and then the outer MAX determines the maximum of the two local maximums.
Therefore, for CX:
=MAX(MAX($AK2:$AX2),MAX($BW2:$CJ2))
For CY:
=MAX(MAX($C2:$AJ2),MAX($CK2:$CT2))
Note that I don't have your full data set, so these values are garbage.

selection of data from a data rows

I got wind speed data in excel table like this:
(wind speed) (wind direction)
Year|month|day|00:00|06:00|12:00|18:00||00:00|06:00|12:00|18:00||X|
1966|01|01|5|12|6|8||60|360|270|50||X|
goal is to get in each day wind directin at wich was the max wind speed, for example: in firs jan. 1966 the max wind speed was 12 m/s at 06:00 and directon at the same time was 360. I need that 360 in next (X) column. If there is equal max wind speed in several observaton times then is no mater which of those directions put in at next column.
Is it poseble do it in MS excel? If someone can help me it would be so great!
Assuming the wind speed columns are D-G and the directions H-K then put the following formula in your column where the 'X' is (for row 2; copy it down the other rows)
=LOOKUP(MAX(D2:G2);D2:G2;H2:K2)

Resources