def test_named(): frb121102 = FRB('FRB121102', 'J053158.7+330852.5', 558.1 * units.pc / units.cm**3, z_frb=0.19273) # Error ellipse frb121102.set_ee(0.1, 0.1, 0., 95.) assert isinstance(frb121102.eellipse, dict) # Pulse -- These are made up frb121102.set_pulse(1 * units.GHz, time_res=0.054 * units.ms, t0=0.66 * units.ms, Wi=1.1 * units.ms, tscatt=0.041 * units.ms, tscatt_err=0.002 * units.ms, scatt_index=-3.84, scatt_index_err=0.77) assert np.isclose(frb121102.pulse['freq'].value, 1.) # Test writing frb121102.write_to_json() assert np.isclose(frb121102.pulse['freq'].value, 1.) # Test load tst = FRB.from_json('FRB121102.json') assert np.isclose(tst.pulse['freq'].value, 1.)
def test_named(): frb121102 = FRB('FRB121102', 'J053158.7+330852.5', 558.1 * units.pc / units.cm**3, z_frb=0.19273) # Error ellipse frb121102.set_ee(0.1, 0.1, 0., 95.) assert isinstance(frb121102.eellipse, dict) # Test writing frb121102.write_to_json() # Test load tst = FRB.from_json('FRB121102.json') # By name tst = FRB.by_name('FRB121102')
def run(frb_input: pandas.core.series.Series, lit_refs: str = None, override: bool = False, out_path: str = None, outfile: str = None): """Main method for generating a Host JSON file Args: frb_input (pandas.core.series.Series): Row of the CVS file providing the frb items lit_refs (str, optional): File of literature references. Defaults to None. override (bool, optional): Attempt to over-ride errors. Mainly for time-outs of public data. Defaults to False. outfile (str, optional): Over-ride default outfile [not recommended; mainly for testing] out_path (str, optional): Over-ride default outfile [not recommended; mainly for testing] Raises: e: [description] ValueError: [description] """ print("--------------------------------------") print(f"Building FRB JSON file for {frb_input.Name}") # Instantiate ifrb = FRB(frb_input.Name, (frb_input.ra, frb_input.dec), frb_input.DM * units.pc / units.cm**3, z_frb=frb_input.z if np.isfinite(frb_input.z) else None, repeater=frb_input.repeater) # DM_err if np.isfinite(frb_input['DM_err']): ifrb.DM_err = frb_input.DM_err * units.pc / units.cm**3 # RM for key in ['RM', 'RM_err']: if np.isfinite(frb_input[key]): setattr(ifrb, key, frb_input[key] * units.rad / units.m**2) # Fluence for key in ['fluence', 'fluence_err']: if np.isfinite(frb_input[key]): setattr(ifrb, key, frb_input[key] * units.Jy * units.ms) # Error ellipse ifrb.set_ee(a=frb_input.ee_a, b=frb_input.ee_b, theta=frb_input.ee_theta, cl=68.) if np.isfinite(frb_input.ee_a_sys): ifrb.set_ee(a=frb_input.ee_a_sys, b=frb_input.ee_b_sys, theta=frb_input.ee_theta, cl=68., stat=False) # Add DM_ISM from NE2001 ifrb.set_DMISM() # Refs ifrb.refs = frb_input.refs.split(',') # Pulses path = os.path.join(resource_filename('frb', 'data'), 'FRBs') tbl_file = os.path.join(path, 'FRB_pulses.csv') frb_pulses = pandas.read_csv(tbl_file) idx = np.where(frb_pulses.Name == frb_input.Name)[0] if len(idx) == 1: frb_pulse = frb_pulses.iloc[idx[0]] # Pulse properties pulse_dict = {} # Width and scattering for key in ['Wi', 'Wi_err', 'tscatt', 'tscatt_err']: if np.isfinite(frb_pulse[key]): pulse_dict[key] = frb_pulse[key] * units.ms ifrb.set_pulse(frb_pulse.freq * units.GHz, **pulse_dict) # References prefs = frb_pulse.refs.split(',') for pref in prefs: if pref not in ifrb.refs: ifrb.refs.append(pref) # Write if out_path is None: out_path = os.path.join(resource_filename('frb', 'data'), 'FRBs') ifrb.write_to_json( path=out_path ) #'/home/xavier/Projects/FRB_Software/FRB/frb/tests/files')