def test_to_astropy_time(): from fact.coordinates.utils import to_astropy_time t = Time('2013-01-01 00:00') assert to_astropy_time(datetime(2013, 1, 1)) == t assert to_astropy_time(pd.Timestamp(t.unix * 1e9)) == t assert to_astropy_time(pd.to_datetime('2013-01-01 00:00')) == t assert to_astropy_time(np.array('2013-01-01 00:00', dtype='datetime64[ns]')) == t
def calc_delta_delta(event, mask): # if 'source_position_zd' not in df.columns: frame = AltAz(location=LOCATION, obstime=to_astropy_time( pd.to_datetime(event.observation_info.time))) crab_altaz = crab.transform_to(frame) source_position_zd_phs = crab_altaz.zen.deg source_position_az_phs = crab_altaz.az.deg source_x, source_y = horizontal_to_camera( source_position_zd_phs, source_position_az_phs, event.zd, event.az, ) # safe x, y and t components of Photons. shape = (#photons,3) xyt = event.photon_stream.point_cloud lol = event.photon_stream.list_of_lists x, y, t = xyt.T x = np.rad2deg(x) / camera_distance_mm_to_deg(1) y = np.rad2deg(y) / camera_distance_mm_to_deg(1) cleaned_photons = np.zeros(len(x), dtype=bool) for i in range(len(lol)): if mask[i]: for j in range(len(lol[i])): cleaned_photons[i] = True cog_x = np.mean(x[cleaned_photons]) cog_y = np.mean(y[cleaned_photons]) true_delta = np.arctan2(cog_y - source_y, cog_x - source_x) delta = calc_delta(phs2image(event.photon_stream.list_of_lists), mask) delta_delta = true_delta - delta if delta_delta < -np.pi / 2: delta_delta += 2 * np.pi # if delta_delta < -90: # delta_delta += 360 return delta_delta
facttools.set_index(['run_id', 'event_num', 'night'], inplace=True) df = phs.join( facttools, how='inner', rsuffix='_std', lsuffix='_phs', on=('run', 'event', 'night'), ) df.sort_index(axis=1, inplace=True) if args.threshold: phs = phs.query(f'gamma_prediction >= {args.threshold}').copy() if 'source_position_zd' not in df.columns: frame = AltAz(location=LOCATION, obstime=to_astropy_time(pd.to_datetime(df['timestamp']))) crab = SkyCoord.from_name('Crab Nebula') crab_altaz = crab.transform_to(frame) df['source_position_zd_phs'] = crab_altaz.zen.deg df['source_position_az_phs'] = crab_altaz.az.deg df['source_x'], df['source_y'] = horizontal_to_camera( df['source_position_zd'], df['source_position_az'], df['pointing_position_zd_phs'], df['pointing_position_az_phs'], ) df['true_delta'] = np.arctan2(df['cog_y_phs'] - df['source_y'],
parser = ArgumentParser() parser.add_argument('inputfile') parser.add_argument('-o', '--outputfile') parser.add_argument('-t', '--threshold', type=float) args = parser.parse_args() print("Reading in data...") df = read_data(args.inputfile, key='events') print("Done!") if args.threshold: df = df.query(f'gamma_prediction >= {args.threshold}').copy() if 'source_position_zd' not in df.columns: frame = AltAz(location=LOCATION, obstime=to_astropy_time(pd.to_datetime(df['timestamp']))) crab = SkyCoord.from_name('Crab') crab_altaz = crab.transform_to(frame) df['source_position_zd'] = crab_altaz.zen.deg df['source_position_az'] = crab_altaz.az.deg df['source_x'], df['source_y'] = horizontal_to_camera( df['source_position_zd'], df['source_position_az'], df['pointing_position_zd'], df['pointing_position_az'], ) df['true_delta'] = np.arctan2(df['cog_y'] - df['source_y'], df['cog_x'] - df['source_x'])