Exemplo n.º 1
0
def target_plan(context):
    #request = context['request']
    start_time = datetime.datetime.now()
    end_time = datetime.datetime.now() + datetime.timedelta(days=1)
    airmass = 3.0
    plan_form = TargetVisibilityForm({
        'start_time': start_time,
        'end_time': end_time,
        'airmass': airmass
    })
    visibility_graph = ''
    visibility_data = get_visibility(context['object'], start_time, end_time,
                                     15, airmass)
    plot_data = [
        go.Scatter(
            x=data[0],
            y=data[1],
            mode='lines',
            name=site,
        ) for site, data in visibility_data.items()
    ]
    layout = go.Layout(yaxis=dict(range=[airmass, 1.0]),
                       margin=dict(l=20, r=10, b=30, t=40),
                       hovermode='closest',
                       width=600,
                       height=300,
                       autosize=True)
    visibility_graph = offline.plot(go.Figure(data=plot_data, layout=layout),
                                    output_type='div',
                                    show_link=False)
    return {
        'form': plan_form,
        'target': context['object'],
        'visibility_graph': visibility_graph
    }
Exemplo n.º 2
0
    def test_get_visibility_non_sidereal(self, mock_observer_for_site, mock_get_rise_set, mock_facility):
        mock_facility.return_value = {'Fake Facility': FakeFacility}
        mock_get_rise_set.return_value = []
        mock_observer_for_site.return_value = ephem.city('Los Angeles')

        start = datetime(1997, 4, 1, 0, 0, 0)
        end = start + timedelta(minutes=60)
        expected_airmass = [
            1.225532769770131, 1.2536644126634366, 1.2843810879053679, 1.3179084796712417,
            1.3545030240774714, 1.3944575296459614, 1.4381124914948578
        ]

        airmass_data = get_visibility(self.nst, start, end, 10, 10)['(Fake Facility) Los Angeles'][1]
        self.assertEqual(len(airmass_data), len(expected_airmass))
        for i in range(0, len(expected_airmass)):
            self.assertLess(math.fabs(airmass_data[i] - expected_airmass[i]), 0.05)
Exemplo n.º 3
0
    def test_get_visibility_sidereal(self, mock_observer_for_site, mock_get_rise_set, mock_facility):
        mock_facility.return_value = {'Fake Facility': FakeFacility}
        mock_get_rise_set.return_value = []
        mock_observer_for_site.return_value = ephem.city('Los Angeles')

        start = self.time
        end = start + timedelta(minutes=60)
        expected_airmass = [
            3.6074370614681017, 3.997263815883785, 4.498087520663738, 5.162731916462906,
            6.083298253498044, 7.4363610371608475, 9.607152214891583
        ]

        airmass_data = get_visibility(self.st, start, end, 10, 10)['(Fake Facility) Los Angeles'][1]
        self.assertEqual(len(airmass_data), len(expected_airmass))
        for i in range(0, len(expected_airmass)):
            self.assertEqual(airmass_data[i], expected_airmass[i])
Exemplo n.º 4
0
def target_plan(context):
    """
    Displays form and renders plot for visibility calculation. Using this templatetag to render a plot requires that
    the context of the parent view have values for start_time, end_time, and airmass.
    """
    request = context['request']
    plan_form = TargetVisibilityForm()
    visibility_graph = ''
    if all(request.GET.get(x) for x in ['start_time', 'end_time']):
        plan_form = TargetVisibilityForm({
            'start_time':
            request.GET.get('start_time'),
            'end_time':
            request.GET.get('end_time'),
            'airmass':
            request.GET.get('airmass')
        })
        if plan_form.is_valid():
            start_time = parse(request.GET['start_time'])
            end_time = parse(request.GET['end_time'])
            if request.GET.get('airmass'):
                airmass_limit = float(request.GET.get('airmass'))
            else:
                airmass_limit = None
            visibility_data = get_visibility(context['object'], start_time,
                                             end_time, 10, airmass_limit)
            plot_data = [
                go.Scatter(x=data[0], y=data[1], mode='lines', name=site)
                for site, data in visibility_data.items()
            ]
            layout = go.Layout(yaxis=dict(autorange='reversed'))
            visibility_graph = offline.plot(go.Figure(data=plot_data,
                                                      layout=layout),
                                            output_type='div',
                                            show_link=False)
    return {
        'form': plan_form,
        'target': context['object'],
        'visibility_graph': visibility_graph
    }