コード例 #1
0
ファイル: constellation_views.py プロジェクト: skybber/czsky
def constellation_chart(constellation_id):
    """View a constellation findchart."""
    constellation = _find_constellation(constellation_id)
    if constellation is None:
        abort(404)

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = constellation.label_ra
            form.dec.data = constellation.label_dec

    chart_control = common_prepare_chart_data(form)

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)

    common_name = _get_constellation_common_name(constellation)
    return render_template(
        'main/catalogue/constellation_info.html',
        fchart_form=form,
        type='chart',
        constellation=constellation,
        chart_control=chart_control,
        common_name=common_name,
    )
コード例 #2
0
def observed_list_chart():
    observed_list = ObservedList.create_get_observed_list_by_user_id(current_user.id)
    if observed_list is None:
        abort(404)

    form  = ChartForm()

    dso_id = request.args.get('dso_id')

    observed_list_item = None
    if dso_id and dso_id.isdigit():
        idso_id = int(dso_id)
        observed_list_item = next((x for x in observed_list.observed_list_items if x.deepskyObject.id == idso_id), None)

    if not observed_list_item:
        observed_list_item = observed_list.observed_list_items[0] if observed_list.observed_list_items else None

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = observed_list_item.deepskyObject.ra if observed_list_item else 0
            form.dec.data = observed_list_item.deepskyObject.dec if observed_list_item else 0

    chart_control = common_prepare_chart_data(form)

    if observed_list_item:
        default_chart_iframe_url = url_for('main_deepskyobject.deepskyobject_info', back='observedlist', dso_id=observed_list_item.deepskyObject.name, embed='fc', allow_back='true')
    else:
        default_chart_iframe_url = None

    return render_template('main/observation/observed_list.html', fchart_form=form, type='chart', observed_list=observed_list, chart_control=chart_control,
                           default_chart_iframe_url=default_chart_iframe_url,)
