示例#1
0
def configuration_submit(request, config_id):
    """
    General reduction uses the /reduction URL prefix.
    
    For SEQ, it is specific. A configuration is a single submission.
    Thus the URL is:
    /seq/configuration/(?P<config_id>\d+)/submit$
    http://localhost:8000/seq/configuration/75/submit
    
    Contrary to EQSANS, for SEQ, 1 configuration has 1 reduction!
    
    @param request: request object
    @param config_id: pk of configuration
    """
        
    logger.debug("Specific SEQ Submit: %s"%(inspect.stack()[0][3]))
 
    instrument_forms = reduction_view_util.import_module_from_app(INSTRUMENT_NAME,'forms') 
    forms_handler = instrument_forms.ConfigurationFormHandler(request,config_id)
    reduction_config = get_object_or_404(ReductionConfiguration, pk=config_id, owner=request.user)
    reductions = reduction_config.reductions.all()
    
    if len(reductions) <= 0:
        messages.add_message(request, messages.ERROR, message="No jobs submitted. Configuration %s does not have any reduction data files associated."%config_id)
    else:
        # Start a new transaction
        transaction = remote.view_util.transaction(request, start=True)
        if transaction is None:
            messages.add_message(request, messages.ERROR, message="Could not get a transaction ID from Fermi. Try the submission again...")
        else:
            job_set = RemoteJobSet(transaction=transaction,
                                   configuration=reduction_config)
            job_set.save()
            
            code = forms_handler.get_mantid_script(None, transaction.directory)
            number_of_nodes,cores_per_node = forms_handler.get_processing_nodes_and_cores()
            
            jobID = remote.view_util.submit_job(request, transaction, code,number_of_nodes,cores_per_node)
            
            if jobID is not None:
                # In EQSANS one config has several reductions. For QEQ is different. We just use one reduction! 
                # However the remote job must have entries for all the redution processes:
                for r in reductions:
                    job = RemoteJob(reduction=r,
                                    remote_id=jobID,
                                    properties=r.properties,
                                    transaction=transaction)
                    job.save()
                    job_set.jobs.add(job) 
                messages.add_message(request, messages.SUCCESS, 
                                     message="Job set %s sucessfully submitted. <a href='%s' class='message-link'>Click to see the results this job set</a>."%
                                     (job_set.id, reverse('configuration_query', kwargs={'remote_set_id' : job_set.id, 'instrument_name' : "seq"})))
            else:
                messages.add_message(request, messages.ERROR, message="The job was not submitted. There was an internal problem with Fermi. The fermi administrators have been notified.")
        
    redirect_url = reverse('configuration_options',
                           kwargs={'config_id' : config_id, 'instrument_name' : INSTRUMENT_NAME})
    logger.debug("Redirecting to %s"%redirect_url)
    return redirect(redirect_url)
示例#2
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