Skip to content

Commit 8d9b7a3

Browse files
TOM updates
1 parent 4048019 commit 8d9b7a3

File tree

3 files changed

+60
-36
lines changed

3 files changed

+60
-36
lines changed

resspect/database.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ def load_features_from_file(self, path_to_features_file: str, screen=False,
276276
'rp1', 'rp2', 'rp3', 'rmax_flux',
277277
'ip1', 'ip2', 'ip3', 'imax_flux',
278278
'zp1', 'zp2', 'zp3', 'zmax_flux']
279-
280279
elif feature_extractor == 'malanchev':
281280
self.features_names = ['ganderson_darling_normal','ginter_percentile_range_5',
282281
'gchi2','gstetson_K','gweighted_mean','gduration',
@@ -310,12 +309,44 @@ def load_features_from_file(self, path_to_features_file: str, screen=False,
310309
self.metadata_names = self.metadata_names + ['cost_' + name]
311310

312311
elif survey == 'LSST':
313-
self.features_names = ['uA', 'uB', 'ut0', 'utfall', 'utrise',
314-
'gA', 'gB', 'gt0', 'gtfall', 'gtrise',
315-
'rA', 'rB', 'rt0', 'rtfall', 'rtrise',
316-
'iA', 'iB', 'it0', 'itfall', 'itrise',
317-
'zA', 'zB', 'zt0', 'ztfall', 'ztrise',
318-
'YA', 'YB', 'Yt0', 'Ytfall', 'Ytrise']
312+
if feature_extractor == "bazin":
313+
self.features_names = ['uA', 'uB', 'ut0', 'utfall', 'utrise',
314+
'gA', 'gB', 'gt0', 'gtfall', 'gtrise',
315+
'rA', 'rB', 'rt0', 'rtfall', 'rtrise',
316+
'iA', 'iB', 'it0', 'itfall', 'itrise',
317+
'zA', 'zB', 'zt0', 'ztfall', 'ztrise',
318+
'YA', 'YB', 'Yt0', 'Ytfall', 'Ytrise']
319+
elif feature_extractor == "malanchev":
320+
self.features_names = ['uanderson_darling_normal','uinter_percentile_range_5',
321+
'uchi2','ustetson_K','uweighted_mean','uduration',
322+
'uotsu_mean_diff','uotsu_std_lower', 'uotsu_std_upper',
323+
'uotsu_lower_to_all_ratio', 'ulinear_fit_slope',
324+
'ulinear_fit_slope_sigma','ulinear_fit_reduced_chi2',
325+
'ganderson_darling_normal','ginter_percentile_range_5',
326+
'gchi2','gstetson_K','gweighted_mean','gduration',
327+
'gotsu_mean_diff','gotsu_std_lower', 'gotsu_std_upper',
328+
'gotsu_lower_to_all_ratio', 'glinear_fit_slope',
329+
'glinear_fit_slope_sigma','glinear_fit_reduced_chi2',
330+
'randerson_darling_normal', 'rinter_percentile_range_5',
331+
'rchi2', 'rstetson_K', 'rweighted_mean','rduration',
332+
'rotsu_mean_diff','rotsu_std_lower', 'rotsu_std_upper',
333+
'rotsu_lower_to_all_ratio', 'rlinear_fit_slope',
334+
'rlinear_fit_slope_sigma','rlinear_fit_reduced_chi2',
335+
'ianderson_darling_normal','iinter_percentile_range_5',
336+
'ichi2', 'istetson_K', 'iweighted_mean','iduration',
337+
'iotsu_mean_diff','iotsu_std_lower', 'iotsu_std_upper',
338+
'iotsu_lower_to_all_ratio', 'ilinear_fit_slope',
339+
'ilinear_fit_slope_sigma','ilinear_fit_reduced_chi2',
340+
'zanderson_darling_normal','zinter_percentile_range_5',
341+
'zchi2', 'zstetson_K', 'zweighted_mean','zduration',
342+
'zotsu_mean_diff','zotsu_std_lower', 'zotsu_std_upper',
343+
'zotsu_lower_to_all_ratio', 'zlinear_fit_slope',
344+
'zlinear_fit_slope_sigma','zlinear_fit_reduced_chi2',
345+
'Yanderson_darling_normal','Yinter_percentile_range_5',
346+
'Ychi2', 'Ystetson_K', 'Yweighted_mean','Yduration',
347+
'Yotsu_mean_diff','Yotsu_std_lower', 'Yotsu_std_upper',
348+
'Yotsu_lower_to_all_ratio', 'Ylinear_fit_slope',
349+
'Ylinear_fit_slope_sigma','Ylinear_fit_reduced_chi2']
319350

320351
if 'objid' in data.keys():
321352
self.metadata_names = ['objid', 'redshift', 'type', 'code',

resspect/fit_lightcurves.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def fit_plasticc(path_photo_file: str, path_header_file: str,
242242
logging.info("Features have been saved to: %s", output_file)
243243

244244
def _TOM_sample_fit(
245-
id: str, dic: dict, feature_extractor: str):
245+
obj_dic: dict, feature_extractor: str):
246246
"""
247247
Reads SNPCC file and performs fit.
248248
@@ -255,20 +255,20 @@ def _TOM_sample_fit(
255255
Options are 'bazin', 'bump', or 'malanchev'.
256256
"""
257257
light_curve_data = FEATURE_EXTRACTOR_MAPPING[feature_extractor]()
258-
light_curve_data.photometry = pd.DataFrame(dic[id]['photometry'])
258+
light_curve_data.photometry = pd.DataFrame(obj_dic['photometry'])
259259
light_curve_data.dataset_name = 'TOM'
260260
light_curve_data.filters = ['u', 'g', 'r', 'i', 'z', 'Y']
261-
light_curve_data.id = id
262-
light_curve_data.redshift = dic[id]['redshift']
261+
light_curve_data.id = obj_dic['objectid']
262+
light_curve_data.redshift = obj_dic['redshift']
263263
light_curve_data.sntype = 'unknown'
264-
light_curve_data.sncode = dic[id]['sncode']
264+
light_curve_data.sncode = obj_dic['sncode']
265265
light_curve_data.sample = 'N/A'
266266

267267
light_curve_data.fit_all()
268268

269269
return light_curve_data
270270

271-
def fit_TOM(data_dic: dict, features_file: str,
271+
def fit_TOM(data_dic: dict, output_features_file: str,
272272
number_of_processors: int = 1,
273273
feature_extractor: str = 'bazin'):
274274
"""
@@ -278,7 +278,7 @@ def fit_TOM(data_dic: dict, features_file: str,
278278
----------
279279
data_dic: str
280280
Dictionary containing the photometry for all light curves.
281-
features_file: str
281+
output_features_file: str
282282
Path to output file where results should be stored.
283283
number_of_processors: int, default 1
284284
Number of cpu processes to use.
@@ -289,45 +289,36 @@ def fit_TOM(data_dic: dict, features_file: str,
289289
header = TOM_FEATURES_HEADER
290290
elif feature_extractor == 'malanchev':
291291
header = TOM_MALANCHEV_FEATURES_HEADER
292-
292+
293293
multi_process = multiprocessing.Pool(number_of_processors)
294294
logging.info("Starting TOM " + feature_extractor + " fit...")
295-
with open(features_file, 'w') as snpcc_features_file:
296-
snpcc_features_file.write(','.join(header) + '\n')
295+
with open(output_features_file, 'w') as TOM_features_file:
296+
TOM_features_file.write(','.join(header) + '\n')
297297

298298
for light_curve_data in multi_process.starmap(
299299
_TOM_sample_fit, zip(
300-
data_dic, repeat(data_dic), repeat(feature_extractor))):
300+
data_dic, repeat(feature_extractor))):
301301
if 'None' not in light_curve_data.features:
302302
write_features_to_output_file(
303-
light_curve_data, snpcc_features_file)
304-
logging.info("Features have been saved to: %s", features_file)
303+
light_curve_data, TOM_features_file)
304+
logging.info("Features have been saved to: %s", output_features_file)
305305

306306
def request_TOM_data(url: str = "https://desc-tom-2.lbl.gov", username: str = None,
307307
passwordfile: str = None, password: str = None, detected_since_mjd: float = None,
308-
detected_in_last_days: float = None,):
308+
detected_in_last_days: float = None, mjdnow: float = None):
309309
tom = TomClient(url = url, username = username, passwordfile = passwordfile,
310310
password = password)
311311
dic = {}
312312
if detected_since_mjd is not None:
313313
dic['detected_since_mjd'] = detected_since_mjd
314314
if detected_in_last_days is not None:
315315
dic['detected_in_last_days'] = detected_in_last_days
316-
res = tom.post('elasticc2/gethotsne', dic)
316+
if mjdnow is not None:
317+
dic['mjd_now'] = mjdnow
318+
res = tom.post('elasticc2/gethottransients', json = dic)
317319
data_dic = res.json()
318320
return data_dic
319321

320-
def submit_queries_to_TOM(objectids: list, priorities: list, requester: str='resspect'):
321-
req = { 'requester': requester,
322-
'objectids': objectids,
323-
'priorities': priorities}
324-
res = TomClient.request( 'POST', 'elasticc2/askforspectrum', json=req )
325-
dic = res.json()
326-
if res.satus_code != 200:
327-
raise ValueError('Request failed, ' + res.text + ". Status code: " + str(res.status_code))
328-
329-
if dic['status'] == 'error':
330-
raise ValueError('Request failed, ' + dic.json()['error'])
331322

332323
def main():
333324
return None

resspect/time_domain_loop.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
__all__ = ['time_domain_loop', 'load_dataset']
17+
__all__ = ['time_domain_loop', 'load_dataset', 'submit_queries_to_TOM']
1818

1919
import os
2020
from typing import Union, Tuple
@@ -24,6 +24,7 @@
2424
import progressbar
2525

2626
from resspect import DataBase
27+
from resspect.tom_client import TomClient
2728

2829

2930
def load_dataset(file_names_dict: dict, survey_name: str = 'DES',
@@ -799,11 +800,12 @@ def process_next_day_loop(
799800
return light_curve_data
800801

801802

802-
def submit_queries_to_TOM(objectids: list, priorities: list, requester: str='resspect'):
803+
def submit_queries_to_TOM(username, passwordfile, objectids: list, priorities: list, requester: str='resspect'):
804+
tom = TomClient(url = "https://desc-tom-2.lbl.gov", username = username, passwordfile = passwordfile)
803805
req = { 'requester': requester,
804806
'objectids': objectids,
805807
'priorities': priorities}
806-
res = TomClient.request( 'POST', 'elasticc2/askforspectrum', json=req )
808+
res = tom.request( 'POST', 'elasticc2/askforspectrum', json=req )
807809
dic = res.json()
808810
if res.satus_code != 200:
809811
raise ValueError('Request failed, ' + res.text + ". Status code: " + str(res.status_code))

0 commit comments

Comments
 (0)