4
4
from astropy .io .votable import parse , from_table
5
5
from astropy .table import Table
6
6
7
- np .random .seed (42 )
7
+ rng = np .random .default_rng (42 )
8
8
9
9
SMALL_SIZE = 1000
10
10
LARGE_SIZE = 200000
17
17
id_data = np .arange (LARGE_SIZE , dtype = np .int64 )
18
18
flag_data = np .random .choice ([True , False ], LARGE_SIZE )
19
19
quality_data = np .random .randint (0 , 256 , LARGE_SIZE , dtype = np .uint8 )
20
- bool_data = np . random . randint (0 , 2 , LARGE_SIZE ). astype ( bool )
20
+ bool_data = rng . integers (0 , 2 , LARGE_SIZE , dtype = bool )
21
21
22
22
short_names = np .array ([f"OBJ_{ i :08d} " for i in range (LARGE_SIZE )])
23
- filter_names = np .random .choice (["u" , "g" , "r" , "i" , "z" , "Y" ], LARGE_SIZE )
23
+ filter_names = np .random .choice (['u' , 'g' , 'r' , 'i' , 'z' , 'Y' ], LARGE_SIZE )
24
24
classifications = np .random .choice (
25
- ["STAR" , "GALAXY" , "QSO" , "UNKNOWN" ], LARGE_SIZE )
26
- long_descriptions = np .array (
27
- [
28
- f"Extend description about a field { i // 1000 :04d} "
29
- for i in range (LARGE_SIZE )
30
- ]
25
+ ['STAR' , 'GALAXY' , 'QSO' , 'UNKNOWN' ], LARGE_SIZE
31
26
)
27
+ long_descriptions = np .array ([
28
+ f"Extend description about a field { i // 1000 :04d} "
29
+ for i in range (LARGE_SIZE )
30
+ ])
32
31
33
32
34
33
def create_votable_bytes (
@@ -39,8 +38,7 @@ def create_votable_bytes(
39
38
votable = from_table (table_data )
40
39
41
40
if bitarray_size is not None :
42
- first_table = votable .get_first_table ()
43
- for field in first_table .fields :
41
+ for field in votable .get_first_table ().fields :
44
42
if field .datatype == "bit" :
45
43
field .arraysize = str (bitarray_size )
46
44
@@ -61,9 +59,9 @@ def setup(self):
61
59
flux_data [:LARGE_SIZE ],
62
60
count_data [:LARGE_SIZE ],
63
61
id_data [:LARGE_SIZE ],
64
- quality_data [:LARGE_SIZE ],
62
+ quality_data [:LARGE_SIZE ]
65
63
],
66
- names = ["ra" , " dec" , " mag" , " flux" , " counts" , "id" , " quality" ],
64
+ names = ['ra' , ' dec' , ' mag' , ' flux' , ' counts' , 'id' , ' quality' ]
67
65
)
68
66
69
67
self .binary_data = create_votable_bytes (
@@ -89,13 +87,13 @@ def setup(self):
89
87
short_names [:LARGE_SIZE ],
90
88
filter_names [:LARGE_SIZE ],
91
89
classifications [:LARGE_SIZE ],
92
- mag_data [:LARGE_SIZE ],
90
+ mag_data [:LARGE_SIZE ]
93
91
],
94
- names = ["ra" , " dec" , " object_id" , " filter" , " class" , " mag" ],
92
+ names = ['ra' , ' dec' , ' object_id' , ' filter' , ' class' , ' mag' ]
95
93
)
96
94
97
- self .binary_data = create_votable_bytes (table , " binary" )
98
- self .binary2_data = create_votable_bytes (table , " binary2" )
95
+ self .binary_data = create_votable_bytes (table , ' binary' )
96
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
99
97
100
98
def time_short_strings_binary (self ):
101
99
parse (io .BytesIO (self .binary_data ))
@@ -113,13 +111,13 @@ def setup(self):
113
111
ra_data [:LARGE_SIZE ],
114
112
dec_data [:LARGE_SIZE ],
115
113
long_descriptions [:LARGE_SIZE ],
116
- mag_data [:LARGE_SIZE ],
114
+ mag_data [:LARGE_SIZE ]
117
115
],
118
- names = ["ra" , " dec" , " description" , " mag" ],
116
+ names = ['ra' , ' dec' , ' description' , ' mag' ]
119
117
)
120
118
121
- self .binary_data = create_votable_bytes (table , " binary" )
122
- self .binary2_data = create_votable_bytes (table , " binary2" )
119
+ self .binary_data = create_votable_bytes (table , ' binary' )
120
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
123
121
124
122
def time_long_strings_binary (self ):
125
123
parse (io .BytesIO (self .binary_data ))
@@ -137,25 +135,19 @@ def setup(self):
137
135
short_names [:LARGE_SIZE ],
138
136
filter_names [:LARGE_SIZE ],
139
137
classifications [:LARGE_SIZE ],
140
- np .random .choice (["A" , "B" , "C" , "D" ], LARGE_SIZE ),
141
- np .random .choice ([" HIGH" , " MED" , " LOW" ], LARGE_SIZE ),
138
+ np .random .choice (['A' , 'B' , 'C' , 'D' ], LARGE_SIZE ),
139
+ np .random .choice ([' HIGH' , ' MED' , ' LOW' ], LARGE_SIZE ),
142
140
long_descriptions [:LARGE_SIZE ],
143
141
ra_data [:LARGE_SIZE ],
144
- dec_data [:LARGE_SIZE ],
142
+ dec_data [:LARGE_SIZE ]
145
143
],
146
144
names = [
147
- "id" ,
148
- "filter" ,
149
- "class" ,
150
- "grade" ,
151
- "priority" ,
152
- "desc" ,
153
- "ra" ,
154
- "dec" ,
155
- ],
145
+ 'id' , 'filter' , 'class' , 'grade' ,
146
+ 'priority' , 'desc' , 'ra' , 'dec'
147
+ ]
156
148
)
157
149
158
- self .binary2_data = create_votable_bytes (table , " binary2" )
150
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
159
151
160
152
def time_string_intensive_binary2 (self ):
161
153
parse (io .BytesIO (self .binary2_data ))
@@ -179,21 +171,13 @@ def setup(self):
179
171
np .random .choice ([True , False ], LARGE_SIZE ),
180
172
],
181
173
names = [
182
- "ra" ,
183
- "dec" ,
184
- "saturated" ,
185
- "flagged" ,
186
- "edge_pixel" ,
187
- "cosmic_ray" ,
188
- "variable" ,
189
- "extended" ,
190
- "public" ,
191
- "calibrated" ,
192
- ],
174
+ 'ra' , 'dec' , 'saturated' , 'flagged' , 'edge_pixel' ,
175
+ 'cosmic_ray' , 'variable' , 'extended' , 'public' , 'calibrated'
176
+ ]
193
177
)
194
178
195
- self .binary_data = create_votable_bytes (table , " binary" )
196
- self .binary2_data = create_votable_bytes (table , " binary2" )
179
+ self .binary_data = create_votable_bytes (table , ' binary' )
180
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
197
181
198
182
def time_booleans_binary (self ):
199
183
parse (io .BytesIO (self .binary_data ))
@@ -207,24 +191,15 @@ class TimeVOTableBitArrayOptimization:
207
191
208
192
def setup (self ):
209
193
table = Table (
210
- [
211
- ra_data [:LARGE_SIZE ],
212
- dec_data [:LARGE_SIZE ],
213
- mag_data [:LARGE_SIZE ],
214
- np .random .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
215
- np .random .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
216
- np .random .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
217
- np .random .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
218
- ],
219
- names = [
220
- "ra" ,
221
- "dec" ,
222
- "mag" ,
223
- "detected" ,
224
- "saturated" ,
225
- "edge_pixel" ,
226
- "cosmic_ray" ,
227
- ],
194
+ {
195
+ "ra" : ra_data [:LARGE_SIZE ],
196
+ "dec" : dec_data [:LARGE_SIZE ],
197
+ "mag" : mag_data [:LARGE_SIZE ],
198
+ "detected" : rng .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
199
+ "saturated" : rng .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
200
+ "edge_pixel" : rng .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
201
+ "cosmic_ray" : rng .randint (0 , 2 , LARGE_SIZE ).astype (bool ),
202
+ }
228
203
)
229
204
230
205
self .binary_bitarray_8_data = create_votable_bytes (
@@ -271,21 +246,13 @@ def setup(self):
271
246
flag_data [:LARGE_SIZE ],
272
247
],
273
248
names = [
274
- "ra" ,
275
- "dec" ,
276
- "id" ,
277
- "mag" ,
278
- "flux" ,
279
- "filter" ,
280
- "class" ,
281
- "counts" ,
282
- "quality" ,
283
- "detected" ,
284
- ],
249
+ 'ra' , 'dec' , 'id' , 'mag' , 'flux' ,
250
+ 'filter' , 'class' , 'counts' , 'quality' , 'detected'
251
+ ]
285
252
)
286
253
287
- self .binary_data = create_votable_bytes (table , " binary" )
288
- self .binary2_data = create_votable_bytes (table , " binary2" )
254
+ self .binary_data = create_votable_bytes (table , ' binary' )
255
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
289
256
290
257
def time_mixed_binary (self ):
291
258
parse (io .BytesIO (self .binary_data ))
@@ -302,13 +269,13 @@ def setup(self):
302
269
[
303
270
ra_data [:SMALL_SIZE ],
304
271
dec_data [:SMALL_SIZE ],
305
- mag_data [:SMALL_SIZE ],
272
+ mag_data [:SMALL_SIZE ]
306
273
],
307
- names = ["ra" , " dec" , " mag" ],
274
+ names = ['ra' , ' dec' , ' mag' ]
308
275
)
309
276
310
- self .binary_data = create_votable_bytes (table , " binary" )
311
- self .binary2_data = create_votable_bytes (table , " binary2" )
277
+ self .binary_data = create_votable_bytes (table , ' binary' )
278
+ self .binary2_data = create_votable_bytes (table , ' binary2' )
312
279
313
280
def time_small_binary (self ):
314
281
parse (io .BytesIO (self .binary_data ))
0 commit comments