示例#1
0
def experiment_list(request, instrument):
    """
        Return the list of experiments for a given instrument
        @param request: request object
        @param instrument: instrument name
    """
    
    breadcrumbs = Breadcrumbs("home", reverse('home'))
    breadcrumbs.append("%s catalog"%instrument.lower())
    
    experiments = get_experiments(instrument.upper())
    
    logger.debug("Catalog: %s : len(experiment list) = %s for %s"%(inspect.stack()[0][3],len(experiments),instrument))
    
    template_values = {'experiments': experiments,
                       'instrument': instrument,
                       'title': '%s experiments' % instrument.upper(),
                       'breadcrumbs': breadcrumbs}
    if len(experiments)==0:
        template_values['user_alert'] = ['Could not get experiment list from the catalog']
    template_values = remote_view_util.fill_template_values(request, **template_values)
    template_values = catalog_view_util.fill_template_values(request, **template_values)
    template_values = users_view_util.fill_template_values(request, **template_values)
    return render_to_response('catalog/experiment_list.html',
                              template_values,
                              context_instance=RequestContext(request))
示例#2
0
def download_autoreduced(request, instrument, ipts):
    """
        Download all the auto-reduced files for a given experiment.
        @param request: request object
        @param instrument: instrument name
        @param ipts: experiment name
    """
    # Start a new transaction
    transaction = remote_view_util.transaction(request, start=True)
    if transaction is None:
        
        breadcrumbs = Breadcrumbs()
        breadcrumbs.append_experiment_list(instrument)
        
        template_values = {'message':"Could not connect to Fermi and establish transaction",
                           'back_url': reverse('catalog_experiments', args=[instrument]),
                           'breadcrumbs': breadcrumbs,}
        template_values = remote_view_util.fill_template_values(request, **template_values)
        template_values = catalog_view_util.fill_template_values(request, **template_values)
        return render_to_response('remote/failed_connection.html',
                                  template_values)

    file_name = "%s_%s.zip" % (instrument.upper(), ipts)
    code =  'import os\n'
    code += 'import zipfile\n'
    code += 'output_zip_file = zipfile.ZipFile("%s", "w")\n' % file_name
    code += 'for f in os.listdir("/SNS/%s/%s/shared/autoreduce"):\n' % (instrument.upper(), ipts.upper())
    code += '    output_zip_file.write("/SNS/%s/%s/shared/autoreduce/"+f, f)\n' % (instrument.upper(), ipts.upper())
    code += 'output_zip_file.close()\n'
    jobID = remote_view_util.submit_job(request, transaction, code)

    return redirect(reverse('catalog_download_link', args=[jobID, file_name]))
示例#3
0
def download_link(request, job_id, filename):
    """
        Waiting page to get a link to download a zip file containing
        all the auto-reduced data for a given IPTS.
        @param request: request object
        @param job_id: remote job ID 
    """
    template_values = remote_view_util.fill_job_values(request, job_id)
    template_values = remote_view_util.fill_template_values(request, **template_values)
    template_values = catalog_view_util.fill_template_values(request, **template_values)
    template_values['title'] = 'Download area'
    template_values['file_name'] = filename
    return render_to_response('catalog/download_link.html',
                              template_values)
示例#4
0
def fill_template_values(request, **template_args):
    """
        Fill template values for the whole application
    """
    template_args = users_view_util.fill_template_values(request, **template_args)
    template_args = remote_view_util.fill_template_values(request, **template_args)
    
    # It may be the case that we are currently viewing a part of the site
    # belonging to an instrument-specific app. In this case, we'll already have
    # an instrument entry in the dictionary. We should exclude that instrument.
    reduction_apps = []
    instrument = None
    if 'instrument' in template_args:
        instrument = template_args['instrument']
        if instrument in settings.REDUCTION_AVAILABLE:
            reduction_apps.append({'name':instrument,
                           'url': reverse('reduction_home', args=[instrument])})
    template_args['reduction_apps'] = reduction_apps
    return template_args
示例#5
0
def instrument_list(request):
    """
        Return a list of available instruments
        @param request: request object
    """
    breadcrumbs = Breadcrumbs("home", None)
    instruments = get_instruments()
    
    logger.debug("Catalog: %s : List of instruments = %s"%(inspect.stack()[0][3],instruments))
    
    template_values = {'breadcrumbs': breadcrumbs}
    if len(instruments)==0:
#         if settings.DEBUG:
#             instruments=['eqsans']
        template_values['user_alert'] = ['Could not get instrument list from the catalog']
    template_values['instruments'] = instruments
    template_values = remote_view_util.fill_template_values(request, **template_values)
    template_values = catalog_view_util.fill_template_values(request, **template_values)
    template_values = users_view_util.fill_template_values(request, **template_values)
    return render_to_response('catalog/instrument_list.html',
                              template_values)
