def get_positioner_index(): # get obsXY data for each device pi = PositionerIndex() pi_df = pd.DataFrame(pi.data).set_index('DEVICE_ID') pi_df.columns = pi_df.columns.str.lower() pi_df.insert(0, 'device_id', pi_df.index) pi_df['obs_x'], pi_df['obs_y'] = np.nan, np.nan ptlXYZ_df = pd.read_csv(os.path.join( os.getenv('PLATE_CONTROL_DIR', '/software/products/plate_control-trunk'), 'petal', 'positioner_locations_0530v14.csv'), usecols=['device_location_id', 'X', 'Y', 'Z'], index_col='device_location_id') ptlXYZ_df.index.rename('device_loc', inplace=True) for pcid in range(10): trans = PetalTransforms(gamma=np.pi / 5 * (pcid - 3)) obsXY = trans.ptlXYZ_to_obsXYZ(ptlXYZ_df.T.values)[:2, :] xy_df = pd.DataFrame(data=obsXY.T, index=ptlXYZ_df.index, columns=['obs_x', 'obs_y']) xy_df['device_id'] = (pi_df[pi_df['petal_loc'] == pcid].set_index( 'device_loc')['device_id']) xy_df.set_index('device_id', inplace=True) xy_df = xy_df[xy_df.index.notnull()] pi_df.loc[xy_df.index, ['obs_x', 'obs_y']] = xy_df return pi_df
def verify_petal(): alignment = (pd.read_csv( os.path.join(data_dir, 'focal_plane_alignment_pm.csv')).set_index('PETAL_LOC')) data = (pd.read_csv(os.path.join(data_dir, 'fiducial-fvc.dat'), sep=r'\s+', skiprows=[1]).rename(columns={ '#LOC': 'id' }).set_index('id')) for i, row in data.iterrows(): petal_loc = i // 1000 params = alignment.loc[petal_loc] data.loc[i, 'petal_loc'] = petal_loc data.loc[i, 'offset_x'] = params['XPETAL(mm)'] data.loc[i, 'offset_y'] = params['YPETAL(mm)'] data.loc[i, 'rot_z'] = params['rot_proper(rad)'] trans = PetalTransforms(Tx=params['XPETAL(mm)'], Ty=params['YPETAL(mm)'], gamma=params['rot_proper(rad)']) QS = row.values.reshape(2, 1) obsXYZ = trans.QS_to_obsXYZ(QS).flatten() data.loc[i, 'obsX'] = obsXYZ[0] data.loc[i, 'obsY'] = obsXYZ[1] data.loc[i, 'obsZ'] = obsXYZ[2] ptlXYZ = trans.QS_to_ptlXYZ(QS).flatten() data.loc[i, 'ptlX'] = ptlXYZ[0] data.loc[i, 'ptlY'] = ptlXYZ[1] data.loc[i, 'ptlZ'] = ptlXYZ[2] fiducial = (pd.read_csv(os.path.join(data_dir, 'qst_fiducial.csv')).set_index('id')) for coord in ['x', 'y', 'z']: data[coord + '_cmm'] = fiducial[coord] data['d' + coord] = data['ptl' + coord.upper()] - data[coord + '_cmm'] data.to_csv(os.path.join(data_dir, 'qs_pm_verify.csv'))
def calculate_qst(alignment): trans = PetalTransforms(Tx=alignment[0], Ty=alignment[1], Tz=alignment[2], alpha=alignment[3], beta=alignment[4], gamma=alignment[5]) obsXYZ = trans.ptlXYZ_to_obsXYZ(data[['x', 'y', 'z']].values.T) data['obs_x'] = obsXYZ[0, :] data['obs_y'] = obsXYZ[1, :] data['obs_z'] = obsXYZ[2, :] QST = trans.obsXYZ_to_QST(obsXYZ) data['qst_q'] = QST[0, :] data['qst_s'] = QST[1, :] data['qst_t'] = QST[2, :] QS = trans.ptlXYZ_to_QS(data[['x', 'y', 'z']].values.T) data['q'], data['s'] = QS[0, :], QS[1, :] # data['dq_old_new'] = data['q_new'] - data['q_old'] # data['ds_old_new'] = data['s_new'] - data['s_old'] # data['dq_old'] = data['q_old'] - data['q_kent'] # data['ds_old'] = data['s_old'] - data['s_kent'] data['dq'] = data['q'] - data['q_kent_wrapped'] data['ds'] = data['s'] - data['s_kent'] # import pdb; pdb.set_trace() return np.sum(np.square(data[['dq', 'ds']].values))
def qst_petal(petal_id): data = pd.read_json(os.path.join(data_dir, f'petal{petal_id}.json'), orient='index') petal_loc = petal_locs[petal_id] data['id'] = petal_loc * 1000 + data['device_loc'] data = data.reset_index().set_index('id') for coord in ['x', 'y', 'z']: data[coord] = [d[coord] for d in data[fid_centre_def]] # initialise petal transformation using nominal configuration, 36 deg * n trans = PetalTransforms(gamma=np.pi / 5 * (petal_loc - 3)) if petal_id == 3: import pdb pdb.set_trace() QST = trans.ptlXYZ_to_QST(data[['x', 'y', 'z']].values.T) data['q'], data['s'], data['t'] = QST[0, :], QST[1, :], QST[2, :] return data
def initialise_data(): path = os.getenv('DOS_POSITIONERINDEXTABLE', '/software/products/PositionerIndexTable-trunk/index_files/desi_positioner_indexes_20190919.csv') pi_df = pd.read_csv(path) pi_df.columns = pi_df.columns.str.lower() # pi_df.set_index('device_id', inplace=True) ptlXYZ_df = pd.read_csv(pc.dirs['positioner_locations_file'], usecols=['device_loc', 'X', 'Y', 'Z'], index_col='device_loc') data_dfs = [] for petal_loc in petal_locs: # create nominal cenre for each petal petal_df = (pi_df[pi_df['petal_loc']==petal_loc] .set_index('device_loc').sort_index()) params = fp_alignment.loc[petal_loc] trans = PetalTransforms(Tx=params['XPETAL(mm)'], Ty=params['YPETAL(mm)'], gamma=params['rot_proper(rad)']) obsXY = trans.ptlXYZ_to_obsXY(ptlXYZ_df.loc[petal_df.index].T.values) petal_df['obsX_0'] = obsXY[0, :] petal_df['obsY_0'] = obsXY[1, :] data_dfs.append(petal_df) data = pd.concat(data_dfs)
def bright_image_spotmatch(bright_exp, i): path = os.path.join(fvc_img_dir, bright_exp+'.pos') pos = pd.read_csv(path, , index_col=0) # debug this columns = ['x', 'y', 'mag', 'id', 'fwhm'] pos.set_index('id', inplace=True) pxXY = pos[['x', 'y']] # for now, assume each fibre spot has a constant id in all exposures # need to match id to d QS = get_centroids(pxXY) # centroids in FVC pixel space to FP CS5 pos['q'], pos['s'] = QS[0, :], QS[1, :] obsXY = PetalTransforms.QS_to_obsXY(QS) # measured 5k obsXY of spots pos['obsX'], pos['obsY'] = obsXY[0, :], obsXY[1, :] for j, row in pos.iterrows(): # j is id in pos file dr = np.linalg.norm(data[['obsX_0', 'obsY_0']].values - row['obsX', 'obsY'].values, axis=1) idx = data.iloc[np.argmin(dr)].name # data index is unique device_id data.loc[idx, f'id_{i}'] = j # spotmatch id data.loc[idx, f'obsX_{i}'] = row['obsX'] data.loc[idx, f'obsY_{i}'] = row['obsY']
def __init__(self, refresh_interval=10): self.logger = logging.getLogger('FP Telemetry Monitor') self.logger.setLevel(logging.WARN) # log everything, DEBUG level up logpath = os.environ.get('DOS_FPPLOTS_LOGS', os.path.abspath('.')) log_path = os.path.join(logpath, 'fp_plots.log') open(log_path, 'a').close() fh = logging.FileHandler(log_path, mode='a', encoding='utf-8') fh.setFormatter( logging.Formatter( # log format for each line fmt='%(asctime)s %(name)s [%(levelname)-8s]: %(message)s', datefmt=pc.timestamp_format)) self.logger.addHandler(fh) self.logger.info('New FPMonitor intance...') self.pi = PositionerIndex() pi_df = pd.DataFrame(self.pi.data).set_index('DEVICE_ID') pi_df.columns = pi_df.columns.str.lower() pi_df.insert(0, 'device_id', pi_df.index) cols = [ 'spectro_sn', 'spectro_ln', 'time_recorded', 'temp', 'posfid_state', 'obs_x', 'obs_y', 'temp_color', 'line_color' ] dtypes = [ str, str, 'datetime64[ns]', np.float32, str, np.float32, np.float32, np.float32, np.float32, str ] data = {col: pd.Series(dtype=dt) for col, dt in zip(cols, dtypes)} # import pdb; pdb.set_trace() self.data = pi_df.join(pd.DataFrame(data=data)) # add dummy centre cap ring so data won't be all NaN or bokeh crashes # self.data.loc['centre cap ring', ['device_loc', 'device_type', 'temp_color', 'line_color']] = -1, 'centre cap ring', 0, 'white' # self.data.loc['centre cap ring', ''] = 0 # self.data.loc['centre cap ring', 'line_color'] = 'white' # create masks for pos and fid self.posmask = ((self.data['device_type'] == 'POS') | (self.data['device_type'] == 'ETC')) self.fidmask = ((self.data['device_type'] == 'GIF') | (self.data['device_type'] == 'FIF')) self.data.loc[self.posmask, 'line_color'] = 'white' self.data.loc[self.fidmask, 'line_color'] = 'green' # add obsXYZ positions to data for plotting path = os.path.join( os.getenv('PLATE_CONTROL_DIR', '/software/products/plate_control-trunk'), 'petal', 'positioner_locations_0530v18.csv') ptlXYZ_df = pd.read_csv(path, usecols=['device_location_id', 'X', 'Y', 'Z'], index_col='device_location_id') ptlXYZ_df.index.rename('device_loc', inplace=True) self.data_status = pd.DataFrame(data={ 'x': 21.5 + 9.5 * (np.arange(len(self.status_colors.keys())) // 9), 'y': np.power( 10, 2 - 0.17 * (np.arange(len(self.status_colors.keys())) % 9)) }, index=FPMonitor.status_colors.keys()) self.data_status.index.rename('status_field', inplace=True) for petal_loc in self.petal_locs: trans = PetalTransforms(gamma=np.pi / 5 * (petal_loc - 3)) obsXY = trans.ptlXYZ_to_obsXYZ(ptlXYZ_df.T.values)[:2, :] xy_df = pd.DataFrame(data=obsXY.T, index=ptlXYZ_df.index, columns=['obs_x', 'obs_y']) xy_df['device_id'] = ( self.data[self.data['petal_loc'] == petal_loc].set_index( 'device_loc')['device_id']) xy_df.set_index('device_id', inplace=True) xy_df = xy_df[xy_df.index.notnull()] self.data.loc[xy_df.index, ['obs_x', 'obs_y']] = xy_df # add spectro serial and logical numbers for each petal location self.data.loc[self.data['petal_loc'] == petal_loc, 'spectro_sn'] = self.spectro_sns[petal_loc] self.data.loc[self.data['petal_loc'] == petal_loc, 'spectro_ln'] = self.spectro_lns[petal_loc] # pc telemetry status data self.data_status[f'val_{petal_loc}'] = np.nan self.data_status[f'color_{petal_loc}'] = 'grey' self.source = ColumnDataSource(self.data) self.source_status = ColumnDataSource(self.data_status) # self.delta_t = timedelta(seconds=refresh_interval) # self.last_updated = pc.now() - self.delta_t # load past 5 min and use the latest readout self.update_data_and_sources(update_hist=False)
orient='index') nonintact = df[df['FIBER_INTACT'] == False] # all nonintact nonintact = nonintact[nonintact.index.isin( pc.index)] # filter out specified pc nonintact = pc.loc[nonintact.index] print(nonintact) # plot nonintact positioners path = os.path.join( os.getenv('PLATE_CONTROL_DIR', '/software/products/plate_control-trunk'), 'petal', 'positioner_locations_0530v14.csv') ptlXYZ = pd.read_csv(path, usecols=['device_location_id', 'X', 'Y', 'Z'], index_col='device_location_id') ptlXYZ.index.rename('DEVICE_LOC', inplace=True) trans = PetalTransforms(gamma=np.pi / 5 * (pcid - 3)) obsXY = trans.ptlXYZ_to_obsXYZ(ptlXYZ.values.T).T[:, :2] xy = pd.DataFrame(obsXY, index=ptlXYZ.index, columns=['obsX', 'obsY']) xy['fvcX'] = -xy['obsX'] xy['fvcY'] = xy['obsY'] nonintact = nonintact.merge(xy, how='left', left_on='DEVICE_LOC', right_index=True) fig, ax = plt.subplots() ax.plot(xy['fvcX'], xy['fvcY'], 'o') ax.plot(nonintact['fvcX'], nonintact['fvcY'], 'rx') for device_id, row in nonintact.iterrows(): ax.annotate(f'{device_id} ({row.DEVICE_LOC})', xy=(row.fvcX, row.fvcY), xytext=(0, -5),