Browse Source

Moved the utility functions to their own file so they can be used independently of main.py. Imports are what is used in each file (python handles multiple imports gracefully)

pull/1/head
Jay Blanchard 3 years ago
parent
commit
b1c336df9b
  1. 34
      main.py
  2. 37
      util_functions.py

34
main.py

@ -2,7 +2,6 @@
from os import path
import copy
import numpy as np
import datetime as dt
from bokeh.io import curdoc
from bokeh.layouts import row, column, widgetbox
@ -13,10 +12,7 @@ from bokeh.plotting import figure, show
from bokeh.resources import CDN
from bokeh.embed import file_html
from astropy import coordinates as coord
from astropy.time import Time
from astropy import units as u
from astropy.io import ascii
@ -24,7 +20,7 @@ from astroplan import Observer
from stations import Station
from util_functions import *
observation_types = ['EVN', 'e-EVN']
@ -55,34 +51,6 @@ outstations = CheckboxGroup(labels=["eMERLIN", "VLBA", "LBA", "KVN"], active=[])
# 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
# Reading all stations
all_stations = Station.stations_from_file(path.dirname(__file__)+'/station_location.txt')

37
util_functions.py

@ -0,0 +1,37 @@
#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
Loading…
Cancel
Save