Exemple #1
0
def parseImageParametersBackground(request,session):
    picnicsession.updateSessionComment(session,'setup')
    if 'custom_display' in request.params and request.params.getone('custom_display')!='default':
        import hsrl.utils.json_config as jc
        disp=jc.json_config(picnicsession.loadjson(session,'display_parameters.json'))#session['display_defaults'])
    else:
        import hsrl.data_stream.display_utilities as du
        (disp,conf)=du.get_display_defaults(session['display_defaults_file'])

    #else:#fixme should this be enable_all()?
    #    (disp,conf)=du.get_display_defaults('web_plots.json')
    allfigs=session['figstocapture']==None
    if not allfigs:
        for k,v in session['figstocapture'].items():
            if None in v:
                allfigs=True
                break
    if not allfigs: # None indicates all should be captured, so if its not, scan structure
        data_req='images'
        lib_filetype='data'
        for fi in disp.get_attrs(): # for each figure
            if 'enable' in disp.get_labels(fi): # if it can be enabled/disabled
                disp.set_value(fi,'enable',0)
        for inst,figset in session['figstocapture'].items():
            for fi in disp.get_attrs(): # for each figure
                if 'enable' in disp.get_labels(fi): # if it can be enabled/disabled        
                    if fi in figset or ('#'+fi) in figset: #if requested, enable it
                        disp.set_value(fi,'enable',1)
                        if not fi.endswith('_image') and inst=='hsrl':
                            data_req='images housekeeping'
                            lib_filetype=None
                    elif ('-'+fi) in figset or ('-#'+fi) in figset:#if explicitly disabled, disable it
                        disp.set_value(fi,'enable',0)
    else:
        if session['figstocapture']!=None:
          for inst,figset in session['figstocapture'].items():
            for fi in disp.get_attrs(): # for each figure
                if 'enable' in disp.get_labels(fi): # if it can be enabled/disabled        
                    if ('-'+fi) in figset or ('-#'+fi) in figset:#if explicitly disabled, disable it
                        disp.set_value(fi,'enable',0)

        data_req= 'images housekeeping'
        lib_filetype=None

    picnicsession.storejson(session,disp.json_representation(),'display_parameters.json')
    if 'data_request' not in session:
        session['data_request']=data_req
    if 'lib_filetype' not in session:
        session['lib_filetype']=lib_filetype
    picnicsession.storesession(session)
