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 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 __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)
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), textcoords='offset points')