def _set_orderby_desc(self, query, model, limit, last_id, offset, descending, orderby): """Return an updated query with the proper orderby and desc.""" if orderby == 'fav_user_ids': n_favs = func.coalesce(func.array_length(model.fav_user_ids, 1), 0).label('n_favs') query = query.add_column(n_favs) if orderby in ['created', 'updated', 'finish_time']: if descending: query = query.order_by(desc( cast(getattr(model, orderby), TIMESTAMP))) else: query = query.order_by(cast(getattr(model, orderby), TIMESTAMP)) else: if orderby != 'fav_user_ids': if descending: query = query.order_by(desc(getattr(model, orderby))) else: query = query.order_by(getattr(model, orderby)) else: if descending: query = query.order_by(desc(text("n_favs"))) else: query = query.order_by(text("n_favs")) if last_id: query = query.limit(limit) else: query = query.limit(limit).offset(offset) return query
def get_paras(entries_q, profile_id=None): CE, CU = CacheEntry, CacheUser entries = entries_q.join(CE, CE.entry_id == Entry.id) \ .filter(func.array_length(CE.paras,1)>0) \ .with_entities(CE.paras).all() paras = [p for e in entries for p in e.paras if e.paras] if profile_id: profile = db.session.query(CU) \ .filter(func.array_length(CU.paras,1)>0, CU.user_id == profile_id) \ .with_entities(CU.paras) \ .first() if profile: paras = profile.paras + paras return paras
def _set_orderby_desc(self, query, model, limit, last_id, offset, descending, orderby): """Return an updated query with the proper orderby and desc.""" if orderby == 'fav_user_ids': n_favs = func.coalesce(func.array_length(model.fav_user_ids, 1), 0).label('n_favs') query = query.add_column(n_favs) if orderby in ['created', 'updated', 'finish_time']: if descending: query = query.order_by(desc( cast(getattr(model, orderby), TIMESTAMP))) else: query = query.order_by(cast(getattr(model, orderby), TIMESTAMP)) else: if orderby != 'fav_user_ids': if descending: query = query.order_by(desc(getattr(model, orderby))) else: query = query.order_by(getattr(model, orderby)) else: if descending: query = query.order_by(desc("n_favs")) else: query = query.order_by("n_favs") if last_id: query = query.limit(limit) else: query = query.limit(limit).offset(offset) return query
def get_profiles(): error, verification_token = get_token(request.headers) if error: return error query = request.args.get('query') verification_email_id = VerificationToken.query.filter( VerificationToken.token == verification_token.token).value( VerificationToken.email_id) return jsonify( profiles_schema.dump( matching_profiles(query).order_by( # Is this the logged-in user's profile? If so, return it first (false) Profile.verification_email_id != verification_email_id, # Get the last word in the name. # Won't work with suffixes. func.split_part( Profile.name, ' ', func.array_length( func.string_to_array( func.regexp_replace( Profile.name, '(,|MD).*', ''), # Remove suffixes after comma and MD ' '), 1 # How many words in the name )))))
def themes(eids, algo='agglomorative'): logger.info("Themes") with session() as sess: # use Model to decrypt fields E, CE = M.Entry, M.CacheEntry res = sess.query(CE) \ .with_entities(CE.paras, CE.clean, CE.vectors) \ .join(E, E.id == CE.entry_id) \ .filter(E.id.in_(eids), func.array_length(CE.vectors,1)>0) \ .order_by(E.created_at.desc()) \ .all() # assert len(eids) == len(res) entries = pd.Series([e for r in res for e in r.paras]) stripped = pd.Series([c for r in res for c in r.clean]) vecs = np.vstack([r.vectors for r in res]).astype(np.float32) chain = Similars(vecs) if False and os.path.exists(vars.AE_PATH): chain = chain.autoencode(filename=vars.AE_PATH).cluster(algo=algo) else: chain = chain.normalize().cluster(algo=algo) clusters = chain.value() labels = chain.data.labels topics = [] for l, center in enumerate(clusters): mask = labels == l n_entries = mask.sum().item() print('n_entries', n_entries) if n_entries < 2: print('skipping') continue vecs_, stripped_, entries_ = vecs[mask], stripped[mask], entries[mask] dists = Similars(center, vecs_).normalize().cosine(abs=True).value().squeeze() entries_ = entries_.iloc[dists.argsort()].tolist()[:5] terms = top_terms(stripped_.tolist()) topics.append({ 'n_entries': n_entries, 'terms': terms, 'summary': entries_, # add full thing, will batch-compute next 'sentiment': None, }) groups = [t['summary'] for t in topics] batch_summaries = nlp_.summarization(groups, min_length=50, max_length=300) for i, res in enumerate(batch_summaries): print(res) topics[i]['summary'] = res['summary'] topics[i]['sentiment'] = res['sentiment'] topics = {'terms': top_terms(stripped, 10), 'themes': topics} return topics
def sampling_figure(prefix="plots"): matplotlib.rcParams["axes.labelsize"] = 40 matplotlib.rcParams["xtick.labelsize"] = 26 xmin = 0. radecs = [] level = 0. fig = plt.figure(figsize=(15, 15)) ax = fig.add_subplot(111) for ii in range(100): lightCurves = session.query(LightCurve).filter( func.array_length(LightCurve.mjd, 1) > 100).limit(100).all() if level >= 10: break for lc in lightCurves: if (max(lc.mjd) - min(lc.mjd)) > 365: next_lc = False for radec in radecs: try: sep = g.subtends(lc.ra, lc.dec, radec[0], radec[1], units="degrees") except ValueError: next_lc = True if sep < 5.: next_lc = True if next_lc: continue else: radecs.append((lc.ra, lc.dec)) #ax.errorbar(lc.Rmjd, lc.Rmag, lc.Rerror, ls='none', marker='o', c='k', ecolor='0.7', capsize=0) ax.plot(lc.Rmjd, [level] * len(lc.Rmjd), marker='o', ms=20.0, c='k', ls='none', alpha=0.3) if xmin == 0: xmin = min(lc.Rmjd) ax.set_xlim(xmin, xmin + 365) level += 1 ymin, ymax = ax.get_ylim() ydel = ymax - ymin ax.set_ylim(ymin - ydel / 10., ymax + ydel / 10.) ax.set_xlabel("MJD") ax.set_yticklabels([]) plt.savefig(os.path.join(prefix, "ptf_sampling_figure.pdf"))
def register_about_page_navbar_links(): """Generate all about page titles and URLs for use in the navbar.""" # NOTE: Because of the unconventional usage of Flask-Copilot # (i.e. not as a routing decorator and always assigning an # endpoint), our shorter navbar_paths must come before longer # ones. for page in AboutPage.query.current.filter_by(active=True).order_by( func.array_length(AboutPage.navbar_path, 1)): copilot.register_entry({ 'path': page.navbar_path, 'endpoint': 'about.rst_content', 'url_for_kwargs': {'slug': page.slug}, })
def numero_differe_view(request): """ get numero_differe """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() role = request.params['role'] if 'role' in request.params else None num_agg = func.array_agg(VNumeros.numero, type_=ARRAY(Integer)).label('numero') diff_id_agg = func.array_agg(VNumeros.diff_id, type_=ARRAY(Integer)).label('numero_id') query = request.dbsession.query(VNumeros.diff_affaire_id.label('diff_affaire_id'), VNumeros.cadastre.label('cadastre'), num_agg, diff_id_agg, func.min(VNumeros.diff_entree).label('diff_entree_min')) if role == "mo": user_id = request.params['user_id'] if 'user_id' in request.params else None affaires = request.dbsession.query(Affaire, VNumeros) if user_id is not None: affaires = affaires.filter(Affaire.technicien_id == user_id) affaires = affaires.filter(Affaire.id == VNumeros.diff_affaire_id).all() affaires_id = [aff.Affaire.id for aff in affaires] query = query.filter(and_( VNumeros.diff_entree.isnot(None), VNumeros.diff_sortie == None, VNumeros.diff_affaire_id.in_(affaires_id) )) elif role == "secr": query = query.filter(and_( VNumeros.diff_req_radiation.isnot(True), VNumeros.diff_sortie.isnot(None) )) result = query.group_by(VNumeros.diff_affaire_id, VNumeros.cadastre).having(func.array_length(num_agg, 1) > 0).all() numeros = [] for num in result: numeros.append({ 'diff_affaire_id': num[0], 'cadastre': num[1], 'numero': num[2], 'diff_id': num[3], 'diff_entree': datetime.strftime(num[4], '%Y-%m-%d') }) return json.dumps(numeros)
def register_about_page_navbar_links(): """Generate all about page titles and URLs for use in the navbar.""" # NOTE: Because of the unconventional usage of Flask-Copilot # (i.e. not as a routing decorator and always assigning an # endpoint), our shorter navbar_paths must come before longer # ones. for page in AboutPage.query.current.filter_by(active=True).order_by( func.array_length(AboutPage.navbar_path, 1)): copilot.register_entry({ 'path': page.navbar_path, 'endpoint': 'about.rst_content', 'url_for_kwargs': { 'slug': page.slug }, })
def get_profiles(): error, verification_token = get_token(request.headers) if error: return error query = request.args.get('query') degrees = request.args.get('degrees', '') affiliations = request.args.get('affiliations', '') page = int(request.args.get('page', 1)) start, end = pagination(page) verification_email_id = VerificationToken.query.filter( VerificationToken.token == verification_token.token).value( VerificationToken.email_id) queryset = ( matching_profiles(query, degrees, affiliations).order_by( # Is this the logged-in user's profile? If so, return it first (false) Profile.verification_email_id != verification_email_id, # Get the last word in the name. # Won't work with suffixes. func.split_part( Profile.name, ' ', func.array_length( func.string_to_array( func.regexp_replace( Profile.name, '(,|MD).*', ''), # Remove suffixes after comma and MD ' ', ), 1, # How many words in the name ), ), ).group_by(Profile.id)) return jsonify({ 'profileCount': queryset.count(), 'profiles': profiles_schema.dump(queryset[start:end]), })
def sampling_figure(prefix="plots"): matplotlib.rcParams["axes.labelsize"] = 40 matplotlib.rcParams["xtick.labelsize"] = 26 xmin = 0. radecs = [] level = 0. fig = plt.figure(figsize=(15,15)) ax = fig.add_subplot(111) for ii in range(100): lightCurves = session.query(LightCurve).filter(func.array_length(LightCurve.mjd, 1) > 100).limit(100).all() if level >= 10: break for lc in lightCurves: if (max(lc.mjd) - min(lc.mjd)) > 365: next_lc = False for radec in radecs: try: sep = g.subtends(lc.ra, lc.dec, radec[0], radec[1], units="degrees") except ValueError: next_lc = True if sep < 5.: next_lc = True if next_lc: continue else: radecs.append((lc.ra, lc.dec)) #ax.errorbar(lc.Rmjd, lc.Rmag, lc.Rerror, ls='none', marker='o', c='k', ecolor='0.7', capsize=0) ax.plot(lc.Rmjd, [level]*len(lc.Rmjd), marker='o', ms=20.0, c='k', ls='none', alpha=0.3) if xmin == 0: xmin = min(lc.Rmjd) ax.set_xlim(xmin, xmin+365) level += 1 ymin, ymax = ax.get_ylim() ydel = ymax-ymin ax.set_ylim(ymin-ydel/10., ymax+ydel/10.) ax.set_xlabel("MJD") ax.set_yticklabels([]) plt.savefig(os.path.join(prefix, "ptf_sampling_figure.pdf"))
def count_by_group(self): """ Returns the total number of notices by groups. Returns a tuple ``(group name, number of notices)`` for each group. Filters by the state of the collection. """ result = self.session.query(UserGroup.name, GazetteNotice._issues.keys()) result = result.filter( GazetteNotice.group_id == UserGroup.id, func.array_length(GazetteNotice._issues.keys(), 1) != 0) if self.state: result = result.filter(GazetteNotice.state == self.state) if self.issues: result = result.filter(GazetteNotice._issues.has_any(self.issues)) result = result.order_by(UserGroup.name) issues = set(self.issues or []) operation = issues.intersection if issues else issues.union return [(group[0], sum([len(operation(set(x[1]))) for x in group[1]])) for group in groupbylist(result, lambda a: a[0])]
def get_ordering(sorting): last_name_sorting = func.split_part( profile_class.name, " ", func.array_length( func.string_to_array(profile_class.name, " "), 1, # Length in the 1st dimension ), ) sort_options = { "starred": [ desc(text("profile_star_count")), desc(profile_class.date_updated), ], "last_name_alphabetical": [asc(last_name_sorting)], "last_name_reverse_alphabetical": [desc(last_name_sorting)], "date_updated": [desc(profile_class.date_updated)], } if sorting not in sort_options: raise InvalidPayloadError({"sorting": ["invalid"]}) return sort_options[sorting]
def has_synonyms(query: Query) -> Query: return query.filter(func.array_length(VocabularyTerm.french, 1) > 1)
def api_v1_get_replays(): if 'key' in request.args: api_key = request.args['key'] else: api_key = None args = request.args print(args) if 'page' not in args: page = 0 else: page = int(args['page']) - 1 if page < 0: page = 0 session = current_app.config['db']() games = session.query(Game) # RANK STUFF if 'rankany' in args: rank_opt = 'any' else: rank_opt = 'all' if 'maxrank' in args: games = games.filter( getattr(Game.ranks, rank_opt)(int(args['maxrank']), operator=operators.ge)) if 'minrank' in args: games = games.filter( getattr(Game.ranks, rank_opt)(int(args['minrank']), operator=operators.le)) any_rank_modifier = ['minrank', 'maxrank'] if any([m in args for m in any_rank_modifier]): games = games.filter(func.array_length(Game.ranks, 1) > 0) # MMR stuff if 'mmrany' in args: mmr_opt = 'any' else: mmr_opt = 'all' if 'maxmmr' in args: games = games.filter( getattr(Game.mmrs, mmr_opt)(int(args['maxmmr']), operator=operators.ge)) if 'minmmr' in args: games = games.filter( getattr(Game.mmrs, mmr_opt)(int(args['minmmr']), operator=operators.le)) any_mmr_modifier = ['maxmmr', 'minmmr'] if any([m in args for m in any_mmr_modifier]): games = games.filter(func.array_length(Game.mmrs, 1) > 0) # USER stuff if 'user' in args: games = games.filter(Game.players.any(args['user'])) # YEAR stuff if 'year' in args: games = games.filter( Game.match_date > datetime.date(int(args['year']), 1, 1)).filter( Game.match_date < datetime.date(int(args['year']) + 1, 1, 1)) # GAME stuff if 'map' in args: games = games.filter(Game.map == args['map']) if 'teamsize' in args: games = games.filter(Game.teamsize == int(args['teamsize'])) pagesize = 50 if 'num' in args: pagesize = int(args['num']) response = {} data = [] games = games[page * pagesize:(page + 1) * pagesize] game: Game for game in games: data.append({ 'team_blue_score': game.team0score, 'team_orange_score': game.team1score, 'match_date': game.match_date, 'upload_date': game.upload_date, 'map': game.map, 'matchtype': game.matchtype, 'teamsize': game.teamsize, 'hash': game.hash, 'link': url_for('replays.view_replay', id_=game.hash), 'download': url_for('replays.download_replay', id_=game.hash), 'info': url_for('apiv1.api_v1_get_replay_info', id_=game.hash, key=api_key), 'mmrs': game.mmrs, 'ranks': game.ranks, 'players': game.players }) response['data'] = data response['page'] = page + 1 response['next'] = url_for('apiv1.api_v1_get_replays', page=page + 2, key=api_key) response['version'] = 1 session.close() return jsonify(response)
) temp_radgroupreply = as_copy(radgroupreply, 'temp_radgroupreply') radpostauth = Table( 'radpostauth', metadata, Column('Id', BigInteger, primary_key=True, nullable=False), Column('UserName', Text, nullable=False), Column('NASIPAddress', IPAddress, nullable=False), Column('NASPortId', Text), Column('PacketType', Text, nullable=False), Column('Groups', TupleArray(Text, dimensions=1)), Column('Reply', TupleArray(Text, dimensions=2)), Column('AuthDate', DateTime(timezone=True), nullable=False), CheckConstraint(func.array_ndim("Groups") == 1), CheckConstraint(func.array_ndim("Reply") == 2 and func.array_length("Reply", 2) == 2), ) radreply = Table( 'radreply', metadata, Column('Priority', Integer, nullable=False), Column('UserName', Text, nullable=False), Column('NASIPAddress', IPAddress, nullable=False), Column('NASPortId', Text, nullable=False), Column('Attribute', Text, nullable=False), Column('Op', String(2), default='=', nullable=False), Column('Value', Text, nullable=False), UniqueConstraint('UserName', 'NASIPAddress', 'NASPortId', 'Priority'), ) temp_radreply = as_copy(radreply, 'temp_radreply')
def bad_data_figure(prefix="plots"): matplotlib.rcParams["axes.titlesize"] = 40 matplotlib.rcParams["axes.labelsize"] = 40 matplotlib.rcParams["xtick.labelsize"] = 20 matplotlib.rcParams["ytick.labelsize"] = 20 lightCurve1 = session.query(LightCurve).filter( LightCurve.objid == 14688560553413090141).one() lightCurve2 = session.query(LightCurve).filter( LightCurve.objid == 14688560553413090134).one() print "Distance between objects: {0}\"".format( g.subtends(lightCurve1.ra, lightCurve1.dec, lightCurve2.ra, lightCurve2.dec, units="degrees") * 3600.) medMag1 = np.median(lightCurve1.mag) medMag2 = np.median(lightCurve2.mag) fig = plt.figure(figsize=(20, 25)) fig.subplots_adjust(hspace=0.2, left=0.1) ax1 = fig.add_subplot(211) ax1.errorbar(lightCurve1.mjd, lightCurve1.mag, lightCurve1.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax2 = fig.add_subplot(212) ax2.errorbar(lightCurve2.mjd, lightCurve2.mag, lightCurve2.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax1.set_ylim(medMag1 - 0.5, medMag1 + 0.5) ax1.set_ylim(ax1.get_ylim()[::-1]) ax1.set_xlim(55000, 56000) ax1.set_ylabel(r"$R$") ax1.set_xticklabels([]) ax1.set_title("objid: {0}".format(lightCurve1.objid)) ax2.set_ylim(medMag2 - 0.5, medMag2 + 0.5) ax2.set_ylim(ax2.get_ylim()[::-1]) ax2.set_xlim(55000, 56000) ax2.set_ylabel(r"$R$") ax2.set_xlabel("MJD") ax2.set_title("objid: {0}".format(lightCurve2.objid)) plt.savefig(os.path.join(prefix, "bad_data_figure.pdf")) return # Code below is to search for light curves that are similar while True: lightCurve1 = session.query(LightCurve).filter( func.array_length(LightCurve.mjd, 1) > 200).order_by( func.random()).limit(1).one() lightCurve2 = session.query(LightCurve).filter(func.array_length(LightCurve.mjd, 1) > 200).\ filter(func.q3c_radial_query(LightCurve.ra, LightCurve.dec, lightCurve1.ra, lightCurve1.dec, 60./3600.)).\ order_by(func.random()).limit(1).one() medMag1 = np.median(lightCurve1.mag) medMag2 = np.median(lightCurve2.mag) if medMag1 > 17 or medMag2 > 17: continue fig = plt.figure(figsize=(20, 25)) fig.subplots_adjust(hspace=0.3, left=0.1) ax1 = fig.add_subplot(211) ax1.errorbar(lightCurve1.mjd, lightCurve1.mag, lightCurve1.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax2 = fig.add_subplot(212) ax2.errorbar(lightCurve2.mjd, lightCurve2.mag, lightCurve2.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax1.set_ylim(medMag1 - 0.5, medMag1 + 0.5) ax1.set_ylim(ax1.get_ylim()[::-1]) ax1.set_xlim(55000, 56000) ax1.set_ylabel(r"$R$") ax1.set_xticklabels([]) ax1.set_title("objid: {0}".format(lightCurve1.objid)) ax2.set_ylim(medMag2 - 0.5, medMag2 + 0.5) ax2.set_ylim(ax2.get_ylim()[::-1]) ax2.set_xlim(55000, 56000) ax2.set_ylabel(r"$R$") ax2.set_xlabel("MJD") ax2.set_title("objid: {0}".format(lightCurve2.objid)) plt.show()
def numero_differe_view(request): """ get numero_differe """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() numero_projet_id = int(request.registry.settings['numero_projet_id']) numero_vigueur_id = int(request.registry.settings['numero_vigueur_id']) role = request.params['role'] if 'role' in request.params else None num_agg = func.array_agg(VNumeros.numero, type_=ARRAY(Integer)) num_id_agg = func.array_agg(VNumeros.id, type_=ARRAY(Integer)) diff_id_agg = func.array_agg(VNumeros.diff_id, type_=ARRAY(Integer)) query = request.dbsession.query( VNumeros.diff_affaire_id, VNumeros.cadastre, num_agg, num_id_agg, diff_id_agg, func.min(VNumeros.diff_entree), VNumeros.diff_operateur_id, VNumeros.diff_operateur_nom, VNumeros.diff_operateur_prenom, VNumeros.diff_operateur_initiales) if role == "mo": user_id = request.params[ 'user_id'] if 'user_id' in request.params else None if user_id is not None: query = query.filter(VNumeros.diff_operateur_id == user_id) query = query.filter( and_(VNumeros.diff_entree.isnot(None), VNumeros.diff_sortie == None)) elif role == "secr": query = query.filter( and_(VNumeros.diff_req_radiation.isnot(True), VNumeros.diff_sortie.isnot(None), VNumeros.etat_id.in_((numero_projet_id, numero_vigueur_id)))) result = query.group_by(VNumeros.diff_affaire_id, VNumeros.cadastre, VNumeros.diff_operateur_id, VNumeros.diff_operateur_nom, VNumeros.diff_operateur_prenom, VNumeros.diff_operateur_initiales).having( func.array_length(num_agg, 1) > 0).all() numeros = [] for num in result: numeros.append({ 'diff_affaire_id': num[0], 'cadastre': num[1], 'numero': num[2], 'numero_id': num[3], 'diff_id': num[4], 'diff_entree': datetime.strftime(num[5], '%Y-%m-%d'), 'diff_operateur_id': num[6], 'diff_operateur_nom': num[7], 'diff_operateur_prenom': num[8], 'diff_operateur_initiales': num[9] }) return numeros
def bad_data_figure(prefix="plots"): matplotlib.rcParams["axes.titlesize"] = 40 matplotlib.rcParams["axes.labelsize"] = 40 matplotlib.rcParams["xtick.labelsize"] = 20 matplotlib.rcParams["ytick.labelsize"] = 20 lightCurve1 = session.query(LightCurve).filter(LightCurve.objid == 14688560553413090141).one() lightCurve2 = session.query(LightCurve).filter(LightCurve.objid == 14688560553413090134).one() print "Distance between objects: {0}\"".format(g.subtends(lightCurve1.ra, lightCurve1.dec, lightCurve2.ra, lightCurve2.dec, units="degrees")*3600.) medMag1 = np.median(lightCurve1.mag) medMag2 = np.median(lightCurve2.mag) fig = plt.figure(figsize=(20,25)) fig.subplots_adjust(hspace=0.2, left=0.1) ax1 = fig.add_subplot(211) ax1.errorbar(lightCurve1.mjd, lightCurve1.mag, lightCurve1.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax2 = fig.add_subplot(212) ax2.errorbar(lightCurve2.mjd, lightCurve2.mag, lightCurve2.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax1.set_ylim(medMag1-0.5,medMag1+0.5) ax1.set_ylim(ax1.get_ylim()[::-1]) ax1.set_xlim(55000, 56000) ax1.set_ylabel(r"$R$") ax1.set_xticklabels([]) ax1.set_title("objid: {0}".format(lightCurve1.objid)) ax2.set_ylim(medMag2-0.5,medMag2+0.5) ax2.set_ylim(ax2.get_ylim()[::-1]) ax2.set_xlim(55000, 56000) ax2.set_ylabel(r"$R$") ax2.set_xlabel("MJD") ax2.set_title("objid: {0}".format(lightCurve2.objid)) plt.savefig(os.path.join(prefix, "bad_data_figure.pdf")) return # Code below is to search for light curves that are similar while True: lightCurve1 = session.query(LightCurve).filter(func.array_length(LightCurve.mjd, 1) > 200).order_by(func.random()).limit(1).one() lightCurve2 = session.query(LightCurve).filter(func.array_length(LightCurve.mjd, 1) > 200).\ filter(func.q3c_radial_query(LightCurve.ra, LightCurve.dec, lightCurve1.ra, lightCurve1.dec, 60./3600.)).\ order_by(func.random()).limit(1).one() medMag1 = np.median(lightCurve1.mag) medMag2 = np.median(lightCurve2.mag) if medMag1 > 17 or medMag2 > 17: continue fig = plt.figure(figsize=(20,25)) fig.subplots_adjust(hspace=0.3, left=0.1) ax1 = fig.add_subplot(211) ax1.errorbar(lightCurve1.mjd, lightCurve1.mag, lightCurve1.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax2 = fig.add_subplot(212) ax2.errorbar(lightCurve2.mjd, lightCurve2.mag, lightCurve2.error, ls='none', marker='o', ecolor='0.7', capsize=0) ax1.set_ylim(medMag1-0.5,medMag1+0.5) ax1.set_ylim(ax1.get_ylim()[::-1]) ax1.set_xlim(55000, 56000) ax1.set_ylabel(r"$R$") ax1.set_xticklabels([]) ax1.set_title("objid: {0}".format(lightCurve1.objid)) ax2.set_ylim(medMag2-0.5,medMag2+0.5) ax2.set_ylim(ax2.get_ylim()[::-1]) ax2.set_xlim(55000, 56000) ax2.set_ylabel(r"$R$") ax2.set_xlabel("MJD") ax2.set_title("objid: {0}".format(lightCurve2.objid)) plt.show()
radpostauth = Table( "radpostauth", metadata, Column('Id', BigInteger, primary_key=True, nullable=False), Column('UserName', Text, nullable=False), Column('NASIPAddress', IPAddress, nullable=False), Column('NASPortId', Text), Column('PacketType', Text, nullable=False), Column('Groups', TupleArray(Text, dimensions=1)), Column('Reply', TupleArray(Text, dimensions=2)), Column('AuthDate', DateTime(timezone=True), nullable=False), CheckConstraint(func.coalesce(func.array_ndims("Groups"), 1) == 1), CheckConstraint( func.coalesce(func.array_ndims("Reply"), 2) == 2 and func.coalesce(func.array_length("Reply", 2), 2) == 2), ) radreply = Table( "radreply", metadata, Column('Priority', Integer, nullable=False), Column('UserName', Text, nullable=False), Column('NASIPAddress', IPAddress, nullable=False), Column('NASPortId', Text, nullable=False), Column('Attribute', Text, nullable=False), Column('Op', String(2), default='=', nullable=False), Column('Value', Text, nullable=False), UniqueConstraint('UserName', 'NASIPAddress', 'NASPortId', 'Priority'), ) temp_radreply = as_copy(radreply, 'temp_radreply')