Exemple #2
0
def parseImageParameters(request, session):

    methods = ['site', 'dataset', 'instrument']
    for m in methods:
        if m not in request.params:
            continue
        method = m
        session['method'] = method
        try:
            session[method] = int(request.params.getone(method))
            session['methodkey'] = int(request.params.getone(method))
        except:
            session[method] = request.params.getone(method)
            session['methodkey'] = request.params.getone(method)
        break
    starttime = datetime(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')), 0)
    endtime = datetime(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')), 0)
    session['altmin'] = float(request.params.getone('lheight')) * 1000
    session['altmax'] = float(request.params.getone('height')) * 1000
    session['starttime'] = starttime.strftime(picnicsession.json_dateformat)
    session['endtime'] = endtime.strftime(picnicsession.json_dateformat)
    #contstruct dpl
    datinfo = lib(**{method: session[method]})
    instruments = datinfo['Instruments']
    name = datinfo['Name']
    datasetname = instruments[0].lower()
    #print figstocapture
    datasets = []
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])

    #dplc=dpl_rti(datasetname,starttime,endtime,timedelta(seconds=timeres),endtime-starttime,altmin,altmax,altres);#alt in m
    #construct image generation parameters
    session['dataset'] = datasetname
    session['name'] = name

    if 'custom_processing' in request.params and request.params.getone(
            'custom_processing') != 'default':
        cust = request.params.getone('custom_processing')
        if cust == 'custom':
            try:
                pd = request.params.getone('process_parameters_content')
                pdc = pd.file.read()
                d = json.loads(pdc)  #.file.read())
            except:
                traceback.format_exc()
                return HTTPBadRequest()
        else:
            d = server_archive.get_archived_json(
                request.params.getone('custom_processing_token'), cust)
        #print 'Storing custom process parameters ',request.params.getone('process_parameters_content')
        picnicsession.storejson(session, d, 'process_parameters.json')
    #return HTTPTemporaryRedirect(location=request.route_path('progress_withid',session=sessionid))
    if 'custom_display' in request.params and request.params.getone(
            'custom_display') != 'default':
        cust = request.params.getone('custom_display')
        if cust == 'custom':
            pd = request.params.getone('display_defaults_content')
            print 'Storing custom image parameters to', session[
                'sessionid'], 'display_parameters.json'
            try:
                d = json.loads(pd.file.read())
            except:
                traceback.format_exc()
                return HTTPBadRequest()
        else:
            d = server_archive.get_archived_json(
                request.params.getone('custom_display_token'), cust)
        picnicsession.storejson(session, d, 'display_parameters.json')
        session['figstocapture'] = None
        getdatasets = datasets
        imagesetlist = jsgen.formsetsForInstruments(datasets, 'images')
        session['figrequest'] = {}
        for i in imagesetlist:
            session['figrequest'][i['formname']] = 'custom'
    elif 'display_defaults_file' in request.params:
        session['display_defaults_file'] = request.params.getone(
            'display_defaults_file')
        if os.path.sep in session['display_defaults_file']:
            session['display_defaults_file'] = picnicsession.sessionfile(
                session, session['display_defaults_file'])
        session['figstocapture'] = None
        getdatasets = datasets
        imagesetlist = jsgen.formsetsForInstruments(datasets, 'images')
        session['figrequest'] = {}
        for i in imagesetlist:
            session['figrequest'][i['formname']] = 'custom'
    else:
        session['display_defaults_file'] = 'all_plots.json'
        imagesetlist = jsgen.formsetsForInstruments(datasets, 'images')
        getdatasets = []
        figstocapture = {}
        session['figrequest'] = {}
        for i in imagesetlist:
            #print i
            try:
                setmode = request.params.getone(i['formname'])
                session['figrequest'][i['formname']] = setmode
                figstocapture[i['setenum']] = i['sets'][setmode]['figs']
                if len(i['sets'][setmode]['figs']) > 0:  #radio buttons
                    if 'enabled' in i['sets'][setmode]:
                        for dat in i['sets'][setmode]['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in i['sets'][setmode]:
                        for dat in i['sets'][setmode]['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                if "options" in i and len(
                        i["options"]
                ) > 0:  #checkboxes only currently, may extend to choicebox
                    for opt in i["options"]:
                        if opt["formname"] in request.params and request.params.getone(
                                opt['formname']):
                            if 'enabled' in opt:
                                for dat in opt['enabled']:
                                    if dat not in getdatasets:
                                        getdatasets.append(dat)
                            if 'required' in opt:
                                for dat in opt['required']:
                                    if dat not in getdatasets:
                                        getdatasets.append(dat)
                            figstocapture[i['setenum']].extend(opt['included'])
                        else:
                            for f in opt['included']:
                                figstocapture[i['setenum']].append('-' + f)
            except:
                pass
        session['figstocapture'] = figstocapture
    session['datastreams'] = getdatasets
    #if None in session['figstocapture']:
    picnicsession.storesession(session)
Exemple #3
0
def parseNetCDFParameters(request, session):
    session['timeres'] = float(request.params.getone('timeres'))
    session['altres'] = float(request.params.getone('altres'))
    session['maxtimeslice_timedelta'] = 60 * 60 * 2
    session['data_request'] = "images housekeeping"
    session['template'] = request.params.getone('cdltemplatename')
    if session['template'] == 'custom':
        fn = picnicsession.sessionfile(session, 'template.cdl', create=True)
        file(fn, 'w').write(
            request.params.getone('cdltemplate_content').file.read())
        session['template'] = fn
    stf = datetime.strptime(
        session['starttime'],
        picnicsession.json_dateformat).strftime('_%Y%m%dT%H%M')
    etf = datetime.strptime(
        session['endtime'],
        picnicsession.json_dateformat).strftime('_%Y%m%dT%H%M')
    session['filesuffix'] = ('_%gs_%gm' %
                             (session['timeres'], session['altres']))
    session['filemode'] = request.params.getone('filemode')
    session['fileprefix'] = session['dataset'] + '_' + session['filemode']
    session['filename'] = session['dataset'] + stf + etf + session[
        'filesuffix'] + '.nc'
    session['username'] = request.params.getone('username')

    datinfo = lib(**{session['method']: session[session['method']]})
    instruments = datinfo['Instruments']
    #print figstocapture
    datasets = []
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])

    fieldstocapture = []
    if not 'allfields' in request.params or not request.params.getone(
            'allfields'):
        fieldsetlist = jsgen.formsetsForInstruments(datasets, 'netcdf')
        getdatasets = []
        for inst in fieldsetlist:  #per instrument
            for subset in inst['sets']:
                subsetincluded = False
                for checkbox in subset['options']:
                    formname = checkbox['formname']
                    if formname not in request.params or not request.params.getone(
                            formname):
                        continue
                    subsetincluded = True
                    for fieldname in checkbox['included']:
                        if fieldname not in fieldstocapture:
                            fieldstocapture.append(fieldname)
                    if 'enabled' in checkbox:
                        for dat in checkbox['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in checkbox:
                        for dat in checkbox['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                if subsetincluded:
                    if 'included' in subset:
                        for fieldname in subset['included']:
                            if fieldname not in fieldstocapture:
                                fieldstocapture.append(fieldname)
                    if 'enabled' in subset:
                        for dat in subset['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in subset:
                        for dat in subset['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
    else:
        getdatasets = datasets
    session['datastreams'] = getdatasets

    print fieldstocapture
    session['selected_fields'] = fieldstocapture

    figstocapture = {}

    if 'custom_display' not in request.params or request.params.getone(
            'custom_display') == 'default':
        imagesetlist = jsgen.formsetsForInstruments(datasets, 'images')
        session['display_defaults_file'] = 'all_plots.json'

        for i in imagesetlist:
            #print i
            try:
                defmode = i['default']
                figstocapture[i['setenum']] = []
                for figname in i['sets'][defmode][
                        'figs']:  #get default images of default set
                    if 'image' in figname and figname not in figstocapture[
                            i['setenum']]:
                        figstocapture[i['setenum']].append(figname)
                if 'options' in i:  #and default options
                    for opt in i['options']:
                        if opt['default']:  #checkbox default is true
                            for figname in i['included']:
                                if 'image' in figname and figname not in figstocapture[
                                        i['setenum']]:
                                    figstocapture[i['setenum']].append(figname)
            except:
                pass
    else:
        figstocapture = None
    session['figstocapture'] = figstocapture
    session['lib_filetype'] = None
    picnicsession.storesession(session)
Exemple #4
0
def parseImageParametersBackground(request, session):
    picnicsession.updateSessionComment(session, 'setup')
    if 'custom_display' in request.params and request.params.getone(
            'custom_display') != 'default':
        import hsrl.utils.json_config as jc
        disp = jc.json_config(
            picnicsession.loadjson(
                session,
                'display_parameters.json'))  #session['display_defaults'])
    else:
        import hsrl.data_stream.display_utilities as du
        (disp,
         conf) = du.get_display_defaults(session['display_defaults_file'])

    #else:#fixme should this be enable_all()?
    #    (disp,conf)=du.get_display_defaults('web_plots.json')
    allfigs = session['figstocapture'] == None
    if not allfigs:
        for k, v in session['figstocapture'].items():
            if None in v:
                allfigs = True
                break
    if not allfigs:  # None indicates all should be captured, so if its not, scan structure
        data_req = 'images'
        lib_filetype = 'data'
        for fi in disp.get_attrs():  # for each figure
            if 'enable' in disp.get_labels(
                    fi):  # if it can be enabled/disabled
                disp.set_value(fi, 'enable', 0)
        for inst, figset in session['figstocapture'].items():
            for fi in disp.get_attrs():  # for each figure
                if 'enable' in disp.get_labels(
                        fi):  # if it can be enabled/disabled
                    if fi in figset or (
                            '#' + fi) in figset:  #if requested, enable it
                        disp.set_value(fi, 'enable', 1)
                        if not fi.endswith('_image') and inst == 'hsrl':
                            data_req = 'images housekeeping'
                            lib_filetype = None
                    elif ('-' + fi) in figset or (
                            '-#' +
                            fi) in figset:  #if explicitly disabled, disable it
                        disp.set_value(fi, 'enable', 0)
    else:
        if session['figstocapture'] != None:
            for inst, figset in session['figstocapture'].items():
                for fi in disp.get_attrs():  # for each figure
                    if 'enable' in disp.get_labels(
                            fi):  # if it can be enabled/disabled
                        if ('-' + fi) in figset or (
                                '-#' + fi
                        ) in figset:  #if explicitly disabled, disable it
                            disp.set_value(fi, 'enable', 0)

        data_req = 'images housekeeping'
        lib_filetype = None

    picnicsession.storejson(session, disp.json_representation(),
                            'display_parameters.json')
    if 'data_request' not in session:
        session['data_request'] = data_req
    if 'lib_filetype' not in session:
        session['lib_filetype'] = lib_filetype
    picnicsession.storesession(session)
Exemple #5
0
def parseImageParameters(request,session):

    methods=['site','dataset','instrument']
    for m in methods:
        if m not in request.params:
            continue
        method=m
        session['method']=method
        try:
            session[method]=int(request.params.getone(method));
            session['methodkey']=int(request.params.getone(method));
        except:
            session[method]=request.params.getone(method);
            session['methodkey']=request.params.getone(method);
        break
    starttime=datetime(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')),
                       0)
    endtime=datetime(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')),
                     0)
    session['altmin']=float(request.params.getone('lheight'))*1000
    session['altmax']=float(request.params.getone('height'))*1000
    session['starttime']=starttime.strftime(picnicsession.json_dateformat)
    session['endtime']=endtime.strftime(picnicsession.json_dateformat)
    #contstruct dpl
    datinfo=lib(**{method:session[method]})
    instruments=datinfo['Instruments']
    name=datinfo['Name']
    datasetname=instruments[0].lower()
    #print figstocapture
    datasets=[]
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])

    #dplc=dpl_rti(datasetname,starttime,endtime,timedelta(seconds=timeres),endtime-starttime,altmin,altmax,altres);#alt in m
    #construct image generation parameters
    session['dataset']=datasetname
    session['name']=name

    if 'custom_processing' in request.params and request.params.getone('custom_processing')!='default':
        cust=request.params.getone('custom_processing')
        if cust=='custom':
            try:
                pd=request.params.getone('process_parameters_content')
                pdc=pd.file.read()
                d=json.loads(pdc)#.file.read())
            except:
                traceback.format_exc()
                return HTTPBadRequest()
        else:
            d=server_archive.get_archived_json(request.params.getone('custom_processing_token'),cust)
        #print 'Storing custom process parameters ',request.params.getone('process_parameters_content')
        picnicsession.storejson(session,d,'process_parameters.json')
    #return HTTPTemporaryRedirect(location=request.route_path('progress_withid',session=sessionid))
    if 'custom_display' in request.params and request.params.getone('custom_display')!='default':
        cust=request.params.getone('custom_display')
        if cust=='custom':
            pd=request.params.getone('display_defaults_content')
            print 'Storing custom image parameters to',session['sessionid'],'display_parameters.json'
            try:
                d=json.loads(pd.file.read())
            except:
                traceback.format_exc()
                return HTTPBadRequest()
        else:
            d=server_archive.get_archived_json(request.params.getone('custom_display_token'),cust)
        picnicsession.storejson(session,d,'display_parameters.json')
        session['figstocapture']=None
        getdatasets=datasets
        imagesetlist=jsgen.formsetsForInstruments(datasets,'images')
        session['figrequest']={}
        for i in imagesetlist:
            session['figrequest'][i['formname']]='custom'
    elif 'display_defaults_file' in request.params:
        session['display_defaults_file']=request.params.getone('display_defaults_file')
        if os.path.sep in session['display_defaults_file']:
            session['display_defaults_file']=picnicsession.sessionfile(session,session['display_defaults_file'])
        session['figstocapture']=None
        getdatasets=datasets
        imagesetlist=jsgen.formsetsForInstruments(datasets,'images')
        session['figrequest']={}
        for i in imagesetlist:
            session['figrequest'][i['formname']]='custom'
    else:
        session['display_defaults_file']='all_plots.json'
        imagesetlist=jsgen.formsetsForInstruments(datasets,'images')
        getdatasets=[]
        figstocapture={}
        session['figrequest']={}
        for i in imagesetlist:
            #print i
            try:
                setmode=request.params.getone(i['formname'])
                session['figrequest'][i['formname']]=setmode
                figstocapture[i['setenum']]=i['sets'][setmode]['figs']
                if len(i['sets'][setmode]['figs'])>0:#radio buttons
                    if 'enabled' in i['sets'][setmode]:
                        for dat in i['sets'][setmode]['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in i['sets'][setmode]:
                        for dat in i['sets'][setmode]['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                if "options" in i and len(i["options"])>0:#checkboxes only currently, may extend to choicebox
                    for opt in i["options"]:
                        if opt["formname"] in request.params and request.params.getone(opt['formname']):
                                if 'enabled' in opt:
                                    for dat in opt['enabled']:
                                        if dat not in getdatasets:
                                            getdatasets.append(dat)
                                if 'required' in opt:
                                    for dat in opt['required']:
                                        if dat not in getdatasets:
                                            getdatasets.append(dat)
                                figstocapture[i['setenum']].extend(opt['included'])
                        else:
                            for f in opt['included']:
                                figstocapture[i['setenum']].append('-'+f)
            except:
                pass
        session['figstocapture']=figstocapture
    session['datastreams']=getdatasets
        #if None in session['figstocapture']:
    picnicsession.storesession(session)
Exemple #6
0
def parseNetCDFParameters(request,session):
    session['timeres']=float(request.params.getone('timeres'))
    session['altres']=float(request.params.getone('altres'))
    session['maxtimeslice_timedelta']=60*60*2
    session['data_request']="images housekeeping"
    session['template']=request.params.getone('cdltemplatename')
    if session['template']=='custom':
        fn=picnicsession.sessionfile(session,'template.cdl',create=True)
        file(fn,'w').write(request.params.getone('cdltemplate_content').file.read())
        session['template']=fn
    stf=datetime.strptime(session['starttime'],picnicsession.json_dateformat).strftime('_%Y%m%dT%H%M')
    etf=datetime.strptime(session['endtime'],picnicsession.json_dateformat).strftime('_%Y%m%dT%H%M')
    session['filesuffix']=('_%gs_%gm' % (session['timeres'],session['altres']))
    session['filemode']=request.params.getone('filemode')
    session['fileprefix']=session['dataset']+ '_' + session['filemode']
    session['filename']=session['dataset'] + stf + etf + session['filesuffix'] + '.nc'
    session['username']=request.params.getone('username')

    datinfo=lib(**{session['method']:session[session['method']]})
    instruments=datinfo['Instruments']
    #print figstocapture
    datasets=[]
    for inst in instruments:
        datasets.extend(lib.instrument(inst)['datasets'])
 
    fieldstocapture=[]
    if not 'allfields' in request.params or not request.params.getone('allfields'):
        fieldsetlist=jsgen.formsetsForInstruments(datasets,'netcdf')
        getdatasets=[]
        for inst in fieldsetlist:#per instrument
            for subset in inst['sets']:
                subsetincluded=False
                for checkbox in subset['options']:
                    formname=checkbox['formname']
                    if formname not in request.params or not request.params.getone(formname):
                        continue
                    subsetincluded=True
                    for fieldname in checkbox['included']:
                        if fieldname not in fieldstocapture:
                            fieldstocapture.append(fieldname)
                    if 'enabled' in checkbox:
                        for dat in checkbox['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in checkbox:
                        for dat in checkbox['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                if subsetincluded:
                    if 'included' in subset:
                        for fieldname in subset['included']:
                            if fieldname not in fieldstocapture:
                                fieldstocapture.append(fieldname)
                    if 'enabled' in subset:
                        for dat in subset['enabled']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
                    if 'required' in subset:
                        for dat in subset['required']:
                            if dat not in getdatasets:
                                getdatasets.append(dat)
    else:
        getdatasets=datasets
    session['datastreams']=getdatasets

    print fieldstocapture
    session['selected_fields']=fieldstocapture

    figstocapture={}

    if 'custom_display' not in request.params or request.params.getone('custom_display')=='default':
        imagesetlist=jsgen.formsetsForInstruments(datasets,'images')
        session['display_defaults_file']='all_plots.json'
      
        for i in imagesetlist:
            #print i
            try:
                defmode=i['default']
                figstocapture[i['setenum']]=[]
                for figname in i['sets'][defmode]['figs']:#get default images of default set
                    if 'image' in figname and figname not in figstocapture[i['setenum']]:
                        figstocapture[i['setenum']].append(figname)
                if 'options' in i:#and default options
                    for opt in i['options']:
                        if opt['default']:#checkbox default is true
                            for figname in i['included']:
                                if 'image' in figname and figname not in figstocapture[i['setenum']]:
                                    figstocapture[i['setenum']].append(figname)
            except:
                pass
    else:
        figstocapture=None
    session['figstocapture']=figstocapture
    session['lib_filetype']=None
    picnicsession.storesession(session)