def load(dic=None): """ Load points from dat-files. :return SetLightCurves: """ from pystella.util.math import is_number fname = None tshift = 0. mshift = 0. mag_lim = 99. arg = [] is_debug = False comments = '#' if dic is not None: is_debug = dic.get('is_debug', False) mag_lim = dic.get('mag_lim', mag_lim) if 'args' in dic: arg = dic['args'] if len(arg) > 0: fname = arg.pop(0) fname = os.path.expanduser(fname) if len(arg) > 0: s = arg.pop(0) if is_number(s): tshift = float(s) elif len(arg) > 0: tshift = float(arg.pop(0)) if len(arg) > 0: mshift = float(arg.pop(0)) print("Load {0} tshift={1} mshift={2}".format(fname, tshift, mshift)) # read data # tbl = read_table_header_float(fname) tbl, cols_data = read_obs_table_header( fname, include_names=band.band_get_names_alias(), is_out=is_debug, comments=comments) curves = table2curves(os.path.basename(fname), tbl) # remove bad data res_curves = SetLightCurve(curves.Name) for lc_orig in curves: is_good = lc_orig.Mag < mag_lim t = lc_orig.Time[is_good] m = lc_orig.Mag[is_good] e = None if lc_orig.IsErr: e = lc_orig.Err[is_good] lc = LightCurve(lc_orig.Band, t, m, e) res_curves.add(lc) res_curves.set_tshift(tshift) res_curves.set_mshift(mshift) return res_curves
def load(dic=None): """ Load points from dat-files. Reader data-file with mix bname data, like: >>% head photometry.txt jd filter mag mage 2457059.6228778586 V 17.493766309999998 0.0592200135089 2457059.6244578934 V 17.539956019999998 0.0542402986717 2457059.6261980557 g 17.782871193345898 0.0454000142503 2457059.6287036575 g 17.7782469177482 0.0395424488201 :return SetLightCurves: """ fname = None tshift = 0. mshift = 0. mag_lim = 30. skiprows = 1. arg = [] if dic is not None: mag_lim = dic.get('mag_lim', 30.) skiprows = dic.get('skiprows', 1) if 'args' in dic: arg = dic['args'] if len(arg) > 0: fname = arg.pop(0) fname = os.path.expanduser(fname) if len(arg) > 0: s = arg.pop(0) if s.isnumeric(): tshift = float(s) elif len(arg) > 0: tshift = float(arg.pop(0)) if len(arg) > 0: mshift = float(arg.pop(0)) print("Load {0} tshift={1} mshift={2}".format(fname, tshift, mshift)) # read data dtype = [('time', '<f4'), ('b', 'str'), ('mag', '<f4'), ('err', '<f4')] # lc_data = np.loadtxt(fname, skiprows=skiprows, dtype=dtype, comments='#') # jd filter mag mage # lc_data = np.genfromtxt(fname, skip_header=skiprows, dtype=dtype, comments='#') # jd filter mag mage lc_data = np.genfromtxt(fname, skip_header=skiprows, dtype=None, names=[v[0] for v in dtype], comments='#') b_tot = lc_data['b'] bnames = np.unique(b_tot) curves = SetLightCurve() for bname in bnames: if band.is_exist(bname.decode()): # filter of the current band d = lc_data[np.where(lc_data['b'] == bname)] # is_good = list(map(lambda x: x == bname, b_tot)) # t = (lc_data['time'])[is_good] # m = lc_data['mag'][is_good] # e = lc_data['err'][is_good] # add light curve b = band.band_by_name(bname.decode()) lc = LightCurve(b, d['time'], d['mag'], d['err']) # lc = LightCurve(b, t, m, e) curves.add(lc) else: print('Could read the light curve. There is no band: {}. ' 'You may try to add it to dir data/bands'.format(bname)) # remove bad data res_curves = SetLightCurve(curves.Name) for lc_orig in curves: is_good = lc_orig.Mag < mag_lim t = lc_orig.Time[is_good] m = lc_orig.Mag[is_good] e = None if lc_orig.IsErr: e = lc_orig.Err[is_good] lc = LightCurve(lc_orig.Band, t, m, e) res_curves.add(lc) res_curves.set_tshift(tshift) res_curves.set_mshift(mshift) return res_curves