def galaxies_data(dateobs): event = models.Event.query.get_or_404(dateobs) table = catalogs.galaxies.copy() # Populate 2D and 3D credible levels. localization_name = request.args.get('search[value]') localization = (models.Localization.query.filter_by( dateobs=event.dateobs, localization_name=localization_name).one_or_none() or event.localizations[-1]) results = find_injection_moc(localization.table, table['ra'].to(u.rad).value, table['dec'].to(u.rad).value, table['distmpc'].to(u.Mpc).value) table['2D CL'][:] = np.ma.masked_invalid(results.searched_prob) * 100 table['3D CL'][:] = np.ma.masked_invalid(results.searched_prob_vol) * 100 table['2D pdf'][:] = np.ma.masked_invalid(results.probdensity) table['3D pdf'][:] = np.ma.masked_invalid(results.probdensity_vol) result = {} # Populate total number of records. result['recordsTotal'] = len(table) # Populate draw counter. try: value = int(request.args['draw']) except KeyError: pass except ValueError: abort(400) else: result['draw'] = value for i in range(len(table.columns)): try: value = json.loads( request.args['columns[{}][search][value]'.format(i)] or '{}') except (KeyError, ValueError): pass else: try: value2, = np.asarray([value['min']], dtype=table[table.colnames[i]].dtype) except KeyError: pass except ValueError: abort(400) else: table = table[table[table.colnames[i]] >= value2] try: value2, = np.asarray([value['max']], dtype=table[table.colnames[i]].dtype) except (KeyError, ValueError): pass else: table = table[table[table.colnames[i]] <= value2] try: value = int(request.args['order[{}][column]'.format(i)]) except (KeyError, ValueError): pass else: table.sort(table.colnames[value]) try: value = request.args['order[{}][dir]'.format(i)] except (KeyError, ValueError): pass else: if value == 'desc': table.reverse() # Populate total number of filtered records. result['recordsFiltered'] = len(table) # Trim results by requested start index. try: value = int(request.args['start']) except KeyError: pass except ValueError: abort(400) else: table = table[value:] # Trim results by requested length. try: value = int(request.args['length']) except KeyError: pass except ValueError: abort(400) else: table = table[:value] result['data'] = list( zip(*((None if item == '--' else item for item in table.formatter._pformat_col_iter(column, max_lines=-1, show_name=False, show_unit=False, outs={})) for column in table.columns.values()))) return jsonify(result)
def objects_data(dateobs): event = models.Event.query.get_or_404(dateobs) table = Table(rows=[(*(_getattr_or_masked(row, key) for key in OBJECTS_COLUMNS[:-2]), np.ma.masked, np.ma.masked) for row in models.Candidate.query], names=OBJECTS_COLUMNS) # Populate 2D and 3D credible levels. localization_name = request.args.get('search[value]') localization = (models.Localization.query.filter_by( dateobs=event.dateobs, localization_name=localization_name).one_or_none() or event.localizations[-1]) results = find_injection_moc(localization.table, np.deg2rad(table['ra']), np.deg2rad(table['dec'])) table['2D CL'] = np.ma.masked_invalid(results.searched_prob) * 100 table['2D pdf'] = np.ma.masked_invalid(results.probdensity) # Make first detection time column filterable table['first_detection_time'] = table['first_detection_time'].astype(str) result = {} # Populate total number of records. result['recordsTotal'] = len(table) # Populate draw counter. try: value = int(request.args['draw']) except KeyError: pass except ValueError: abort(400) else: result['draw'] = value for i in range(len(table.columns)): try: value = json.loads( request.args['columns[{}][search][value]'.format(i)] or '{}') except (KeyError, ValueError): pass else: try: value2, = np.asarray([value['min']], dtype=table[table.colnames[i]].dtype) except KeyError: pass except ValueError: abort(400) else: table = table[table[table.colnames[i]] >= value2] try: value2, = np.asarray([value['max']], dtype=table[table.colnames[i]].dtype) except (KeyError, ValueError): pass else: table = table[table[table.colnames[i]] <= value2] try: value = int(request.args['order[{}][column]'.format(i)]) except (KeyError, ValueError): pass else: table.sort(table.colnames[value]) try: value = request.args['order[{}][dir]'.format(i)] except (KeyError, ValueError): pass else: if value == 'desc': table.reverse() # Populate total number of filtered records. result['recordsFiltered'] = len(table) # Trim results by requested start index. try: value = int(request.args['start']) except KeyError: pass except ValueError: abort(400) else: table = table[value:] # Trim results by requested length. try: value = int(request.args['length']) except KeyError: pass except ValueError: abort(400) else: table = table[:value] result['data'] = list( zip(*((None if item == '--' else item for item in table.formatter._pformat_col_iter(column, max_lines=-1, show_name=False, show_unit=False, outs={})) for column in table.columns.values()))) return jsonify(result)