DIURNAL CYCLE ANALYSIS: TIME-OF-DAY PATTERNS

Extract and analyze hourly patterns in time series data, showing seasonal variation.

See Also:

examples/visualization/plot_dielcycle.py: plotting diel cycles with the DielCycle class

Part of the diive library: https://github.com/holukas/diive

Load example data

import diive as dv

df = dv.load_exampledata_parquet()
series = df['Tair_f'].copy()

print("Example data:")
print(f"  Records: {len(series)}")
print(f"  Period: {series.index[0]} to {series.index[-1]}")
  > Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-DAV_FP2022.5_2013-2022_ID20230206154316_30MIN.parquet (0.050
seconds).
Example data:
  Records: 175296
  Period: 2013-01-01 00:15:00 to 2022-12-31 23:45:00

Annual diel cycle

Calculate mean and standard deviation for each hour of day.

from diive.core.times.resampling import diel_cycle

diel_annual = diel_cycle(
    series=series,
    mean=True,
    std=True,
    each_month=False
)

print("\n" + "=" * 60)
print("Annual diel cycle (each_month=False)")
print("=" * 60)
print(f"Shape: {diel_annual.shape}")
print(f"\nOutput:")
print(diel_annual)
============================================================
Annual diel cycle (each_month=False)
============================================================
Shape: (48, 5)

Output:
                           count      mean       std    mean+sd   mean-sd
TIMESTAMP_MIDDLE
ALL_MONTHS       00:15:00   3652  2.982479  6.543553   9.526032 -3.561074
                 00:45:00   3652  2.871692  6.504860   9.376552 -3.633167
                 01:15:00   3652  2.768189  6.460868   9.229057 -3.692679
                 01:45:00   3652  2.679380  6.434603   9.113983 -3.755223
                 02:15:00   3652  2.597477  6.410437   9.007914 -3.812960
                 02:45:00   3652  2.517368  6.380169   8.897537 -3.862801
                 03:15:00   3652  2.452548  6.371561   8.824109 -3.919013
                 03:45:00   3652  2.386964  6.348012   8.734976 -3.961048
                 04:15:00   3652  2.327141  6.331879   8.659020 -4.004738
                 04:45:00   3652  2.256947  6.323969   8.580916 -4.067022
                 05:15:00   3652  2.218545  6.322720   8.541266 -4.104175
                 05:45:00   3652  2.209019  6.333705   8.542724 -4.124686
                 06:15:00   3652  2.244321  6.382093   8.626413 -4.137772
                 06:45:00   3652  2.369841  6.511223   8.881064 -4.141382
                 07:15:00   3652  2.587219  6.670534   9.257753 -4.083315
                 07:45:00   3652  2.939450  6.942091   9.881541 -4.002641
                 08:15:00   3652  3.453320  7.309579  10.762899 -3.856259
                 08:45:00   3652  4.099221  7.660549  11.759770 -3.561328
                 09:15:00   3652  4.746343  7.882584  12.628927 -3.136242
                 09:45:00   3652  5.383641  7.984165  13.367806 -2.600523
                 10:15:00   3652  5.980084  7.980639  13.960723 -2.000556
                 10:45:00   3652  6.496927  7.946424  14.443351 -1.449497
                 11:15:00   3652  6.939557  7.915866  14.855423 -0.976309
                 11:45:00   3652  7.288131  7.888662  15.176792 -0.600531
                 12:15:00   3652  7.604271  7.892842  15.497113 -0.288571
                 12:45:00   3652  7.842409  7.902305  15.744714 -0.059896
                 13:15:00   3652  8.028335  7.918245  15.946581  0.110090
                 13:45:00   3652  8.137510  7.951061  16.088571  0.186449
                 14:15:00   3652  8.171547  7.966701  16.138248  0.204846
                 14:45:00   3652  8.134189  7.981928  16.116117  0.152261
                 15:15:00   3652  8.012382  8.000144  16.012526  0.012238
                 15:45:00   3652  7.818468  8.027858  15.846326 -0.209390
                 16:15:00   3652  7.510818  8.053166  15.563983 -0.542348
                 16:45:00   3652  7.121048  8.058500  15.179548 -0.937452
                 17:15:00   3652  6.685729  8.036566  14.722295 -1.350837
                 17:45:00   3652  6.237397  7.953727  14.191124 -1.716330
                 18:15:00   3652  5.798995  7.813690  13.612685 -2.014696
                 18:45:00   3652  5.372668  7.621458  12.994126 -2.248791
                 19:15:00   3652  5.010137  7.461361  12.471498 -2.451224
                 19:45:00   3652  4.682585  7.320804  12.003389 -2.638220
                 20:15:00   3652  4.374713  7.166042  11.540755 -2.791329
                 20:45:00   3652  4.111743  7.034105  11.145848 -2.922362
                 21:15:00   3652  3.890518  6.931003  10.821521 -3.040485
                 21:45:00   3652  3.695499  6.833059  10.528558 -3.137560
                 22:15:00   3652  3.522417  6.755768  10.278185 -3.233351
                 22:45:00   3652  3.361139  6.697874  10.059013 -3.336736
                 23:15:00   3652  3.211265  6.638503   9.849767 -3.427238
                 23:45:00   3652  3.092345  6.584511   9.676856 -3.492166

