Exemple #1
0
def month_view(request):
    methodtype=request.matchdict['accesstype']
    methodkey=request.matchdict['access']
    isMulti='thumbtype' not in request.matchdict or request.matchdict['thumbtype']=='all'
    try:
        mylib=HSRLImageArchiveLibrarian(**{methodtype:methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    yearno=int(request.matchdict['year'])
    monthno=int(request.matchdict['month'])
    dayno=1
    if 'day' in request.matchdict:
        if not isMulti:
            return redirect_month(request)
        dayno=int(request.matchdict['day'])
    elif isMulti:
        return redirect_month(request)
    #datasetdesc=methodkey
    #imagedesc=subtypekey
    #print request.matched_route.__dict__.keys()
    try:
        thismonth=datetime(yearno,monthno,dayno)
        #print thismonth
        realtime=mylib.validClosestTime(thismonth)
        #print realtime
        if (isMulti and realtime.date()!=thismonth.date()) or (not isMulti and (realtime.year!=yearno or realtime.month!=monthno)):
            return redirect_month(request)
    except ValueError, e:
        print e
        return redirect_month(request)
Exemple #2
0
def redirect_month(request):
    #try:
        methodtype=request.matchdict['accesstype']
        methodkey=request.matchdict['access']
        try:
            mylib=HSRLImageArchiveLibrarian(**{methodtype:methodkey})
        except RuntimeError:
            return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#            return HTTPTemporaryRedirect(location=request.route_path("home"))
        if 'thumbtype' in request.matchdict and request.matchdict['thumbtype']!='all':
            subtypekey=request.matchdict['thumbtype']
        else:
            subtypekey=None
        nowtime=datetime.utcnow()
        if 'year' in request.matchdict:
            yearno=int(request.matchdict['year'])
        else:
            yearno=nowtime.year
        if 'month' in request.matchdict:
            monthno=int(request.matchdict['month'])
        else:
            monthno=nowtime.month
        if 'day' in request.matchdict:
            dayno=int(request.matchdict['day'])
        elif monthno==nowtime.month and yearno==nowtime.year and subtypekey==None:
            dayno=nowtime.day
        else:
            dayno=1
        d=validdate(yearno,monthno,dayno,0,0)
        besttime=mylib.validClosestTime(d)
        return HTTPTemporaryRedirect(location=monthurlfor(request,methodtype,methodkey,subtypekey,besttime))
Exemple #3
0
def redirect_day(request):
    try:
        methodtype=request.matchdict['accesstype']
        methodkey=request.matchdict['access']
        nowtime=datetime.utcnow()
        try:
            mylib=HSRLImageArchiveLibrarian(**{methodtype:methodkey})
        except RuntimeError:
            return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")

        if 'year' in request.matchdict:
            yearno=int(request.matchdict['year'])
        else:
            yearno=nowtime.year
        if 'month' in request.matchdict:
            monthno=int(request.matchdict['month'])
        else:
            monthno=nowtime.month
        if 'day' in request.matchdict:
            dayno=int(request.matchdict['day'])
        else:
            dayno=nowtime.day
        if 'ampm' in request.matchdict:
            ampm=request.matchdict['ampm']
            if ampm=='am':
                hourno=0
            else:
                hourno=12
        else:
            hourno=nowtime.hour
        besttime=mylib.validClosestTime(datetime(yearno,monthno,dayno,hourno,0,0))
        return HTTPTemporaryRedirect(location=dayurlfor(request,methodtype,methodkey,besttime))
    except:
        return HTTPTemporaryRedirect(location=request.route_path('home'))
Exemple #4
0
def date_view(request):
    methodtype=request.matchdict['accesstype']
    methodkey=request.matchdict['access']
    try:
        mylib=HSRLImageArchiveLibrarian(**{methodtype:methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    yearno=int(request.matchdict['year'])
    monthno=int(request.matchdict['month'])
    dayno=int(request.matchdict['day'])
    ampm=request.matchdict['ampm']
    hourno=-1
    ampm_range=None
    if ampm=='am':
        hourno=0
        ampm_range='00:00-12:00'
    elif ampm=='pm':
        hourno=12
        ampm_range='12:00-00:00'
    try:
        selectdate=datetime(yearno,monthno,dayno,hourno)
        #print selectdate
        realtime=mylib.validClosestTime(selectdate)
        #print realtime
        if realtime.date()!=selectdate.date() or realtime.hour!=hourno:
            return redirect_day(request)
    except ValueError, e:
        print e
        return redirect_day(request)
def month_view(request):
    methodtype = request.matchdict['accesstype']
    methodkey = request.matchdict['access']
    isMulti = 'thumbtype' not in request.matchdict or request.matchdict[
        'thumbtype'] == 'all'
    try:
        mylib = HSRLImageArchiveLibrarian(**{methodtype: methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    yearno = int(request.matchdict['year'])
    monthno = int(request.matchdict['month'])
    dayno = 1
    if 'day' in request.matchdict:
        if not isMulti:
            return redirect_month(request)
        dayno = int(request.matchdict['day'])
    elif isMulti:
        return redirect_month(request)
    #datasetdesc=methodkey
    #imagedesc=subtypekey
    #print request.matched_route.__dict__.keys()
    try:
        thismonth = datetime(yearno, monthno, dayno)
        #print thismonth
        realtime = mylib.validClosestTime(thismonth)
        #print realtime
        if (isMulti and realtime.date() != thismonth.date()) or (
                not isMulti and
            (realtime.year != yearno or realtime.month != monthno)):
            return redirect_month(request)
    except ValueError, e:
        print e
        return redirect_month(request)
def date_view(request):
    methodtype = request.matchdict['accesstype']
    methodkey = request.matchdict['access']
    try:
        mylib = HSRLImageArchiveLibrarian(**{methodtype: methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")


#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    yearno = int(request.matchdict['year'])
    monthno = int(request.matchdict['month'])
    dayno = int(request.matchdict['day'])
    ampm = request.matchdict['ampm']
    hourno = -1
    ampm_range = None
    if ampm == 'am':
        hourno = 0
        ampm_range = '00:00-12:00'
    elif ampm == 'pm':
        hourno = 12
        ampm_range = '12:00-00:00'
    try:
        selectdate = datetime(yearno, monthno, dayno, hourno)
        #print selectdate
        realtime = mylib.validClosestTime(selectdate)
        #print realtime
        if realtime.date() != selectdate.date() or realtime.hour != hourno:
            return redirect_day(request)
    except ValueError, e:
        print e
        return redirect_day(request)
def redirect_month(request):
    #try:
    methodtype = request.matchdict['accesstype']
    methodkey = request.matchdict['access']
    try:
        mylib = HSRLImageArchiveLibrarian(**{methodtype: methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#            return HTTPTemporaryRedirect(location=request.route_path("home"))
    if 'thumbtype' in request.matchdict and request.matchdict[
            'thumbtype'] != 'all':
        subtypekey = request.matchdict['thumbtype']
    else:
        subtypekey = None
    nowtime = datetime.utcnow()
    if 'year' in request.matchdict:
        yearno = int(request.matchdict['year'])
    else:
        yearno = nowtime.year
    if 'month' in request.matchdict:
        monthno = int(request.matchdict['month'])
    else:
        monthno = nowtime.month
    if 'day' in request.matchdict:
        dayno = int(request.matchdict['day'])
    elif monthno == nowtime.month and yearno == nowtime.year and subtypekey == None:
        dayno = nowtime.day
    else:
        dayno = 1
    d = validdate(yearno, monthno, dayno, 0, 0)
    besttime = mylib.validClosestTime(d)
    return HTTPTemporaryRedirect(location=monthurlfor(
        request, methodtype, methodkey, subtypekey, besttime))
def redirect_day(request):
    try:
        methodtype = request.matchdict['accesstype']
        methodkey = request.matchdict['access']
        nowtime = datetime.utcnow()
        try:
            mylib = HSRLImageArchiveLibrarian(**{methodtype: methodkey})
        except RuntimeError:
            return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")

        if 'year' in request.matchdict:
            yearno = int(request.matchdict['year'])
        else:
            yearno = nowtime.year
        if 'month' in request.matchdict:
            monthno = int(request.matchdict['month'])
        else:
            monthno = nowtime.month
        if 'day' in request.matchdict:
            dayno = int(request.matchdict['day'])
        else:
            dayno = nowtime.day
        if 'ampm' in request.matchdict:
            ampm = request.matchdict['ampm']
            if ampm == 'am':
                hourno = 0
            else:
                hourno = 12
        else:
            hourno = nowtime.hour
        besttime = mylib.validClosestTime(
            datetime(yearno, monthno, dayno, hourno, 0, 0))
        return HTTPTemporaryRedirect(
            location=dayurlfor(request, methodtype, methodkey, besttime))
    except:
        return HTTPTemporaryRedirect(location=request.route_path('home'))
Exemple #9
0
from sets import Set

from HSRLImageArchiveLibrarian import HSRLImageArchiveLibrarian
lib = HSRLImageArchiveLibrarian(indexdefault='site')
from pyramid.view import view_config


@view_config(route_name='imagejavascript', renderer='string')
@view_config(route_name='netcdfjavascript', renderer='string')
def formjavascript(request):
    methodtype = request.matchdict['accesstype']
    methodkey = request.matchdict['access']
    request.response.content_type = 'text/javascript'
    datasets = []
    try:
        for inst in lib(**{methodtype: methodkey})['Instruments']:
            datasets.extend(lib.instrument(inst)['datasets'])
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
    if request.matched_route.name == 'imagejavascript':
        return imagejavascriptgen(methodtype, methodkey, datasets,
                                  request.route_path('dataAvailability'))
    return netcdfjavascriptgen(methodtype, methodkey, datasets,
                               request.route_path('dataAvailability'))


setsfile = 'picnic/resources/portal_requestsets.json'


def formsetsForInstruments(instruments, subset):
    import json
Exemple #10
0
def form_view(request):
    #print 'URLREQ: ',request.matched_route.name
    methodtype = request.matchdict['accesstype']
    methodkey = request.matchdict['access']
    try:
        mylib = HSRLImageArchiveLibrarian(**{methodtype: methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    st = mylib()
    instruments = st['Instruments']
    instcount = len(instruments)
    name = st['Name']
    datasets = []
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])

    try:
        starttime = validdate(int(request.params.getone('byr')),
                              int(request.params.getone('bmo')),
                              int(request.params.getone('bdy')),
                              int(request.params.getone('bhr')),
                              int(request.params.getone('bmn')))
        endtime = validdate(int(request.params.getone('eyr')),
                            int(request.params.getone('emo')),
                            int(request.params.getone('edy')),
                            int(request.params.getone('ehr')),
                            int(request.params.getone('emn')))
        maxalt = float(request.params.getone('maxalt'))
        minalt = float(request.params.getone('minalt'))
    except:
        #print 'fallback'
        #print request.POST
        #print request.GET
        minalt = 0
        maxalt = 15
        lasttime = mylib.validClosestTime(datetime.utcnow())
        endtime = validdate(lasttime.year, lasttime.month, lasttime.day,
                            lasttime.hour,
                            lasttime.minute - (lasttime.minute % 5))
        starttime = validdate(endtime.year, endtime.month, endtime.day,
                              endtime.hour - 2, endtime.minute)

    oldformparmsdict = {
        methodtype: methodkey,
        'forcematlab': 'yes',
        'byr': '%i' % starttime.year,
        'bmo': '%i' % starttime.month,
        'bdy': '%i' % starttime.day,
        'bhr': '%i' % starttime.hour,
        'bmn': '%i' % starttime.minute,
        'eyr': '%i' % endtime.year,
        'emo': '%i' % endtime.month,
        'edy': '%i' % endtime.day,
        'ehr': '%i' % endtime.hour,
        'emn': '%i' % endtime.minute,
        'minalt': '%i' % minalt,
        'maxalt': '%i' % maxalt
    }
    oldformparams = '&'.join(
        (k + '=' + oldformparmsdict[k]) for k in oldformparmsdict.keys())
    #print oldformparams

    if request.matched_route.name == 'netcdfgen':
        oldurl = "http://lidar.ssec.wisc.edu/cgi-bin/processeddata/retrievedata.cgi?%s" % (
            oldformparams)
    if request.matched_route.name == 'imagegen':
        oldurl = "http://lidar.ssec.wisc.edu/cgi-bin/ahsrldisplay/requestfigs.cgi?%s" % (
            oldformparams)
    if False:  #instcount>3 :#more than just HSRL. python doesn't support it yet
        return HTTPTemporaryRedirect(location=oldurl)

    #print request
    # used in both forms, but simplifies template
    alts = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25,
            30]  #in kilometers
    # these are only used in netcdf, and not form-configurable. this simplifies the template
    altres = 30
    timeres = 30
    altresvals = [
        7.5, 15, 30, 45, 60, 75, 90, 120, 150, 300, 450, 600, 900, 1200
    ]  # in meters
    timeresvals = [
        2.5, 5, 10, 15, 30, 60, 120, 180, 240, 300, 600, 900, 1200, 3600, 43200
    ]  # in seconds

    #print instruments

    hosttouse = None
    porttouse = None
    if "X-Forwarded-Host" in request.headers:
        hosttouse = request.headers['X-Forwarded-Host']
        porttouse = ''

    return {
        'project':
        'Picnic',
        'bdate':
        starttime,
        'edate':
        endtime,
        'calendar':
        calendar,
        'timedelta':
        timedelta,
        'datetime':
        datetime,
        'altrange': [minalt, maxalt],
        'alts':
        alts,
        'timeresvals':
        timeresvals,
        'altresvals':
        altresvals,
        'timeres':
        timeres,
        'altres':
        altres,
        'imagesets':
        jsgen.formsetsForInstruments(datasets, 'images'),
        'netcdfsets':
        jsgen.formsetsForInstruments(datasets, 'netcdf'),
        'datasets':
        datasets,
        'method':
        methodtype,
        methodtype:
        methodkey,
        'oldurl':
        oldurl,
        'netcdfdestinationurl':
        request.route_url('netcdfreq', _host=hosttouse, _port=porttouse),
        'imagedestinationurl':
        request.route_url('imagereq', _host=hosttouse, _port=porttouse),
        'cdltemplates': {
            "hsrl_nomenclature.cdl": "UW HSRL(NetCDF4)",
            "hsrl_cfradial.cdl": "NCAR CFRadial",
            "hsrl3_processed.cdl": "UW Processed (NetCDF3)",
            "hsrl3_raw.cdl": "UW Raw (NetCDF3)",
            "custom": "User Provided:"
        },
        'cdltemplateorder': [
            "hsrl_nomenclature.cdl", "hsrl_cfradial.cdl",
            "hsrl3_processed.cdl", "hsrl3_raw.cdl", "custom"
        ],
        'userTracking':
        picnicsession.haveUserTracking(),
        #'usercheckurl':request.route_path('userCheck'),#'http://lidar.ssec.wisc.edu/cgi-bin/util/userCheck.cgi',
        'dataAvailabilityURL':
        request.route_path('dataAvailability'),
        'sitename':
        name,
        'setCount':
        setCount,
        'setGen':
        setGen,
        'make_archived_widget':
        server_archive.make_archived_widget,
        'archived_widget_head':
        server_archive.archived_widget_head
    }
Exemple #11
0
def form_view(request):
    #print 'URLREQ: ',request.matched_route.name
    methodtype=request.matchdict['accesstype']
    methodkey=request.matchdict['access']
    try:
        mylib=HSRLImageArchiveLibrarian(**{methodtype:methodkey})
    except RuntimeError:
        return HTTPNotFound(methodtype + "-" + methodkey + " is invalid")
#        return HTTPTemporaryRedirect(location=request.route_path("home"))
    st=mylib()
    instruments=st['Instruments']
    instcount=len(instruments)
    name=st['Name']
    datasets=[]
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])

    try:
        starttime=validdate(int(request.params.getone('byr')),
                            int(request.params.getone('bmo')),
                            int(request.params.getone('bdy')),
                            int(request.params.getone('bhr')),
                            int(request.params.getone('bmn')))
        endtime=validdate(int(request.params.getone('eyr')),
                          int(request.params.getone('emo')),
                          int(request.params.getone('edy')),
                          int(request.params.getone('ehr')),
                          int(request.params.getone('emn')))
        maxalt=float(request.params.getone('maxalt'))
        minalt=float(request.params.getone('minalt'))
    except:
        #print 'fallback'
        #print request.POST
        #print request.GET
        minalt=0
        maxalt=15
        lasttime=mylib.validClosestTime(datetime.utcnow())
        endtime=validdate(lasttime.year,lasttime.month,lasttime.day,lasttime.hour,lasttime.minute-(lasttime.minute%5))
        starttime=validdate(endtime.year,endtime.month,endtime.day,endtime.hour-2,endtime.minute)

    oldformparmsdict={methodtype:methodkey, 'forcematlab':'yes',
                      'byr':'%i' % starttime.year,
                      'bmo':'%i' % starttime.month,
                      'bdy':'%i' % starttime.day,
                      'bhr':'%i' % starttime.hour,
                      'bmn':'%i' % starttime.minute,
                      'eyr':'%i' % endtime.year,
                      'emo':'%i' % endtime.month,
                      'edy':'%i' % endtime.day,
                      'ehr':'%i' % endtime.hour,
                      'emn':'%i' % endtime.minute,
                      'minalt':'%i' % minalt,'maxalt':'%i' % maxalt}
    oldformparams='&'.join((k+'='+oldformparmsdict[k]) for k in oldformparmsdict.keys())
    #print oldformparams

    if request.matched_route.name=='netcdfgen':
        oldurl="http://lidar.ssec.wisc.edu/cgi-bin/processeddata/retrievedata.cgi?%s" % (oldformparams)
    if request.matched_route.name=='imagegen':
        oldurl="http://lidar.ssec.wisc.edu/cgi-bin/ahsrldisplay/requestfigs.cgi?%s" % (oldformparams)
    if False:#instcount>3 :#more than just HSRL. python doesn't support it yet
        return HTTPTemporaryRedirect(location=oldurl)


    #print request
    # used in both forms, but simplifies template
    alts=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,20,25,30] #in kilometers
    # these are only used in netcdf, and not form-configurable. this simplifies the template
    altres=30
    timeres=30
    altresvals=[7.5,15,30,45,60,75,90,120,150,300,450,600,900,1200] # in meters
    timeresvals=[2.5,5,10,15,30,60,120,180,240,300,600,900,1200,3600,43200] # in seconds

                                                                            #print instruments

    hosttouse=None
    porttouse=None
    if "X-Forwarded-Host" in request.headers:
        hosttouse=request.headers['X-Forwarded-Host']
        porttouse=''

    return {'project':'Picnic',
            'bdate':starttime,
            'edate':endtime,'calendar':calendar,'timedelta':timedelta,'datetime':datetime,
            'altrange':[minalt,maxalt],'alts':alts,
            'timeresvals':timeresvals,'altresvals':altresvals,
            'timeres':timeres,'altres':altres,
            'imagesets':jsgen.formsetsForInstruments(datasets,'images'),
            'netcdfsets':jsgen.formsetsForInstruments(datasets,'netcdf'),
            'datasets':datasets,'method':methodtype,methodtype:methodkey,
            'oldurl':oldurl,
            'netcdfdestinationurl':request.route_url('netcdfreq',_host=hosttouse,_port=porttouse),
            'imagedestinationurl':request.route_url('imagereq',_host=hosttouse,_port=porttouse),
            'cdltemplates':{
                "hsrl_nomenclature.cdl":"UW HSRL(NetCDF4)",
                "hsrl_cfradial.cdl":"NCAR CFRadial",
                "hsrl3_processed.cdl":"UW Processed (NetCDF3)",
                "hsrl3_raw.cdl":"UW Raw (NetCDF3)",
                "custom":"User Provided:"
            },
            'cdltemplateorder':[ "hsrl_nomenclature.cdl","hsrl_cfradial.cdl","hsrl3_processed.cdl","hsrl3_raw.cdl","custom"],
            'userTracking':picnicsession.haveUserTracking(),
            #'usercheckurl':request.route_path('userCheck'),#'http://lidar.ssec.wisc.edu/cgi-bin/util/userCheck.cgi',
            'dataAvailabilityURL':request.route_path('dataAvailability'),
            'sitename':name,'setCount':setCount,'setGen':setGen,'make_archived_widget':server_archive.make_archived_widget,'archived_widget_head':server_archive.archived_widget_head}