forked from bmarcote/seffers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_functions.py
37 lines (28 loc) · 1.24 KB
/
util_functions.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
#util functions for seffers
import numpy as np
import datetime as dt
from astropy import coordinates as coord
from astropy.time import Time
from astropy import units as u
# useful functions
def get_coordinates(text_coord):
"""Given a string representing coordinates in the form hh:mm:ss dd:mm:ss
if returns the astropy.coordinates from this object.
"""
ra, dec = text_coord.strip().split(' ')
ra = [float(i) for i in ra.split(':')]
dec = [float(i) for i in dec.split(':')]
return coord.SkyCoord('{:n}h{:n}m{}s {:n}d{:n}m{}s'.format(*ra, *dec))
def get_time(text_time):
"""Returns a datetime.datetime object representing the input text_time that
should have the form DD/MM/YYYY HH:MM
"""
# return Observer.datetime_to_astropy_time(dt.datetime.strptime(text_time, '%d/%m/%Y %H:%M'))
the_time = dt.datetime.strptime(text_time, '%d/%m/%Y %H:%M')
return Time(the_time.strftime('%Y-%m-%d %H:%M'))
#date = [int(i) for i in date.split('/')]
def get_obs_times(start_time, duration, interval=0.2):
"""Returns the times of the observation from the starting to the end
Duration and interval must be in hours, without units.
"""
return start_time + np.arange(0.0, duration+interval/2., interval)*u.h