コード例 #3
0
ファイル: double_star_views.py プロジェクト: skybber/czsky
def double_star_chart(double_star_id):
    """View a double star findchart."""
    double_star = DoubleStar.query.filter_by(id=double_star_id).first()
    if not double_star:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['double_star_embed_seltab'] = 'catalogue_data'

    season = request.args.get('season')

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = double_star.ra_first
            form.dec.data = double_star.dec_first

    chart_control = common_prepare_chart_data(form)

    prev_dbl_star, next_dbl_star = _get_prev_next_double_star(double_star)

    lang, editor_user = get_lang_and_editor_user_from_request(for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(double_star_id=double_star_id, user_id=editor_user.id, lang_code=lang).first()

    return render_template('main/catalogue/double_star_info.html', fchart_form=form, type='chart', double_star=double_star,
                           chart_control=chart_control, prev_dbl_star=prev_dbl_star, next_dbl_star=next_dbl_star, embed=embed, season=season,
                           user_descr=user_descr)
コード例 #4
0
def star_chart(star_id):
    """View a star findchart."""
    star = Star.query.filter_by(id=star_id).first()
    if not star:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['star_embed_seltab'] = 'info'

    season = request.args.get('season')

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = star.ra
            form.dec.data = star.dec

    chart_control = common_prepare_chart_data(form)

    prev_star, next_star = _get_prev_next_star(star)

    return render_template(
        'main/catalogue/star_info.html',
        fchart_form=form,
        type='chart',
        star=star,
        user_descr=None,
        chart_control=chart_control,
        prev_star=prev_star,
        next_star=next_star,
        embed=embed,
        season=season,
    )
コード例 #5
0
def news_chart(news_id):
    """View a comet info."""
    news = News.query.filter_by(id=news_id).first()
    if news is None:
        abort(404)
    if not news.is_released and (current_user.is_anonymous
                                 or not current_user.is_editor):
        abort(404)

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = news.ra
            form.dec.data = news.dec

    chart_control = common_prepare_chart_data(form)

    return render_template(
        'main/news/news_info.html',
        fchart_form=form,
        type='chart',
        news=news,
        user_descr=None,
        chart_control=chart_control,
    )
コード例 #6
0
def planet_info(planet_name):
    """View a planet info."""
    planet = _find_planet(planet_name)
    if planet is None:
        abort(404)

    form = PlanetFindChartForm()

    ts = load.timescale(builtin=True)
    eph = load('de421.bsp')
    earth = eph['earth']

    if not form.date_from.data or not form.date_to.data:
        today = datetime.today()
        form.date_from.data = today
        form.date_to.data = today + timedelta(days=7)

    if (form.date_from.data is None) or (form.date_to.data is None) or form.date_from.data >= form.date_to.data:
        t = ts.now()
        planet_ra_ang, planet_dec_ang, distance = earth.at(t).observe(planet.eph).radec()
        trajectory_b64 = None
    else:
        d1 = date(form.date_from.data.year, form.date_from.data.month, form.date_from.data.day)
        d2 = date(form.date_to.data.year, form.date_to.data.month, form.date_to.data.day)
        t = ts.now()
        planet_ra_ang, planet_dec_ang, distance = earth.at(t).observe(planet.eph).radec()
        if d1 != d2:
            time_delta = d2 - d1
            if time_delta.days > 365:
                d2 = d1 + timedelta(days=365)
            dt = get_trajectory_time_delta(d1, d2)
            trajectory = []
            while d1 <= d2:
                t = ts.utc(d1.year, d1.month, d1.day)
                ra, dec, distance = earth.at(t).observe(planet.eph).radec()
                trajectory.append((ra.radians, dec.radians, d1.strftime('%d.%m.')))
                if d1 == d2:
                    break
                d1 += dt  # timedelta(days=1)
                if d1 > d2:
                    d1 = d2
            t = ts.utc(d1.year, d1.month, d1.day)
            trajectory_json = json.dumps(trajectory)
            trajectory_b64 = base64.b64encode(trajectory_json.encode('utf-8'))
        else:
            trajectory_b64 = None

    planet_ra = planet_ra_ang.radians
    planet_dec = planet_dec_ang.radians

    if not common_ra_dec_fsz_from_request(form):
        form.ra.data = planet_ra
        form.dec.data = planet_dec

    chart_control = common_prepare_chart_data(form)

    return render_template('main/solarsystem/planet_info.html', fchart_form=form, type='info', planet=planet,
                           planet_ra=planet_ra, planet_dec=planet_dec,
                           chart_control=chart_control, trajectory=trajectory_b64)
コード例 #7
0
ファイル: comet_views.py プロジェクト: skybber/czsky
def comet_info(comet_id):
    """View a comet info."""
    comet = _find_comet(comet_id)
    if comet is None:
        abort(404)

    form = CometFindChartForm()

    ts = load.timescale(builtin=True)
    eph = load('de421.bsp')
    sun, earth = eph['sun'], eph['earth']

    c = sun + mpc.comet_orbit(comet, ts, GM_SUN)

    if not form.date_from.data or not form.date_to.data:
        today = datetime.today()
        form.date_from.data = today
        form.date_to.data = today + timedelta(days=7)

    if (form.date_from.data is None) or (form.date_to.data is None) or form.date_from.data >= form.date_to.data:
        t = ts.now()
        comet_ra_ang, comet_dec_ang, distance = earth.at(t).observe(c).radec()
        trajectory_b64 = None
    else:
        d1 = date(form.date_from.data.year, form.date_from.data.month, form.date_from.data.day)
        d2 = date(form.date_to.data.year, form.date_to.data.month, form.date_to.data.day)
        t = ts.now()
        comet_ra_ang, comet_dec_ang, distance = earth.at(t).observe(c).radec()
        if d1 != d2:
            time_delta = d2 - d1
            if time_delta.days > 365:
                d2 = d1 + timedelta(days=365)
            dt = get_trajectory_time_delta(d1, d2)
            trajectory = []
            while d1 <= d2:
                t = ts.utc(d1.year, d1.month, d1.day)
                ra, dec, distance = earth.at(t).observe(c).radec()
                trajectory.append((ra.radians, dec.radians, d1.strftime('%d.%m.')))
                d1 += dt
            t = ts.utc(d1.year, d1.month, d1.day)
            trajectory_json = json.dumps(trajectory)
            trajectory_b64 = base64.b64encode(trajectory_json.encode('utf-8'))
        else:
            trajectory_b64 = None

    comet_ra = comet_ra_ang.radians
    comet_dec = comet_dec_ang.radians

    if not common_ra_dec_fsz_from_request(form):
        form.ra.data = comet_ra
        form.dec.data = comet_dec

    chart_control = common_prepare_chart_data(form)

    return render_template('main/solarsystem/comet_info.html', fchart_form=form, type='info', comet=comet, comet_ra=comet_ra, comet_dec=comet_dec,
                           chart_control=chart_control, trajectory=trajectory_b64)
コード例 #8
0
def observing_session_chart(observing_session_id):
    observing_session = ObservingSession.query.filter_by(
        id=observing_session_id).first()
    is_mine_observing_session = _check_observing_session(observing_session,
                                                         allow_public=True)

    form = ChartForm()

    dso_id = request.args.get('dso_id')
    observing_session_item = None
    dso = None

    idso_id = int(dso_id) if dso_id and dso_id.isdigit() else None
    for oitem in observing_session.observations:
        for oitem_dso in oitem.deepsky_objects:
            if idso_id is None or oitem_dso.id == idso_id:
                observing_session_item = oitem
                dso = oitem_dso
                break
        if observing_session_item is not None:
            break

    if not common_ra_dec_fsz_from_request(form):
        if observing_session_item:
            if form.ra.data is None or form.dec.data is None:
                if not dso:
                    dso = observing_session_item.deepsky_objects[
                        0] if observing_session_item and observing_session_item.deepsky_objects else None
                form.ra.data = dso.ra if dso else 0
                form.dec.data = dso.dec if dso else 0
        else:
            common_set_initial_ra_dec(form)

    if observing_session_item:
        default_chart_iframe_url = url_for(
            'main_deepskyobject.deepskyobject_info',
            back='observing_session',
            back_id=observing_session.id,
            dso_id=dso.name,
            embed='fc',
            allow_back='true')
    else:
        default_chart_iframe_url = None

    chart_control = common_prepare_chart_data(form)

    return render_template('main/observation/observing_session_info.html',
                           fchart_form=form,
                           type='chart',
                           observing_session=observing_session,
                           chart_control=chart_control,
                           default_chart_iframe_url=default_chart_iframe_url,
                           is_mine_observing_session=is_mine_observing_session)
コード例 #9
0
ファイル: dso_list_views.py プロジェクト: skybber/czsky
def dso_list_chart(dso_list_id):
    dso_list = _find_dso_list(dso_list_id)
    if dso_list is None:
        abort(404)

    form = ChartForm()

    dso_id = request.args.get('dso_id')
    dso_list_item = None
    if dso_id and dso_id.isdigit():
        idso_id = int(dso_id)
        dso_list_item = next((x for x in dso_list.dso_list_items
                              if x.deepskyObject.id == idso_id), None)

    if not dso_list_item:
        dso_list_item = DsoListItem.query.filter_by(dso_list_id=dso_list.id,
                                                    item_id=1).first()

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    dso_list_descr = DsoListDescription.query.filter_by(
        dso_list_id=dso_list.id, lang_code=lang).first()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = dso_list_item.deepskyObject.ra if dso_list_item else 0
            form.dec.data = dso_list_item.deepskyObject.dec if dso_list_item else 0

    if dso_list_item:
        default_chart_iframe_url = url_for(
            'main_deepskyobject.deepskyobject_info',
            back='dso_list',
            back_id=dso_list.id,
            dso_id=dso_list_item.deepskyObject.name,
            embed='fc',
            allow_back='true')
    else:
        default_chart_iframe_url = None

    chart_control = common_prepare_chart_data(form)

    return render_template('main/catalogue/dso_list_info.html',
                           fchart_form=form,
                           type='chart',
                           dso_list=dso_list,
                           dso_list_descr=dso_list_descr,
                           chart_control=chart_control,
                           default_chart_iframe_url=default_chart_iframe_url)
コード例 #10
0
ファイル: sessionplan_views.py プロジェクト: skybber/czsky
def session_plan_chart(session_plan_id):
    session_plan = SessionPlan.query.filter_by(id=session_plan_id).first()
    is_mine_session_plan = _check_session_plan(session_plan, allow_public=True)

    form = ChartForm()

    dso_id = request.args.get('dso_id')
    session_plan_item = None
    if dso_id and dso_id.isdigit():
        idso_id = int(dso_id)
        session_plan_item = next((x for x in session_plan.session_plan_items
                                  if x.deepskyObject.id == idso_id), None)

    if not session_plan_item:
        session_plan_item = SessionPlanItem.query.filter_by(
            session_plan_id=session_plan.id).first()

    if not common_ra_dec_fsz_from_request(form):
        if session_plan_item:
            if form.ra.data is None or form.dec.data is None:
                form.ra.data = session_plan_item.deepskyObject.ra if session_plan_item else 0
                form.dec.data = session_plan_item.deepskyObject.dec if session_plan_item else 0
        else:
            common_set_initial_ra_dec(form)

    if session_plan_item:
        default_chart_iframe_url = url_for(
            'main_deepskyobject.deepskyobject_info',
            back='session_plan',
            back_id=session_plan.id,
            dso_id=session_plan_item.dso_id,
            embed='fc',
            allow_back='true')
    else:
        default_chart_iframe_url = None

    chart_control = common_prepare_chart_data(form)

    return render_template('main/planner/session_plan_info.html',
                           fchart_form=form,
                           type='chart',
                           session_plan=session_plan,
                           chart_control=chart_control,
                           default_chart_iframe_url=default_chart_iframe_url,
                           is_mine_session_plan=is_mine_session_plan)
コード例 #11
0
def star_descr_chart(star_descr_id):
    """View a star findchart."""
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(id=star_descr_id,
                                                     user_id=editor_user.id,
                                                     lang_code=lang).first()
    if user_descr is None:
        abort(404)

    star = user_descr.star
    if not star:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['star_embed_seltab'] = 'info'

    season = request.args.get('season')

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = star.ra
            form.dec.data = star.dec

    chart_control = common_prepare_chart_data(form)

    if user_descr.star is not None:
        prev_star, next_star = _get_prev_next_star(user_descr.star)
    else:
        prev_star, next_star = (None, None)

    return render_template(
        'main/catalogue/star_info.html',
        fchart_form=form,
        type='chart',
        user_descr=user_descr,
        chart_control=chart_control,
        prev_star=prev_star,
        next_star=next_star,
        embed=embed,
        season=season,
    )
コード例 #12
0
ファイル: chart_views.py プロジェクト: skybber/czsky
def chart():
    """View a chart."""
    form = ChartForm()

    ra = request.args.get('mra', None)
    dec = request.args.get('mdec', None)
    if ra is not None and dec is not None:
        form.ra.data = float(ra)
        form.dec.data = float(dec)
    elif not common_ra_dec_fsz_from_request(form):
        common_set_initial_ra_dec(form)

    chart_control = common_prepare_chart_data(form)

    return render_template('main/chart/chart.html',
                           fchart_form=form,
                           chart_control=chart_control,
                           mark_ra=ra,
                           mark_dec=dec)
コード例 #13
0
ファイル: deepskyobject_views.py プロジェクト: skybber/czsky
def deepskyobject_chart(dso_id):
    """View a deepsky object chart."""
    dso, orig_dso = _find_dso(dso_id)
    if dso is None:
        abort(404)

    form = ChartForm()

    prev_dso, prev_dso_title, next_dso, next_dso_title = _get_prev_next_dso(
        orig_dso)

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = dso.ra
            form.dec.data = dso.dec

    chart_control = common_prepare_chart_data(
        form,
        cancel_selection_url=url_for('main_deepskyobject.deepskyobject_chart',
                                     dso_id=dso.name))

    back = request.args.get('back')
    back_id = request.args.get('back_id')

    season = request.args.get('season')
    embed = request.args.get('embed')

    if embed:
        session['dso_embed_seltab'] = 'chart'

    back = request.args.get('back')
    if back == 'running_plan':
        iframe_endpoit = 'main_deepskyobject.deepskyobject_observation_log'
    else:
        iframe_endpoit = 'main_deepskyobject.deepskyobject_info'

    default_chart_iframe_url = url_for(iframe_endpoit,
                                       back=back,
                                       back_id=back_id,
                                       dso_id=dso.name,
                                       season=season,
                                       embed='fc',
                                       allow_back='true')

    has_observations = _has_dso_observations(dso, orig_dso)

    return render_template(
        'main/catalogue/deepskyobject_info.html',
        fchart_form=form,
        type='chart',
        dso=dso,
        prev_dso=prev_dso,
        next_dso=next_dso,
        prev_dso_title=prev_dso_title,
        next_dso_title=next_dso_title,
        chart_control=chart_control,
        default_chart_iframe_url=default_chart_iframe_url,
        season=season,
        embed=embed,
        has_observations=has_observations,
    )
コード例 #14
0
ファイル: minor_planet_views.py プロジェクト: skybber/czsky
def minor_planet_info(minor_planet_id):
    """View a minor_planet info."""
    minor_planet = MinorPlanet.query.filter_by(id=minor_planet_id).first()
    if minor_planet is None:
        abort(404)

    form = MinorPlanetFindChartForm()

    ts = load.timescale(builtin=True)
    eph = load('de421.bsp')
    sun, earth = eph['sun'], eph['earth']

    mpc_minor_planet = _get_mpc_minor_planets().iloc[
        minor_planet.int_designation - 1]

    c = sun + mpc.mpcorb_orbit(mpc_minor_planet, ts, GM_SUN)

    if not form.date_from.data or not form.date_to.data:
        today = datetime.today()
        form.date_from.data = today
        form.date_to.data = today + timedelta(days=7)

    if (form.date_from.data is
            None) or (form.date_to.data is
                      None) or form.date_from.data >= form.date_to.data:
        t = ts.now()
        minor_planet_ra_ang, minor_planet_dec_ang, distance = earth.at(
            t).observe(c).radec()
        trajectory_b64 = None
    else:
        d1 = date(form.date_from.data.year, form.date_from.data.month,
                  form.date_from.data.day)
        d2 = date(form.date_to.data.year, form.date_to.data.month,
                  form.date_to.data.day)
        t = ts.now()
        minor_planet_ra_ang, minor_planet_dec_ang, distance = earth.at(
            t).observe(c).radec()
        if d1 != d2:
            time_delta = d2 - d1
            if time_delta.days > 365:
                d2 = d1 + timedelta(days=365)
            dt = get_trajectory_time_delta(d1, d2)
            trajectory = []
            while d1 <= d2:
                t = ts.utc(d1.year, d1.month, d1.day)
                ra, dec, distance = earth.at(t).observe(c).radec()
                trajectory.append(
                    (ra.radians, dec.radians, d1.strftime('%d.%m.')))
                if d1 == d2:
                    break
                d1 += dt  # timedelta(days=1)
                if d1 > d2:
                    d1 = d2
            t = ts.utc(d1.year, d1.month, d1.day)
            trajectory_json = json.dumps(trajectory)
            trajectory_b64 = base64.b64encode(trajectory_json.encode('utf-8'))
        else:
            trajectory_b64 = None

    minor_planet_ra = minor_planet_ra_ang.radians
    minor_planet_dec = minor_planet_dec_ang.radians

    if not common_ra_dec_fsz_from_request(form):
        form.ra.data = minor_planet_ra
        form.dec.data = minor_planet_dec

    chart_control = common_prepare_chart_data(form)

    return render_template('main/solarsystem/minor_planet_info.html',
                           fchart_form=form,
                           type='info',
                           minor_planet=minor_planet,
                           minor_planet_ra=minor_planet_ra,
                           minor_planet_dec=minor_planet_dec,
                           chart_control=chart_control,
                           trajectory=trajectory_b64)