Ejemplo n.º 1
0
def years(request):
    """
    Controller for the 'years' page.
    """
    post = request.POST

    # Plot
    if post and post['pointLonLat'] != '-9999':
        varname = get_wms_vars()[post['model']][post['variable']][1]
        varunit = get_wms_vars()[post['model']][post['variable']][2]
        point_lon_lat = post['pointLonLat']
        datarod_ts, datarods_urls_dict = get_data_rod_years(post, point_lon_lat)
        timeseries_plot = TimeSeries(
            height='250px',
            width='100%',
            engine='highcharts',
            title=False,
            y_axis_title=varname,
            y_axis_units=varunit,
            series=datarod_ts
        )

        context = {
            'timeseries_plot': timeseries_plot,
            'datarods_urls_dict': datarods_urls_dict,
            'plot_type': 'years'
        }

        return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 2
0
def years(request):
    """
    Controller for the 'years' page.
    """
    post = request.POST

    # Plot
    if post and post['pointLonLat'] != '-9999':
        varname = get_wms_vars()[post['model']][post['variable']][1]
        varunit = get_wms_vars()[post['model']][post['variable']][2]
        point_lon_lat = post['pointLonLat']
        datarod_ts, datarods_urls_dict = get_data_rod_years(post, point_lon_lat)
        timeseries_plot = TimeSeries(
            height='250px',
            width='100%',
            engine='highcharts',
            title=False,
            y_axis_title=varname,
            y_axis_units=varunit,
            series=datarod_ts
        )

        context = {
            'timeseries_plot': timeseries_plot,
            'datarods_urls_dict': datarods_urls_dict
        }

        return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 3
0
def get_raster_zip(latlonbox, time_st, model, variable):
    # Parameter
    minx, miny, maxx, maxy = latlonbox

    # Files, paths, and store name & store id
    tiff_file = NamedTemporaryFile(suffix=".tif", delete=False)
    tiff_path = tiff_file.name
    file_name = tiff_file.name[:-4]
    store_name = os.path.basename(file_name)
    store_id = get_workspace() + ':' + store_name
    tfw_path = file_name + '.tfw'
    prj_path = file_name + '.prj'
    zip_path = file_name + '.zip'

    # Create tiff file
    url_image = urllib2.urlopen(get_datarods_png().format(minx, miny, maxx, maxy,
                                                          time_st, get_wms_vars()[model][variable][0]))
    tiff_file.write(url_image.read())
    tiff_file.close()
    # Create prj file
    create_prj_file(prj_path)
    # Create tfw file
    create_tfw_file(tfw_path, float(minx), float(miny), float(maxx), float(maxy))
    create_zip_file(zip_path, tiff_path, tfw_path, prj_path)

    # Return
    return [zip_path, store_name, store_id]
Ejemplo n.º 4
0
def plot(request):
    """
    Controller for the plot page.
    """
    post = request.POST
    context = {}

    # Plot
    if post and post['pointLonLat'] != '-9999':
        try:
            varname = get_wms_vars()[post['model']][post['variable']][1]
            varunit = get_wms_vars()[post['model']][post['variable']][2]
            point_lon_lat = post['pointLonLat']
            datarod_ts, datarods_urls_dict = get_data_rod_plot(post, point_lon_lat)
            timeseries_plot = TimeSeries(
                height='250px',
                width='100%',
                engine='highcharts',
                title=False,
                y_axis_title=varname,
                y_axis_units=varunit,
                series=[{
                    'name': '%s (Lon,Lat)' % point_lon_lat,
                    'data': datarod_ts
                }]
            )
            context = {
                'timeseries_plot': timeseries_plot,
                'datarods_urls_dict': datarods_urls_dict,
                'plot_type': 'plot'
            }
        except Exception as e:
            print str(e)
            if 'ERROR 999' in str(e):
                context = {
                    'error': str(e)
                }
            else:
                context = {
                    'error': 'An unknown error occured.'
                }

    return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 5
0
def plot(request):
    """
    Controller for the plot page.
    """
    post = request.POST
    context = {}

    # Plot
    if post and post['pointLonLat'] != '-9999':
        try:
            varname = get_wms_vars()[post['model']][post['variable']][1]
            varunit = get_wms_vars()[post['model']][post['variable']][2]
            point_lon_lat = post['pointLonLat']
            datarod_ts, datarods_urls_dict = get_data_rod_plot(post, point_lon_lat)
            timeseries_plot = TimeSeries(
                height='250px',
                width='100%',
                engine='highcharts',
                title=False,
                y_axis_title=varname,
                y_axis_units=varunit,
                series=[{
                    'name': '%s (Lon,Lat)' % point_lon_lat,
                    'data': datarod_ts
                }]
            )
            context = {
                'timeseries_plot': timeseries_plot,
                'datarods_urls_dict': datarods_urls_dict
            }
        except Exception as e:
            print str(e)
            if 'ERROR 999' in str(e):
                context = {
                    'error': str(e)
                }
            else:
                context = {
                    'error': 'An unknown error occured.'
                }

    return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 6
