Пример #1
0
def _get_deflate_data(deflater):
    buf = jarray.zeros(1024, 'b')
    sb = lang.StringBuffer()
    while not deflater.finished():
        l = deflater.deflate(buf)
        if l == 0:
            break
        sb.append(lang.String(buf, 0, 0, l))
    return sb.toString()
Пример #2
0
def _toXML(filter, pretty=True, version=1.0):
  """
  Encodes a filter object as XML.

  """

  ogc, ogcconfig = _ogc(version)
  e = Encoder(ogcconfig)
  e.indenting = pretty
  e.omitXMLDeclaration = True
  out = io.ByteArrayOutputStream()
  e.encode(filter, ogc.Filter, out)
  return str(lang.String(out.toByteArray()))
Пример #3
0
def toInputStream(o):
    if isinstance(o, (io.InputStream, io.Reader, file)):
        return o

    f = toFile(o)
    if isinstance(f, io.File) and f.exists():
        return io.FileInputStream(f)

    if isinstance(o, (str, unicode)):
        return io.ByteArrayInputStream(lang.String(o).getBytes())

    if type(o).__name__ == 'array':
        return io.ByteArrayInputStream(o)
Пример #4
0
def _get_inflate_data(inflater, max_length=0):
    buf = jarray.zeros(1024, 'b')
    sb = lang.StringBuffer()
    total = 0
    while not inflater.finished():
        if max_length:
            l = inflater.inflate(buf, 0, min(1024, max_length - total))
        else:
            l = inflater.inflate(buf)
        if l == 0:
            break

        total += l
        sb.append(lang.String(buf, 0, 0, l))
        if max_length and total == max_length:
            break
    return sb.toString()
Пример #5
0
 def sendStringToPrinter( self, data , type = jprint.DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST ):
     
     hatt = jatt.HashDocAttributeSet()
     type = jprint.DocFlavor.INPUT_STREAM.AUTOSENSE
     bais = java.io.ByteArrayInputStream( jlang.String( data ).getBytes( "US-ASCII" ) )
     sdoc = jprint.SimpleDoc( bais, type , hatt )
     pservices = jprint.PrintServiceLookup.lookupPrintServices( type , hatt )
     print pservices
     
     if pservices:
         hpattset = jatt.HashPrintRequestAttributeSet()
         ps = jprint.ServiceUI.printDialog( None, 50, 50, pservices, pservices[ 0 ], type , hpattset )
         if ps:
             dpj = ps.createPrintJob()
             dpj.addPrintJobListener( self.PrintJobReporter() )
             try:
                 dpj.print( sdoc, hpattset )
             except jlang.Exception, x:
                 g.es( "Could not execute print job", color='red' )
Пример #6
0
    def findXpathNodes(self, xmlAsText, xpathExpr):
        xmlText = InputSource(
            ByteArrayInputStream(lang.String(xmlAsText).getBytes()))
        docBuilderFactory = DocumentBuilderFactory.newInstance()
        docBuilderFactory.setValidating(0)
        docBuilderFactory.setNamespaceAware(0)
        docBuilder = docBuilderFactory.newDocumentBuilder()
        doc = docBuilder.parse(xmlText)
        xpathFactory = XPathFactory.newInstance()
        xPath = xpathFactory.newXPath()
        expr = xPath.compile(xpathExpr)

        nodeList = expr.evaluate(doc, XPathConstants.NODESET)
        nodeCount = nodeList.getLength()
        count = 0
        xpathNodes = []
        while count < nodeCount:
            xpathNodes.append(nodeList.item(count))
            count = count + 1
        return xpathNodes
Пример #7
0

# In fact it is easy for users to write their own Scannables (like VM's in JCLAM or Pseudo Motors in SPEC).  To do this, a minimum of only three methods need to be written - so its quick to write them.
# Scannables have levels so they are operated in order during a scan.
# Scannables can be set to be 'default'  (see the add default above) so they are implicitly operated in every scan.
#The data points from each scan will be shown in the display.  To have each scan plot to a brand new graph, then check the tick box at the bottom of the plotting area on the Terminal tab

#==================== Using Java from Jython ==========================================
#import Java packages as needed
import java.lang as lang

#Invoke the Java static method:
lang.System.out.println("Hello Jython from Java");

#Create Java instance the same way as create Python object, without using the Java new keyword
myStr = lang.String("Zot");

#The Java method can be invoked in two way:
#1. bounded way
print myStr.startsWith("Z")

#2. Unbounded way
print lang.String.startsWith(myStr, "Z");
  
#jarrays
import jarray
x=jarray.zeros(200,"i");
print x;

