<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> __all__ = [ '<STR_LIT>' ] <EOL> import numpy as np <EOL> from scipy . interpolate import interp1d <EOL> from . import fetch_rrlyrae_templates , fetch_rrlyrae <EOL> class RRLyraeGenerated ( object ) : <EOL> """<STR_LIT>""" <EOL> lcdata = None <EOL> templates = None <EOL> ext_correction = { '<STR_LIT:u>' : <NUM_LIT> , <EOL> '<STR_LIT:g>' : <NUM_LIT> , <EOL> '<STR_LIT:r>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT:i>' : <NUM_LIT> , <EOL> '<STR_LIT:z>' : <NUM_LIT> } <EOL> @ classmethod <EOL> def _fetch_data ( cls ) : <EOL> if cls . lcdata is None : <EOL> cls . lcdata = fetch_rrlyrae ( ) <EOL> cls . templates = fetch_rrlyrae_templates ( ) <EOL> @ classmethod <EOL> def _template_func ( cls , num , band , mu = <NUM_LIT:0> , A = <NUM_LIT:1> ) : <EOL> template_id = "<STR_LIT>" . format ( num , band ) <EOL> phase , amp = cls . templates . get_template ( template_id ) <EOL> phase = np . concatenate ( [ phase , [ <NUM_LIT:1> ] ] ) <EOL> amp = np . concatenate ( [ amp , amp [ - <NUM_LIT:1> : ] ] ) <EOL> return interp1d ( phase , mu + A * amp ) <EOL> def __init__ ( self , lcid , random_state = None ) : <EOL> self . _fetch_data ( ) <EOL> self . lcid = lcid <EOL> self . meta = self . lcdata . get_metadata ( lcid ) <EOL> self . obsmeta = self . lcdata . get_obsmeta ( lcid ) <EOL> self . rng = np . random . RandomState ( random_state ) <EOL> @ property <EOL> def period ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . meta [ '<STR_LIT:P>' ] <EOL> def observed ( self , band , corrected = True ) : <EOL> """<STR_LIT>""" <EOL> if band not in '<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" . format ( band ) ) <EOL> i = '<STR_LIT>' . find ( band ) <EOL> t , y , dy = self . lcdata . get_lightcurve ( self . lcid , return_1d = False ) <EOL> if corrected : <EOL> ext = self . obsmeta [ '<STR_LIT>' ] * self . ext_correction [ band ] <EOL> else : <EOL> ext = <NUM_LIT:0> <EOL> return t [ : , i ] , y [ : , i ] - ext , dy [ : , i ] <EOL> def generated ( self , band , t , err = None , corrected = True ) : <EOL> """<STR_LIT>""" <EOL> t = np . asarray ( t ) <EOL> num = self . meta [ band + '<STR_LIT:T>' ] <EOL> mu = self . meta [ band + '<STR_LIT:0>' ] <EOL> amp = self . meta [ band + '<STR_LIT:A>' ] <EOL> t0 = self . meta [ band + '<STR_LIT:E>' ] <EOL> bad_vals = np . isnan ( t ) | np . isinf ( t ) <EOL> t [ bad_vals ] = t0 <EOL> if corrected : <EOL> ext = <NUM_LIT:0> <EOL> else : <EOL> ext = self . obsmeta [ '<STR_LIT>' ] * self . ext_correction [ band ] <EOL> func = self . _template_func ( num , band , mu + ext , amp ) <EOL> mag = func ( ( ( t - t0 ) / self . period ) % <NUM_LIT:1> ) <EOL> mag [ bad_vals ] = np . nan <EOL> if err is not None : <EOL> mag += self . rng . normal ( <NUM_LIT:0> , err , t . shape ) <EOL> return mag </s>
