exoclock 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,184 @@
1
+ from my_packages import *
2
+
3
+ # https://ssd.jpl.nasa.gov/horizons.cgi#top
4
+ # Astrometric RA & DEC
5
+ # One-way (down-leg) light-time
6
+ # Delta-T (TDB - UT)
7
+ # Start=2000-01-01 12:00, Stop=2040-01-01 12:00, Step=6 h
8
+
9
+
10
+
11
+ data_t = np.arange(2451545.0, 2451545.0+14610.000000001, 0.25)
12
+
13
+ data_ra = []
14
+ data_ra_noleaps = []
15
+ data_dec = []
16
+ data_d = []
17
+ data_dt = []
18
+ leaps = 0
19
+ for xx in open('/Users/angelos/Desktop/BJD.txt').readlines():
20
+ test_ra = float(xx.split()[2])+float(xx.split()[3])/60.0+float(xx.split()[4])/3600.0
21
+ test_dec = (abs(float(xx.split()[5]))+float(xx.split()[6])/60.0+float(xx.split()[7])/3600.0)*float('{0}1'.format(xx.split()[5][0]))
22
+ if len(data_ra) > 0:
23
+ if test_ra < data_ra_noleaps[-1]:
24
+ leaps += 1
25
+ data_ra.append((test_ra + 24 * leaps) * 15 * np.pi / 180)
26
+ data_ra_noleaps.append(test_ra)
27
+ data_dec.append(test_dec * np.pi / 180)
28
+ data_d.append(float(xx.split()[-2]))
29
+ data_dt.append(float(xx.split()[-1]))
30
+
31
+ plt.plot(data_t, data_ra, 'o')
32
+ plt.show()
33
+
34
+ plt.plot(data_t, data_dec, 'o')
35
+ plt.show()
36
+
37
+ plt.plot(data_t, data_d, 'o')
38
+ plt.show()
39
+
40
+ plt.plot(data_t, data_dt, 'o')
41
+ plt.show()
42
+
43
+
44
+ data_dict = {int(ff):{'t':np.array([]), 'ra':np.array([]), 'dec':np.array([]), 'd':np.array([]), 'dt':np.array([])} for ff in np.arange(2451545.0, 2451545.0+14610)}
45
+ for xx in range(len(data_t)):
46
+ indx = int(data_t[xx])
47
+ if indx in data_dict:
48
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
49
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
50
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
51
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
52
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
53
+ if indx == data_t[xx]:
54
+ indx = int(data_t[xx] - 1)
55
+ if indx in data_dict:
56
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
57
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
58
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
59
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
60
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
61
+
62
+ plc.save_dict(data_dict, '/Users/angelos/Desktop/bjd_dict.pickle')
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ data_t = np.arange(2451545.0, 2451545.0+14610.000000001, 0.25)
73
+
74
+ data_ra = []
75
+ data_ra_noleaps = []
76
+ data_dec = []
77
+ data_d = []
78
+ data_dt = []
79
+ leaps = 0
80
+ for xx in open('/Users/angelos/Desktop/HJD.txt').readlines():
81
+ test_ra = float(xx.split()[2])+float(xx.split()[3])/60.0+float(xx.split()[4])/3600.0
82
+ test_dec = (abs(float(xx.split()[5]))+float(xx.split()[6])/60.0+float(xx.split()[7])/3600.0)*float('{0}1'.format(xx.split()[5][0]))
83
+ if len(data_ra) > 0:
84
+ if test_ra < data_ra_noleaps[-1]:
85
+ leaps += 1
86
+ data_ra.append((test_ra + 24.0 * leaps) * 15.0 * np.pi / 180.0)
87
+ data_ra_noleaps.append(test_ra)
88
+ data_dec.append(test_dec * np.pi / 180)
89
+ data_d.append(float(xx.split()[-2]))
90
+ data_dt.append(float(xx.split()[-1]))
91
+
92
+ plt.plot(data_t, data_ra, 'o')
93
+ plt.show()
94
+
95
+ plt.plot(data_t, data_dec, 'o')
96
+ plt.show()
97
+
98
+ plt.plot(data_t, data_d, 'o')
99
+ plt.show()
100
+
101
+ plt.plot(data_t, data_dt, 'o')
102
+ plt.show()
103
+
104
+
105
+ data_dict = {int(ff): {'t':np.array([]), 'ra':np.array([]), 'dec':np.array([]), 'd':np.array([]), 'dt':np.array([])} for ff in np.arange(2451545.0, 2451545.0+14610)}
106
+ for xx in range(len(data_t)):
107
+ indx = int(data_t[xx])
108
+ if indx in data_dict:
109
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
110
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
111
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
112
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
113
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
114
+ if indx == data_t[xx]:
115
+ indx = int(data_t[xx] - 1)
116
+ if indx in data_dict:
117
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
118
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
119
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
120
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
121
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
122
+
123
+ plc.save_dict(data_dict, '/Users/angelos/Desktop/hjd_dict.pickle')
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ import numpy as np
132
+ import matplotlib.pyplot as plt
133
+ data_t = np.arange(2451545.0, 2451545.0+14610.000000001, 0.25)
134
+
135
+ data_ra = []
136
+ data_ra_noleaps = []
137
+ data_dec = []
138
+ data_d = []
139
+ data_dt = []
140
+ leaps = 0
141
+ for xx in open('/Users/angelos/Downloads/MOON.txt').readlines():
142
+ test_ra = float(xx.split()[2])+float(xx.split()[3])/60.0+float(xx.split()[4])/3600.0
143
+ test_dec = (abs(float(xx.split()[5]))+float(xx.split()[6])/60.0+float(xx.split()[7])/3600.0)*float('{0}1'.format(xx.split()[5][0]))
144
+ if len(data_ra) > 0:
145
+ if test_ra < data_ra_noleaps[-1]:
146
+ leaps += 1
147
+ data_ra.append((test_ra + 24.0 * leaps) * 15.0 * np.pi / 180.0)
148
+ data_ra_noleaps.append(test_ra)
149
+ data_dec.append(test_dec * np.pi / 180)
150
+ data_d.append(float(xx.split()[-2]))
151
+ data_dt.append(float(xx.split()[-1]))
152
+
153
+ plt.plot(data_t, data_ra, 'o')
154
+ plt.show()
155
+
156
+ plt.plot(data_t, data_dec, 'o')
157
+ plt.show()
158
+
159
+ plt.plot(data_t, data_d, 'o')
160
+ plt.show()
161
+
162
+ plt.plot(data_t, data_dt, 'o')
163
+ plt.show()
164
+
165
+
166
+ data_dict = {int(ff): {'t':np.array([]), 'ra':np.array([]), 'dec':np.array([]), 'd':np.array([]), 'dt':np.array([])} for ff in np.arange(2451545.0, 2451545.0+14610)}
167
+ for xx in range(len(data_t)):
168
+ indx = int(data_t[xx])
169
+ if indx in data_dict:
170
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
171
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
172
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
173
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
174
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
175
+ if indx == data_t[xx]:
176
+ indx = int(data_t[xx] - 1)
177
+ if indx in data_dict:
178
+ data_dict[indx]['t'] = np.append(data_dict[indx]['t'], data_t[xx])
179
+ data_dict[indx]['ra'] = np.append(data_dict[indx]['ra'], data_ra[xx])
180
+ data_dict[indx]['dec'] = np.append(data_dict[indx]['dec'], data_dec[xx])
181
+ data_dict[indx]['d'] = np.append(data_dict[indx]['d'], data_d[xx])
182
+ data_dict[indx]['dt'] = np.append(data_dict[indx]['dt'], data_dt[xx])
183
+
184
+ plc.save_dict(data_dict, '/Users/angelos/Desktop/moon_dict.pickle')
@@ -0,0 +1 @@
1
+ Angelos Tsiaras
@@ -0,0 +1 @@
1
+ aggelostsiaras@gmail.com
Binary file
@@ -0,0 +1,182 @@
1
+
2
+ import os
3
+ import time
4
+ import shutil
5
+
6
+ from .processes.files import open_dict, download
7
+
8
+ try:
9
+ import zipfile
10
+ download_zip = True
11
+ except:
12
+ download_zip = False
13
+
14
+
15
+ def _setup_database(package_data, database_name):
16
+
17
+ print('exoclock: Checking {0} database...'.format(database_name))
18
+
19
+ # define paths
20
+
21
+ database_directory_path = os.path.join(package_data.databases_directory_path, database_name)
22
+ database_file_path = os.path.join(package_data.databases_directory_path, database_name + '.pickle')
23
+ database_link_file_path = os.path.join(package_data.databases_directory_path, database_name + '_link.txt')
24
+ database_file_path_new = os.path.join(package_data.databases_directory_path, database_name + '_new.pickle')
25
+ database_file_path_old = os.path.join(package_data.databases_directory_path, database_name + '_old.pickle')
26
+ last_update_file_path = os.path.join(package_data.databases_directory_path, '{0}_last_update.txt'.format(database_name))
27
+
28
+ # define paths
29
+
30
+ # check if everything exists, if not reset database
31
+
32
+ if not os.path.isdir(database_directory_path) or not os.path.isfile(database_file_path) or not os.path.isfile(database_link_file_path):
33
+
34
+ try:
35
+ shutil.rmtree(database_directory_path)
36
+ except:
37
+ pass
38
+
39
+ try:
40
+ os.remove(database_file_path)
41
+ except:
42
+ pass
43
+
44
+ try:
45
+ os.remove(database_file_path_old)
46
+ except:
47
+ pass
48
+
49
+ try:
50
+ os.remove(database_file_path_new)
51
+ except:
52
+ pass
53
+
54
+ try:
55
+ os.remove(database_link_file_path)
56
+ except:
57
+ pass
58
+
59
+ try:
60
+ os.remove(last_update_file_path)
61
+ except:
62
+ pass
63
+
64
+ os.mkdir(database_directory_path)
65
+
66
+
67
+ print(package_data.databases[package_data.version][database_name], database_file_path)
68
+
69
+ if not download(package_data.databases[package_data.version][database_name], database_file_path):
70
+ print('\n{0} features cannot be used.'.format(database_name))
71
+ return False
72
+ else:
73
+ shutil.copy(database_file_path, database_file_path_old)
74
+ w = open(database_link_file_path, 'w')
75
+ w.write(package_data.databases[package_data.version][database_name])
76
+ w.close()
77
+
78
+ try:
79
+ new_database = open_dict(database_file_path)
80
+ download(new_database['zipfile'], database_directory_path + '.zip')
81
+ new_database = zipfile.ZipFile(database_directory_path + '.zip', 'r')
82
+ here = os.path.abspath('.')
83
+ os.chdir(package_data.databases_directory_path)
84
+ new_database.extractall()
85
+ os.chdir(here)
86
+ os.remove(database_directory_path + '.zip')
87
+ except:
88
+ pass
89
+
90
+ # check if everything exists, if not reset database
91
+
92
+ # download database if there is an update
93
+
94
+ if package_data.databases[package_data.version][database_name] != open(database_link_file_path).read():
95
+
96
+ if not download(package_data.databases[package_data.version][database_name], database_file_path_new):
97
+ pass
98
+ else:
99
+ shutil.move(database_file_path, database_file_path_old)
100
+ shutil.move(database_file_path_new, database_file_path)
101
+
102
+ w = open(database_link_file_path, 'w')
103
+ w.write(package_data.databases[package_data.version][database_name])
104
+ w.close()
105
+
106
+ # download database if there is an update
107
+
108
+ # check all files in database, remove files that need to be updated
109
+
110
+ current_database = open_dict(database_file_path_old)
111
+ new_database = open_dict(database_file_path)
112
+
113
+ for dbx_file in current_database['files']:
114
+
115
+ if dbx_file not in new_database['files']:
116
+ try:
117
+ os.remove(os.path.join(package_data.databases_directory_path,
118
+ new_database['files'][dbx_file]['local_path']))
119
+ except:
120
+ pass
121
+ elif new_database['files'][dbx_file]['link'] != current_database['files'][dbx_file]['link']:
122
+ try:
123
+ os.remove(os.path.join(package_data.databases_directory_path,
124
+ new_database['files'][dbx_file]['local_path']))
125
+ except:
126
+ pass
127
+
128
+ # check for updates, remove files that need to be updated
129
+
130
+ # download missing files
131
+
132
+ final_check = True
133
+
134
+ for dbx_file in new_database['files']:
135
+ if not os.path.isfile(os.path.join(package_data.databases_directory_path,
136
+ new_database['files'][dbx_file]['local_path'])):
137
+ try:
138
+ os.remove(last_update_file_path)
139
+ except:
140
+ pass
141
+ if not download(new_database['files'][dbx_file]['link'],
142
+ os.path.join(package_data.databases_directory_path,
143
+ new_database['files'][dbx_file]['local_path'])):
144
+ final_check = False
145
+
146
+ # download missing files
147
+
148
+ # update files from external links
149
+
150
+ frequency = new_database['frequency']
151
+ if frequency:
152
+
153
+ try:
154
+ last_update_date = int(open(last_update_file_path).read())
155
+ except:
156
+ last_update_date = 0
157
+
158
+ today = int(time.strftime('%y%m%d'))
159
+
160
+ if today >= last_update_date + frequency:
161
+
162
+ for dbx_file in new_database['files']:
163
+ if 'external_link' in new_database['files'][dbx_file]:
164
+ print('\tUpdating: ', dbx_file)
165
+ if not download(new_database['files'][dbx_file]['external_link'],
166
+ os.path.join(package_data.databases_directory_path,
167
+ new_database['files'][dbx_file]['local_path'])):
168
+ final_check = False
169
+
170
+ w = open(last_update_file_path, 'w')
171
+ w.write(time.strftime('%y%m%d'))
172
+ w.close()
173
+
174
+ # update files from external links
175
+
176
+ if not final_check:
177
+ print('\n{0} features cannot be used.'.format(database_name))
178
+ return False
179
+ else:
180
+ if current_database != new_database:
181
+ shutil.copy(database_file_path, database_file_path_old)
182
+ return database_directory_path
@@ -0,0 +1 @@
1
+ A python package for programmatic interaction with the ExoClock project archives.
exoclock/__init__.py ADDED
@@ -0,0 +1,20 @@
1
+ import os
2
+
3
+ __version__ = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__version__.txt')).read()
4
+ __author__ = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__author__.txt')).read()
5
+ __author_email__ = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__author_email__.txt')).read()
6
+ __description__ = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__description__.txt')).read()
7
+ __url__ = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__url__.txt')).read()
8
+
9
+ from .catalogues.catalogues import *
10
+ from .catalogues.simbad import *
11
+
12
+ from .spacetime.angles import *
13
+ from .spacetime.moments import *
14
+ from .spacetime.observatories import *
15
+ from .spacetime.targets import *
16
+
17
+ from .processes.files import *
18
+
19
+ from .errors import *
20
+ from .databases import *
exoclock/__url__.txt ADDED
@@ -0,0 +1 @@
1
+ https://github.com/atsiaras/exoclock
@@ -0,0 +1 @@
1
+ 1.0.1
File without changes
@@ -0,0 +1,121 @@
1
+
2
+ __all__ = ['get_planet', 'get_system', 'get_all_planets', 'locate_planet', 'locate_system', 'get_all_planets']
3
+
4
+ import numpy as np
5
+
6
+
7
+ from .simbad import simbad_search_by_name
8
+
9
+ from ..spacetime.angles import *
10
+ from ..spacetime.angles import _request_angle, _reformat_or_request_angle
11
+ from ..spacetime.targets import *
12
+ from ..databases import exoclock_data
13
+ from ..errors import *
14
+
15
+
16
+ def _flat_name(name):
17
+
18
+ flat_name_list = [
19
+ [' ', ''],
20
+ ['-', ''],
21
+ ['cancri', 'cnc'],
22
+ ['hatp10', 'wasp11'],
23
+ ['wasp40', 'hatp27'],
24
+ ['wasp51', 'hatp30'],
25
+ ['wasp86', 'kelt12'],
26
+ ['kelt22', 'wasp173'],
27
+ ]
28
+
29
+ name = name.lower()
30
+
31
+ for char in flat_name_list:
32
+ name = name.replace(char[0], char[1])
33
+
34
+ return name
35
+
36
+
37
+ def _search_by_planet(name):
38
+
39
+ planets = exoclock_data.ecc()['planets']
40
+
41
+ name_or = name
42
+
43
+ if name in planets:
44
+ return name
45
+
46
+ else:
47
+ for i in planets:
48
+ if _flat_name(i) == _flat_name(name):
49
+ return str(i)
50
+ elif (_flat_name(i)[-1] == _flat_name(name)[-1] and _flat_name(i)[:-2] == _flat_name(name)[:-1] and
51
+ _flat_name(i)[-2] in ['a', 'b', 'n']):
52
+ return str(i)
53
+
54
+ raise ExoClockInputError('No planet {0} found in the catalogue.'.format(name_or))
55
+
56
+
57
+ def get_all_planets():
58
+
59
+ return list(exoclock_data.ecc()['planets'].keys())
60
+
61
+
62
+ def get_planet(name):
63
+
64
+ name = _search_by_planet(name)
65
+
66
+ planet_data = exoclock_data.ecc()['planets'][name]
67
+ star_data = exoclock_data.ecc()['stars'][planet_data['star']]
68
+ star_data['ra_deg'] = Hours(star_data['ra']).deg()
69
+ star_data['dec_deg'] = Degrees(star_data['dec']).deg_coord()
70
+
71
+ return {'name': name, 'planet': planet_data, 'star': star_data}
72
+
73
+
74
+ def get_system(star_name):
75
+
76
+ target = simbad_search_by_name(star_name)
77
+ if not target:
78
+ return []
79
+
80
+ test = list(set(target.all_names).intersection(list(exoclock_data.ecc()['hosts'])))
81
+
82
+ if len(test) == 0:
83
+ return []
84
+
85
+ planets = exoclock_data.ecc()['hosts'][test[0]]
86
+
87
+ return [get_planet(planet) for planet in planets]
88
+
89
+
90
+ def locate_planet(ra, dec, radius=Degrees(0.02), observation_time=None, observation_type=None):
91
+
92
+ _request_angle(ra)
93
+ _request_angle(dec)
94
+ _request_angle(radius)
95
+
96
+ pointing = FixedTarget(ra, dec)
97
+
98
+ test_planets = []
99
+
100
+ for test_planet_name in get_all_planets():
101
+ test_planet = get_planet(test_planet_name)
102
+ test_planet = FixedTarget(Degrees(test_planet['star']['ra_deg']), Degrees(test_planet['star']['dec_deg']))
103
+ test_planets.append([pointing.distance_on_sphere(test_planet).deg(), test_planet_name])
104
+
105
+ test_planets.sort()
106
+
107
+ if test_planets[0][0] < radius.deg():
108
+ return get_planet(test_planets[0][1])
109
+ else:
110
+ raise ExoClockLibraryError('Planet could not be located')
111
+
112
+
113
+ def locate_system(ra, dec, radius=0.02):
114
+
115
+ return get_system(locate_planet(ra, dec, radius)['star']['simbad_id'])
116
+
117
+
118
+ def get_all_planets():
119
+ return list(exoclock_data.ecc()['planets'].keys())
120
+
121
+