import java.lang.Math
y=java.lang.Math.sqrt(256);
Пример #8
0
def to10dash1(action_code,
              sample_id,
              specs,
              instrument_analysis_date,
              analysis_lab_id="N",
              srm_id="IIIE",
              pkg_lab_id="N",
              instrument="E",
              instrument_number="2",
              spot_size="5",
              operator="NWMR",
              spectrometer="EDS15",
              comment={}):
    """to10dash1(
	action_code, 
	sample_id, 
	specs, 
	instrument_analysis_date, 
	analysis_lab_id="N", 
	srm_id="IIIE", 
	pkg_lab_id="N", 
	instrument="I", 
	instrument_number="1", 
	spot_size="5", 
	operator="NWMR", 
	spectrometer="EDS15", 
	comment={}
)
	* action_code = "N", "R" or "D"
	* sample_id unique id
	* specs = selected() or a list of spectra
	* instrument_analysis_date = "10-DEC-2020" or equivalent for date of acquisition
	* srm_id = "IIIX" where "X" is the letter of your block
	* pkg_lab and analysis_lab_id = your lab ID letter
	* instrument - Instrument id
	* spot_size a number in unspecified units as a string
	* operator = "Your initials"
	* spectrometer = the spectrometer ID
	* comment = { element("Fe"):"Eat more iron", element("Si"):"Sillycone" } or similar
	
The function prints a line per element for each element in the "MicroanalyticalComposition" property of the selected spectra.  The selected spectra are
assumed to come from the same material.  The "_error" columns reflect the standard deviation between the spectra not the single spectrum uncertainty."""
    def savg(vals):
        s = 0.0
        for val in vals:
            s = s + val
        return s / len(vals)

    def sstd(vals):
        s, s2 = savg(vals), 0.0
        for val in vals:
            s2 += (val - s) * (val - s)
        return jl.Math.sqrt(s2 / len(vals))

    elms = ju.TreeSet()
    props = specs[0].getProperties()
    e0 = props.getNumericProperty(epq.SpectrumProperties.BeamEnergy)
    beam_current = "%0.3f" % (props.getNumericProperty(
        epq.SpectrumProperties.FaradayBegin), )
    for spec in specs:
        mat = spec.getProperties().getObjectProperty(
            epq.SpectrumProperties.MicroanalyticalComposition)
        elms.addAll(mat.getElementSet())
    for elm in elms:
        comment.setifabsent(elm, "")
    wfa, afa, ks, cr = {}, {}, {}, []
    for spec in specs:
        props = spec.getProperties()
        mat = props.getObjectProperty(
            epq.SpectrumProperties.MicroanalyticalComposition)
        krs = props.getObjectProperty(epq.SpectrumProperties.OptimalKRatios)
        cr.append(
            epq.SpectrumUtils.integrate(spec, 100.0, 1000.0 * e0) /
            props.getNumericProperty(epq.SpectrumProperties.LiveTime))
        for elm in elms:
            wfa.setifabsent(elm,
                            []), afa.setifabsent(elm,
                                                 []), ks.setifabsent(elm, []),
            wfa[elm].append(mat.weightFraction(elm, False))
            afa[elm].append(mat.atomicPercent(elm))
            xrts = krs.optimalDatum(elm)
            ks[elm].append(krs.getKRatio(xrts) if xrts != None else 0.0)
    full = ""
    for elm in elms:
        weight_percent = "%0.2f" % (100.0 * savg(wfa[elm]), )
        weight_percent_error = "%0.2f" % (100.0 * sstd(wfa[elm]), )
        atom_percent = "%0.2f" % (100.0 * savg(afa[elm]), )
        atom_percent_error = "%0.2f" % (100.0 * sstd(afa[elm]), )
        amount = ("MAJOR" if weight_percent > 10.0 else
                  ("MINOR" if weight_percent > 1.0 else "TRACE"))
        k_value = "%0.4f" % (savg(ks[elm]), )
        normalization_factor = ""
        normalization_model = ""
        count_rate = "%0.0f" % (savg(cr))
        diffracting_crystal = "NA"
        incident_beam_energy = "%0.1f" % (e0, )
        star_elemental_comments = comment[elm]
        element = str(jl.String(elm.toAbbrev()).toUpperCase())
        item = (action_code, sample_id, srm_id, pkg_lab_id, analysis_lab_id,
                element, instrument, instrument_number,
                instrument_analysis_date, operator, weight_percent,
                weight_percent_error, atom_percent, atom_percent_error, amount,
                k_value, normalization_factor, normalization_model, count_rate,
                diffracting_crystal, spectrometer, e0, beam_current, spot_size,
                star_elemental_comments)
        res = "%1s%07i %-6s %1s %1s %-3s %-2s %-3s %-11s %12s %12s %12s %12s %12s %5s %12s %12s %3s %12s %-6s %5s %4s %5s %5s %s" % item
        full = "%s%s\n" % (full, res)
        print(res)
    return full[0:-1]