示例#6
0
def experiment_run_list(request, instrument, ipts):
    """
        Return a list of runs for a given experiment with the reduce link.
        The reduce link will generate a JQuery Dialog unique per instrument
        The configuration of the Dialog Box are in <instrument_name>.__init__.py
        under the funtion get_reduction_dialog_settings(ipts, run)
        @param request: request object
        @param instrument: instrument name
        @param ipts: experiment name
    """
    
    logger.debug("Catalog: %s : instrument = %s, IPTS = %s"%(inspect.stack()[0][3],instrument,ipts))
    
    
    
    breadcrumbs = Breadcrumbs("home", reverse('catalog'))
    breadcrumbs.append_experiment_list(instrument)
    breadcrumbs.append(ipts.lower())
        
    template_values = {'instrument': instrument,
                       'experiment': ipts,
                       'title': '%s %s' % (instrument.upper(), ipts.upper()),
                       'breadcrumbs': breadcrumbs}

    if users_view_util.is_experiment_member(request, instrument, ipts) is False:
        template_values['user_alert'] = ["You do not have access to this experiment data."]
    else:
        runs = get_ipts_runs(instrument.upper(), ipts)
        template_values['run_data'] = runs
        if len(runs) == 0:
            template_values['user_alert'] = ['No runs were found for instrument %s experiment %s' % (instrument, ipts)]
    # Fill in Fermi auth values, login info,
    template_values = remote_view_util.fill_template_values(request, **template_values)
    template_values = catalog_view_util.fill_template_values(request, **template_values)
    template_values = users_view_util.fill_template_values(request, **template_values)
    return render_to_response('catalog/experiment_run_list.html', template_values)
示例#7
0
def get_dummy_data(request, remote_job_id):
    """
        Create a dummy job and plot data
        @param request: request object
        @param job_id: RemoteJob pk
    """
    try:
        remote_job = RemoteJob.objects.get(pk=remote_job_id)
    except:
        eqsans = Instrument.objects.get(name='eqsans')
        reduction = ReductionProcess(instrument=eqsans,
                                     name='Dummy job',
                                     owner=request.user,
                                     data_file='/tmp/dummy.nxs')
        reduction.save()
        try:
            transaction = Transaction.objects.get(trans_id=-1)
        except:
            transaction = Transaction(trans_id=-1,
                                      owner=request.user,
                                      directory='/tmp')
            transaction.save()
        remote_job = RemoteJob(reduction=reduction,
                              remote_id='-1',
                              transaction=transaction)
        remote_job.save()
        
    breadcrumbs = "<a href='%s'>home</a>" % reverse(settings.LANDING_VIEW)
    breadcrumbs += " &rsaquo; <a href='%s'>eqsans reduction</a>" % reverse('reduction.views.reduction_home',args=['eqsans'])
    breadcrumbs += " &rsaquo; <a href='%s'>jobs</a>" % reverse('eqsans.views.reduction_jobs')
    breadcrumbs += " &rsaquo; dummy job"

    template_values = {'remote_job': remote_job,
                       'parameters': remote_job.reduction.get_data_dict(),
                       'reduction_id': remote_job.reduction.id,
                       'breadcrumbs': breadcrumbs,
                       'back_url': request.path}
    template_values = remote_view_util.fill_job_values(request, remote_job.remote_id, **template_values)
    template_values = users_view_util.fill_template_values(request, **template_values)
    template_values = remote_view_util.fill_template_values(request, **template_values)
    
    # Go through the files and find data to plot
    f = os.path.join(os.path.split(__file__)[0],'..','plotting','data','4065_Iq.txt')
                
    # Do we read this data already?
    plot_object = remote_job.get_first_plot(filename='4065_Iq.txt', owner=request.user)
    if plot_object is not None and plot_object.first_data_layout() is not None:
        data_str = plot_object.first_data_layout().dataset.data
    else:
        # If we don't have data stored, read it from file
        file_content = open(f,'r').read()
        data_str = view_util.process_Iq_data(file_content)
        plot_object = Plot1D.objects.create_plot(request.user,
                                                 data=data_str,
                                                 filename='4065_Iq.txt')
        remote_job.plots.add(plot_object)
    
    template_values['plot_1d'] = data_str
    template_values['plot_object'] = plot_object
    template_values['plot_1d_id'] = plot_object.id if plot_object is not None else None
    
    # Now the 2D data
    f = os.path.join(os.path.split(__file__)[0],'..','plotting','data','4065_Iqxy.nxs')
    plot_object2d = remote_job.get_plot_2d(filename='4065_Iqxy.nxs', owner=request.user)
    if plot_object2d is None:
        numpy.set_printoptions(threshold='nan', nanstr='0', infstr='0')
        fd = h5py.File(f, 'r')
        g = fd['mantid_workspace_1']
        y = g['workspace']['axis1']
        x = g['workspace']['axis2']
        values = g['workspace']['values']
        z_max = numpy.amax(values)
        numpy.set_string_function( lambda x: '['+','.join(map(lambda y:'['+','.join(map(lambda z: "%.4g" % z,y))+']',x))+']' )
        data_str_2d = values[:].__repr__()
        numpy.set_string_function( lambda x: '['+','.join(map(lambda z: "%.4g" % z,x))+']' )

        y_str = y[:].__repr__()
        x_str = x[:].__repr__()
        plot_object2d = Plot2D.objects.create_plot(user=request.user, data=data_str_2d,
                                                   x_axis=x_str, y_axis=y_str,
                                                   z_min=0.0, z_max=z_max, filename='4065_Iqxy.nxs')
        remote_job.plots2d.add(plot_object2d)

    template_values['plot_2d'] = plot_object2d

    return template_values