0
def plot2(request):
    """
    Controller for the plot2 page.
    """
    post = request.POST

    # Plot
    if post and post['pointLonLat'] != '-9999':
        point_lon_lat = post['pointLonLat']
        datarod_ts, datarods_urls_dict = get_data_rod_plot2(post, point_lon_lat)
        timeseries_plot = {'y1_axis_units': get_wms_vars()[post['model']][post['variable']][2],
                           'y2_axis_units': get_wms_vars()[post['model2']][post['variable2']][2],
                           'series': datarod_ts}

        context = {
            'timeseries_plot': timeseries_plot,
            'plot2': True,
            'datarods_urls_dict': datarods_urls_dict
        }

        return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 7
0
def plot2(request):
    """
    Controller for the plot2 page.
    """
    post = request.POST

    # Plot
    if post and post['pointLonLat'] != '-9999':
        point_lon_lat = post['pointLonLat']
        datarod_ts, datarods_urls_dict = get_data_rod_plot2(post, point_lon_lat)
        timeseries_plot = {'y1_axis_units': get_wms_vars()[post['model']][post['variable']][2],
                           'y2_axis_units': get_wms_vars()[post['model2']][post['variable2']][2],
                           'series': datarod_ts}

        context = {
            'timeseries_plot': timeseries_plot,
            'plot_type': 'plot2',
            'datarods_urls_dict': datarods_urls_dict
        }

        return render(request, 'data_rods_explorer/plot.html', context)
Ejemplo n.º 8
0
def get_data_rod_plot2(req_get, point_lon_lat):
    start_date = req_get['startDate']
    end_date = req_get['endDate']

    # 1st variable
    model1 = req_get['model']
    variable1 = req_get['variable']
    superstring1 = get_datarods_tsb()[model1]

    dr_link1 = str(superstring1.format(variable1, point_lon_lat.replace(',', ',%20'),
                                       start_date, end_date))

    data1 = get_data_from_nasa_server(dr_link1)

    # 2nd variable
    model2 = req_get['model2']
    variable2 = req_get['variable2']
    superstring2 = get_datarods_tsb()[model2]

    dr_link2 = str(superstring2.format(variable2, point_lon_lat.replace(',', ',%20'),
                                       start_date, end_date))
    data2 = get_data_from_nasa_server(dr_link2)
    # Create list
    dr_ts = [{'name': get_wms_vars()[model1][variable1][1] + ' (' + get_wms_vars()[model1][variable1][2] + ')',
              'data': data1,
              'code': str(variable1) + ' (' + get_wms_vars()[model1][variable1][2] + ')'},
             {'name': get_wms_vars()[model2][variable2][1] + ' (' + get_wms_vars()[model2][variable2][2] + ')',
              'data': data2,
              'code': str(variable2) + ' (' + get_wms_vars()[model2][variable2][2] + ')'}]

    datarods_urls_dict = generate_datarods_urls_dict([dr_link1, dr_link2])
    return dr_ts, datarods_urls_dict
Ejemplo n.º 9
0
def get_data_rod_plot2(req_get, point_lon_lat):
    start_date = req_get['startDate']
    end_date = req_get['endDate']

    # 1st variable
    model1 = req_get['model']
    variable1 = req_get['variable']
    superstring1 = get_datarods_tsb()[model1]

    dr_link1 = str(
        superstring1.format(variable1, point_lon_lat.replace(',', ',%20'),
                            start_date, end_date))

    data1 = get_data_from_nasa_server(dr_link1)

    # 2nd variable
    model2 = req_get['model2']
    variable2 = req_get['variable2']
    superstring2 = get_datarods_tsb()[model2]

    dr_link2 = str(
        superstring2.format(variable2, point_lon_lat.replace(',', ',%20'),
                            start_date, end_date))
    data2 = get_data_from_nasa_server(dr_link2)
    # Create list
    dr_ts = [{
        'name':
        get_wms_vars()[model1][variable1][1] + ' (' +
        get_wms_vars()[model1][variable1][2] + ')',
        'data':
        data1,
        'code':
        str(variable1) + ' (' + get_wms_vars()[model1][variable1][2] + ')'
    }, {
        'name':
        get_wms_vars()[model2][variable2][1] + ' (' +
        get_wms_vars()[model2][variable2][2] + ')',
        'data':
        data2,
        'code':
        str(variable2) + ' (' + get_wms_vars()[model2][variable2][2] + ')'
    }]

    datarods_urls_dict = generate_datarods_urls_dict([dr_link1, dr_link2])
    return dr_ts, datarods_urls_dict
