-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_streak_len.py
executable file
·165 lines (142 loc) · 5.23 KB
/
find_streak_len.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
import os, sys, time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import healpy as hp
from rubin_sim.data import get_data_dir
import sqlite3
import argparse
from sat_utils import (
Constellation,
starlink_constellation_v1,
starlink_constellation_v2,
oneweb_constellation,
sun_alt_limits,
)
def data_setup(datalocation, sun_alt_limit=-90):
"""
Loads up the dataframe given a datalocation
Parameters
----------
Param1 : str
the location of data
Returns
-------
dataframe
dataframe that contains the data in that location
"""
# Conenct to the sqlite database
con = sqlite3.connect(datalocation)
# Load up the first year
df = pd.read_sql(
"select * from observations where night < 366 and sunAlt > %f;" % sun_alt_limit,
con,
)
con.close()
return df
def compute_streak_len(
datalocation,
constellation,
fieldRA="fieldRA",
fieldDec="fieldDec",
mjd="observationStartMJD",
exptime="visitTime",
obsid="observationId",
sun_alt_limit=-90,
chunk_size=None,
):
"""
computes the streak length of satellite crossing
Parameters
----------
Param1 : datalocation
the location of data that contains the pointing informations.
Param2 : constellation
the constellation of satellites.
Param3 : fieldRA
the name of the dataframe column that gives information about the RA of the pointing.
Param4 : fieldDec
the name of the dataframe column that gives information about the Dec of the pointing.
Param5 : mjd
the name of the dataframe column that gives information about the observation mjd of the pointing.
Param6 : exptime
the name of the dataframe column that gives information about the exposure time of the pointing.
Param7 : obsid
the name of the dataframe column that gives information about the observation id of the pointing.
Returns
-------
list
list with 3-Tuple elements containing observation id, the length of the streaks, and the number of streaks of each pointing.
"""
if datalocation is None:
dd = get_data_dir()
baseline_file = os.path.join(dd, "sim_baseline/baseline.db")
datalocation = baseline_file
df = data_setup(datalocation, sun_alt_limit=sun_alt_limit)
if chunk_size is None:
fast_lengths, fast_nstreaks = constellation.check_pointings(
df[fieldRA].values, df[fieldDec].values, df[mjd].values, df[exptime].values
)
else:
lengths = []
n_streaks = []
n_chunks = np.ceil(df[fieldRA].values.size/chunk_size)
for i, chunk in enumerate(np.array_split(df, n_chunks)):
#print('working on chunk %i of %i' % (i, n_chunks))
fast_lengths, fast_nstreaks = constellation.check_pointings(
chunk[fieldRA].values, chunk[fieldDec].values,
chunk[mjd].values, chunk[exptime].values
)
lengths.append(fast_lengths)
n_streaks.append(fast_nstreaks)
fast_lengths = np.concatenate(lengths)
fast_nstreaks = np.concatenate(n_streaks)
names = [obsid, "streak_len_deg", "n_streaks"]
types = [int, float, int]
result = np.empty(np.size(fast_lengths), dtype=list(zip(names, types)))
result[obsid] = df.loc[:, obsid].values
result["streak_len_deg"] = fast_lengths
result["n_streaks"] = fast_nstreaks
return result
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--datalocation", type=str, default=None)
parser.add_argument("--fieldRA", type=str, default="fieldRA")
parser.add_argument("--fieldDec", type=str, default="fieldDec")
parser.add_argument("--mjd", type=str, default="observationStartMJD")
parser.add_argument("--exptime", type=str, default="visitTime")
parser.add_argument("--obsid", type=str, default="observationId")
parser.add_argument("--constellation_name", type=str, default="slv1")
parser.add_argument("--chunk_size", type=int, default=None)
args = parser.parse_args()
datalocation = args.datalocation
if args.constellation_name == "slv1":
tles = starlink_constellation_v1()
elif args.constellation_name == "slv2":
tles = starlink_constellation_v2()
elif args.constellation_name == "oneweb":
tles = oneweb_constellation()
else:
ValueError("Constellation name unknown, use slv1, slv2, or oneweb")
sun_alt_limit = sun_alt_limits()[args.constellation_name]
constellation = Constellation(tles)
fieldRA = args.fieldRA
fieldDec = args.fieldDec
mjd = args.mjd
exptime = args.exptime
obsid = args.obsid
chunk_size = args.chunk_size
filename = datalocation.replace(".db", "") + ".npz"
obs_array = compute_streak_len(
datalocation,
constellation,
fieldRA,
fieldDec,
mjd,
exptime,
obsid,
sun_alt_limit=sun_alt_limit,
chunk_size=chunk_size,
)
np.savez(filename, obs_array=obs_array)