Monthly diel cycles

Calculate separate pattern for each month.

diel_monthly = diel_cycle(
    series=series,
    mean=True,
    std=True,
    each_month=True
)

print("\n" + "=" * 60)
print("Monthly diel cycles (each_month=True)")
print("=" * 60)
print(f"Shape: {diel_monthly.shape}")
print(f"Index levels: (month 1-12, time of day)")
print(f"\nJuly (month 7) data:")
print(diel_monthly.loc[7])
============================================================
Monthly diel cycles (each_month=True)
============================================================
Shape: (576, 5)
Index levels: (month 1-12, time of day)

July (month 7) data:
          count       mean       std    mean+sd    mean-sd
00:15:00    310  10.869797  2.819510  13.689307   8.050287
00:45:00    310  10.682829  2.789711  13.472541   7.893118
01:15:00    310  10.504168  2.783628  13.287796   7.720540
01:45:00    310  10.323919  2.775859  13.099778   7.548060
02:15:00    310  10.214313  2.764727  12.979039   7.449586
02:45:00    310  10.078339  2.745914  12.824253   7.332425
03:15:00    310   9.996768  2.738394  12.735162   7.258374
03:45:00    310   9.871023  2.735376  12.606398   7.135647
04:15:00    310   9.780694  2.745418  12.526112   7.035275
04:45:00    310   9.701416  2.725587  12.427003   6.975829
05:15:00    310   9.660587  2.759554  12.420141   6.901033
05:45:00    310   9.715365  2.767752  12.483117   6.947612
06:15:00    310   9.893055  2.750676  12.643731   7.142379
06:45:00    310  10.284513  2.762349  13.046862   7.522164
07:15:00    310  10.840655  2.857890  13.698545   7.982765
07:45:00    310  11.628681  3.022074  14.650755   8.606607
08:15:00    310  12.685952  3.355923  16.041875   9.330029
08:45:00    310  13.676219  3.695470  17.371689   9.980749
09:15:00    310  14.428684  3.984591  18.413275  10.444093
09:45:00    310  14.982848  4.179360  19.162209  10.803488
10:15:00    310  15.406542  4.298980  19.705522  11.107562
10:45:00    310  15.758081  4.396545  20.154626  11.361536
11:15:00    310  16.033587  4.460874  20.494461  11.572714
11:45:00    310  16.277965  4.465546  20.743511  11.812418
12:15:00    310  16.562845  4.492265  21.055110  12.070581
12:45:00    310  16.769681  4.531590  21.301270  12.238091
13:15:00    310  16.968071  4.530044  21.498114  12.438027
13:45:00    310  17.168294  4.575173  21.743466  12.593121
14:15:00    310  17.242700  4.573927  21.816627  12.668773
14:45:00    310  17.309490  4.561548  21.871039  12.747942
15:15:00    310  17.270677  4.594328  21.865006  12.676349
15:45:00    310  17.161868  4.610535  21.772403  12.551333
16:15:00    310  16.971119  4.614969  21.586089  12.356150
16:45:00    310  16.686532  4.570647  21.257180  12.115885
17:15:00    310  16.371319  4.532165  20.903485  11.839154
17:45:00    310  15.987465  4.524198  20.511663  11.463266
18:15:00    310  15.520110  4.402530  19.922639  11.117580
18:45:00    310  14.875258  4.141460  19.016718  10.733798
19:15:00    310  14.375700  3.980667  18.356367  10.395033
19:45:00    310  13.843552  3.758530  17.602082  10.085022
20:15:00    310  13.289561  3.538473  16.828034   9.751088
20:45:00    310  12.805903  3.411845  16.217748   9.394059
21:15:00    310  12.455665  3.287105  15.742770   9.168559
21:45:00    310  12.130016  3.131410  15.261426   8.998606
22:15:00    310  11.857706  3.024802  14.882509   8.832904
22:45:00    310  11.600145  2.955289  14.555434   8.644857
23:15:00    310  11.357965  2.888793  14.246757   8.469172
23:45:00    310  11.118768  2.827155  13.945923   8.291613

Total running time of the script: (0 minutes 0.241 seconds)

Gallery generated by Sphinx-Gallery