Ejemplo n.º 10
0
def home(request):
    """
    Controller for the app 'home' page.
    """

    init_model()

    model = get_model_options()[0][1]

    select_model = create_select_model(model)
    select_date, select_hour = create_map_date_ctrls(model)

    # Load map
    map_view, map_view_options = create_map()

    start_date1, end_date1, plot_button1 = create_plot_ctrls(model, 'plot')
    start_date2, end_date2, plot_button2 = create_plot_ctrls(model, 'plot2')
    select_model2 = SelectInput(display_text='',
                                name='model2',
                                multiple=False,
                                original=True,
                                options=get_model_options(),
                                attributes="onchange=oc_model2();"
                                )

    years_list = create_years_list(1979)
    select_years = SelectInput(display_text='',
                               name='years',
                               multiple=True,
                               original=False,
                               options=years_list,
                               attributes="onchange=oc_years();"
                               )

    plot_button3 = Button(display_text='Plot',
                          name='years',
                          style='',
                          icon='',
                          href='',
                          submit=False,
                          disabled=False,
                          attributes='onclick=createPlot(this.name);',
                          classes='btn-plot')

    # Context variables
    context = {
        'select_model': select_model,
        'MapView': map_view,
        'map_view_options': map_view_options,
        'select_date': select_date,
        'select_hour': select_hour,
        'MODEL_FENCES': dumps(get_model_fences()),
        'VAR_DICT': dumps(get_var_dict()),
        'DATARODS_PNG': dumps(get_datarods_png()),
        'DATARODS_TSB': dumps(get_datarods_tsb()),
        'WMS_VARS': dumps(get_wms_vars()),
        'start_date1': start_date1,
        'end_date1': end_date1,
        'plot_button1': plot_button1,
        'start_date2': start_date2,
        'end_date2': end_date2,
        'plot_button2': plot_button2,
        'select_model2': select_model2,
        'plot_button3': plot_button3,
        'select_years': select_years,
        # 'messages': [{
        #     'category': 'info',
        #     'text': 'Click on the map to define data query location.',
        #     'id': 'click-map'
        # }]
    }

    return render(request, 'data_rods_explorer/app_base_dre.html', context)
Ejemplo n.º 11
0
			            [dt.datetime(2008, 12, 9), 10.6],
			            [dt.datetime(2008, 12, 16), 10.6],
			            [dt.datetime(2008, 12, 28), 10.67],
			            [dt.datetime(2009, 1, 1), 10.81]
			            ]}
			        ]
'''
=======
    """
    Controller for the 'years' page.
    """
    post = request.POST

    # Plot
    if post and post['pointLonLat'] != '-9999':
        varname = get_wms_vars()[post['model']][post['variable']][1]
        varunit = get_wms_vars()[post['model']][post['variable']][2]
        point_lon_lat = post['pointLonLat']
        datarod_ts, datarods_urls_dict = get_data_rod_years(post, point_lon_lat)
        timeseries_plot = TimeSeries(
            height='250px',
            width='100%',
            engine='highcharts',
            title=False,
            y_axis_title=varname,
            y_axis_units=varunit,
            series=datarod_ts
        )

        context = {
            'timeseries_plot': timeseries_plot,
Ejemplo n.º 12
0
def home(request):
    """
    Controller for the app 'home' page.
    """

    init_model()

    model = get_model_options()[0][1]

    select_model = create_select_model(model)
    select_date, select_hour = create_map_date_ctrls(model)

    # Load map
    map_view, map_view_options = create_map()

    start_date1, end_date1, plot_button1 = create_plot_ctrls(model, 'plot')
    start_date2, end_date2, plot_button2 = create_plot_ctrls(model, 'plot2')
    select_model2 = SelectInput(display_text='',
                                name='model2',
                                multiple=False,
                                original=True,
                                options=get_model_options(),
                                attributes="onchange=oc_model2();"
                                )

    years_list = create_years_list(1979)
    select_years = SelectInput(display_text='',
                               name='years',
                               multiple=True,
                               original=False,
                               options=years_list,
                               attributes="onchange=oc_years();"
                               )

    plot_button3 = Button(display_text='Plot',
                          name='years',
                          style='',
                          icon='',
                          href='',
                          submit=False,
                          disabled=False,
                          attributes='onclick=createPlot(this.name);',
                          classes='btn-plot')

    # Context variables
    context = {
        'select_model': select_model,
        'MapView': map_view,
        'map_view_options': map_view_options,
        'select_date': select_date,
        'select_hour': select_hour,
        'MODEL_FENCES': dumps(get_model_fences()),
        'VAR_DICT': dumps(get_var_dict()),
        'DATARODS_PNG': dumps(get_datarods_png()),
        'DATARODS_TSB': dumps(get_datarods_tsb()),
        'WMS_VARS': dumps(get_wms_vars()),
        'start_date1': start_date1,
        'end_date1': end_date1,
        'plot_button1': plot_button1,
        'start_date2': start_date2,
        'end_date2': end_date2,
        'plot_button2': plot_button2,
        'select_model2': select_model2,
        'plot_button3': plot_button3,
        'select_years': select_years
    }

    return render(request, 'data_rods_explorer/app_base_dre.html', context)