def guinieranalysis(samplenames, qranges=None, qmax_from_shanum=True, prfunctions_postfix='<STR_LIT>', dist=None,<EOL>plotguinier=True, graph_extension='<STR_LIT>', dmax=None, dmax_from_shanum=False):
figpr = plt.figure()<EOL>ip = get_ipython()<EOL>axpr = figpr.add_subplot(<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>)<EOL>if qranges is None:<EOL><INDENT>qranges = {'<STR_LIT>': (<NUM_LIT:0>, <NUM_LIT>)}<EOL><DEDENT>if dmax is None:<EOL><INDENT>dmax = {'<STR_LIT>': None}<EOL><DEDENT>if '<STR_LIT>' not in qranges:<EOL><INDENT>qranges['<STR_LIT>'] = (<NUM_LIT:0>, <NUM_LIT>)<EOL><DEDENT>if '<STR_LIT>' not in dmax:<EOL><INDENT>dmax['<STR_LIT>'] = None<EOL><DEDENT>table_autorg = [['<STR_LIT:Name>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']]<EOL>table_gnom = [['<STR_LIT:Name>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']]<EOL>results = {}<EOL>for sn in samplenames:<EOL><INDENT>if sn not in qranges:<EOL><INDENT>print('<STR_LIT>'.format(sn))<EOL>qrange = qranges['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>qrange = qranges[sn]<EOL><DEDENT>if sn not in dmax:<EOL><INDENT>dmax_ = dmax['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>dmax_ = dmax[sn]<EOL><DEDENT>print('<STR_LIT>'.format(sn, qrange[<NUM_LIT:0>], qrange[<NUM_LIT:1>]))<EOL>curve = getsascurve(sn, dist)[<NUM_LIT:0>].trim(*qrange).sanitize()<EOL>curve.save(sn + '<STR_LIT>')<EOL>try:<EOL><INDENT>Rg, I0, qmin, qmax, quality, aggregation = autorg(sn + '<STR_LIT>')<EOL><DEDENT>except ValueError:<EOL><INDENT>print('<STR_LIT>' % sn)<EOL>continue<EOL><DEDENT>dmax_shanum, nsh, nopt, qmaxopt = shanum(sn + '<STR_LIT>')<EOL>if qmax_from_shanum:<EOL><INDENT>curve_trim = curve.trim(qmin, qmaxopt)<EOL><DEDENT>else:<EOL><INDENT>curve_trim = curve.trim(qmin, qrange[<NUM_LIT:1>])<EOL><DEDENT>if dmax_from_shanum:<EOL><INDENT>dmax_ = dmax_from_shanum<EOL><DEDENT>curve_trim.save(sn + '<STR_LIT>')<EOL>if dmax_ is None:<EOL><INDENT>print('<STR_LIT>'.format(<EOL>sn, Rg.val, curve_trim.q.min(), curve_trim.q.max()))<EOL>gnompr, metadata = datgnom(sn + '<STR_LIT>', Rg=Rg.val, noprint=True)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>'.format(<EOL>sn, dmax_, curve_trim.q.min(), curve_trim.q.max()))<EOL>gnompr, metadata = gnom(curve_trim, dmax_)<EOL><DEDENT>rg, i0, vporod = datporod(sn + '<STR_LIT>')<EOL>axpr.errorbar(gnompr[:, <NUM_LIT:0>], gnompr[:, <NUM_LIT:1>], gnompr[:, <NUM_LIT:2>], None, label=sn)<EOL>if plotguinier:<EOL><INDENT>figsample = plt.figure()<EOL>axgnomfit = figsample.add_subplot(<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:1>)<EOL>curve.errorbar('<STR_LIT>', axes=axgnomfit, label='<STR_LIT>')<EOL>axgnomfit.errorbar(metadata['<STR_LIT>'], metadata['<STR_LIT>'], metadata['<STR_LIT>'], None, '<STR_LIT>', label='<STR_LIT>')<EOL>axgnomfit.loglog(metadata['<STR_LIT>'], metadata['<STR_LIT>'], '<STR_LIT>', label='<STR_LIT>')<EOL>figsample.suptitle(sn)<EOL>axgnomfit.set_xlabel('<STR_LIT>')<EOL>axgnomfit.set_ylabel('<STR_LIT>')<EOL>axgnomfit.axvline(qmaxopt, <NUM_LIT:0>, <NUM_LIT:1>, linestyle='<STR_LIT>', color='<STR_LIT>', lw=<NUM_LIT:2>)<EOL>axgnomfit.grid(True, which='<STR_LIT>')<EOL>axgnomfit.axis('<STR_LIT>')<EOL>axgnomfit.legend(loc='<STR_LIT>')<EOL>axguinier = figsample.add_subplot(<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:2>)<EOL>axguinier.errorbar(curve.q, curve.Intensity, curve.Error, curve.qError, '<STR_LIT:.>', label='<STR_LIT>')<EOL>q = np.linspace(qmin, qmax, <NUM_LIT:100>)<EOL>axguinier.plot(q, I0.val * np.exp(-q ** <NUM_LIT:2> * Rg.val ** <NUM_LIT:2> / <NUM_LIT:3>), label='<STR_LIT>')<EOL>axguinier.plot(q, metadata['<STR_LIT>'].val * np.exp(-q ** <NUM_LIT:2> * metadata['<STR_LIT>'].val ** <NUM_LIT:2> / <NUM_LIT:3>),<EOL>label='<STR_LIT>')<EOL>axguinier.set_xscale('<STR_LIT>', exponent=<NUM_LIT:2>)<EOL>axguinier.set_yscale('<STR_LIT>')<EOL>axguinier.set_xlabel('<STR_LIT>')<EOL>axguinier.set_ylabel('<STR_LIT>')<EOL>axguinier.legend(loc='<STR_LIT>')<EOL><DEDENT>idxmin = np.arange(len(curve))[curve.q <= qmin].max()<EOL>idxmax = np.arange(len(curve))[curve.q >= qmax].min()<EOL>idxmin = max(<NUM_LIT:0>, idxmin - <NUM_LIT:5>)<EOL>idxmax = min(len(curve) - <NUM_LIT:1>, idxmax + <NUM_LIT:5>)<EOL>if plotguinier:<EOL><INDENT>curveguinier = curve.trim(curve.q[idxmin], curve.q[idxmax])<EOL>axguinier.axis(xmax=curve.q[idxmax], xmin=curve.q[idxmin], ymin=curveguinier.Intensity.min(),<EOL>ymax=curveguinier.Intensity.max())<EOL>axguinier.grid(True, which='<STR_LIT>')<EOL><DEDENT>table_gnom.append(<EOL>[sn, metadata['<STR_LIT>'].tostring(extra_digits=<NUM_LIT:2>), metadata['<STR_LIT>'].tostring(extra_digits=<NUM_LIT:2>),<EOL>metadata['<STR_LIT>'], metadata['<STR_LIT>'],<EOL>metadata['<STR_LIT>'], metadata['<STR_LIT>'], metadata['<STR_LIT>'], vporod])<EOL>table_autorg.append([sn, Rg.tostring(extra_digits=<NUM_LIT:2>), I0, '<STR_LIT>' % qmin, '<STR_LIT>' % qmax, qmin * Rg, qmax * Rg,<EOL>'<STR_LIT>' % (quality * <NUM_LIT:100>), aggregation, '<STR_LIT>' % dmax_shanum, '<STR_LIT>' % qmaxopt])<EOL>if plotguinier:<EOL><INDENT>figsample.tight_layout()<EOL>figsample.savefig(os.path.join(ip.user_ns['<STR_LIT>'], '<STR_LIT>' % (sn, graph_extension)),<EOL>dpi=<NUM_LIT>)<EOL><DEDENT>results[sn] = {<EOL>'<STR_LIT>'  : Rg, '<STR_LIT>': I0,<EOL>'<STR_LIT>': qmin, '<STR_LIT>': qmax,<EOL>'<STR_LIT>'    : quality, '<STR_LIT>': aggregation,<EOL>'<STR_LIT>': dmax_shanum, '<STR_LIT>': qmaxopt,<EOL>'<STR_LIT>'    : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'    : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'  : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'  : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'  : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'  : metadata['<STR_LIT>'],<EOL>'<STR_LIT>'     : vporod,<EOL>}<EOL><DEDENT>axpr.set_xlabel('<STR_LIT>')<EOL>axpr.set_ylabel('<STR_LIT>')<EOL>axpr.legend(loc='<STR_LIT>')<EOL>axpr.grid(True, which='<STR_LIT>')<EOL>writemarkdown('<STR_LIT>')<EOL>tab = ipy_table.IpyTable(table_autorg)<EOL>tab.apply_theme('<STR_LIT>')<EOL>display(tab)<EOL>writemarkdown('<STR_LIT>')<EOL>tab = ipy_table.IpyTable(table_gnom)<EOL>tab.apply_theme('<STR_LIT>')<EOL>if prfunctions_postfix and prfunctions_postfix[<NUM_LIT:0>] != '<STR_LIT:_>':<EOL><INDENT>prfunctions_postfix = '<STR_LIT:_>' + prfunctions_postfix<EOL><DEDENT>figpr.tight_layout()<EOL>figpr.savefig(os.path.join(ip.user_ns['<STR_LIT>'], '<STR_LIT>' % (prfunctions_postfix, graph_extension)),<EOL>dpi=<NUM_LIT>)<EOL>display(tab)<EOL>return results<EOL>
Perform Guinier analysis on the samples.

    Inputs:
        samplenames: list of sample names
        qranges: dictionary of q ranges for each sample. The keys are sample names. The special '__default__' key
            corresponds to all samples which do not have a key in the dict.
        qmax_from_shanum: use the qmax determined by the shanum program for the GNOM input.
        prfunctions_postfix: The figure showing the P(r) functions will be saved as
            prfunctions_<prfunctions_postfix><graph_extension>
        dist: the sample-to-detector distance to use.
        plotguinier: if Guinier plots are needed.
        graph_extension: the extension of the saved graph image files.
        dmax: Dict of Dmax parameters. If not found or None, determine automatically using DATGNOM. If found,
            GNOM is used. The special key '__default__' works in a similar fashion as for `qranges`.