-
Notifications
You must be signed in to change notification settings - Fork 1
/
UTCDateTime_funcs.py
36 lines (25 loc) · 952 Bytes
/
UTCDateTime_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 25 18:20:16 2016
@author: tbartholomaus ** This script was created by Timothy Bartholomaus**
A few custom functions that make it easier to work with obspy UTCDateTimes
"""
from obspy import UTCDateTime
import numpy as np
#import datetime as dt
from matplotlib.dates import date2num
#print('Hello')
# Round down a given UTCDatetime to the beginning of the day (midnight) of the given day.
def UTCfloor(t):
t_floor = UTCDateTime(t.year, t.month, t.day)
return t_floor
# Round up a given UTCDatetime to the beginning of the next day (midnight) from the given day.
def UTCceil(t):
t_ceil = UTCDateTime(t.year, t.month, t.day + 1)
return t_ceil
# Transform an np.array of UTCDateTimes into datenums, for the purpose of plotting
def UTC2dn(t):
t_datenum = np.empty(len(t))
for i in range(len(t)):
t_datenum[i] = date2num(t[i].datetime)
return t_datenum