示例#1
0
def readFromFile_CoordsXYZ(FN, forceRead=False):
	# Sanity check filename:
	if not forceRead:
		doRegexMatch(FN,names.pixelCoordsFNRE)
	assert (fileExists(FN))

	# Read (x,y,z) coordinate:
	#dataRegex = myRE.compile(myRE.withinSpaces(myRE.floatREx3))
	dataRegex = myRE.compile(myRE.floatREx3)
	coords = np.fromregex(FN,dataRegex,dtype='f')
	# Return the array
	return coords
示例#2
0
def readFromFile_CoordsAB_header(FN, forceRead=False):
	# Sanity check filename:
	if not forceRead:
		doRegexMatch(FN,names.pixelCoords2DFNRE)
	assert (fileExists(FN))

	# Read header from coordinates file:
	coordsFile = open(FN)
	coordsFile_row1 = coordsFile.readline() # "a= [%f %f %f]" line
	coordsFile_row2 = coordsFile.readline() # "b= [%f %f %f]" line
	coordsFile_row3 = coordsFile.readline() # "%i %i" line, yielding (Na, Nb)
	coordsFile.close()

	# Analyse the read Strings:
	row1_RE = "a= \[" + myRE.withinSpaces(myRE.floatREx3) + "\]" 
	row1_RO = myRE.compile(row1_RE)
	span_a_str = myRE.getMatchingGroups(coordsFile_row1, row1_RO)
	row2_RE = "b= \[" + myRE.withinSpaces(myRE.floatREx3) + "\]" 
	row2_RO = myRE.compile(row2_RE)
	span_b_str = myRE.getMatchingGroups(coordsFile_row2, row2_RO)
	row3_RO = myRE.compile(myRE.group(myRE.intRE) + " " + myRE.group(myRE.intRE))
	npix_str = myRE.getMatchingGroups(coordsFile_row3, row3_RO)
	
	#print(span_a)
	#print(span_b)
	#print(npix)

	# Convert str tuple to ints/floats tuple:
	npix=()
	for item in npix_str:
		npix += (int(item),)
	span_a=()
	for item in span_a_str:
		span_a += (float(item),)
	span_b=()
	for item in span_b_str:
		span_b += (float(item),)

	# Done!
	return (npix, (span_a,span_b))
示例#3
0
def getResultDirs(mainDir):
	# Sanity:
	# TODO

	# List content of mainDir:
	content = sortArray(os.listdir(mainDir))
	#print("content = " + str(content))
	innerResDNs = myRE.getMatchingItems(content, myRE.compile(names.resInnerDNRE))
	if (len(innerResDNs) > 0):
		# We must have inner result directories
		# so return an array of them
		# First prepend mainDir:
		for i, item in enumerate(innerResDNs):
			innerResDNs[i] = os.path.join(mainDir, item)
		return innerResDNs
	else:
		# There are no inner result directories
		# so just return the main one
		return [mainDir]
示例#4
0
#! /usr/bin/env python3

import helpers.nameConventions as names
import helpers.regex as myRE

if __name__ == '__main__':
    print("Now testing writer:")
    print(names.resDN())
    print(names.resDN("a"))
    print(names.resInnerDN("2"))
    print(names.resInnerDN("73"))
    try:
        print(names.resInnerDN("a"))
    except:
        print("Inner result directory error with \"a\".")

    print("Now testing reader:")
    print(myRE.getMatch(names.resDN(), myRE.compile(names.resDNRE)))
    print(myRE.getMatch(names.resDN("a"), myRE.compile(names.resDNRE)))
    print(
        myRE.getMatch(names.resInnerDN("2"), myRE.compile(names.resInnerDNRE)))

# EOF
示例#5
0
	def natural_keys(text):
		try:
			return atof( myRE.getMatchingGroups(text, myRE.compile(r"[^\d]*" + myRE.group(myRE.floatRE)))[0] )
		except:
			return float("inf")
        "Required arguments for the chosen speckle contrast function (if any). "
        + "Separate the parameters with a semicolon (e.g., --args \"a;b\").")
    parser.add_option("-v",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="verbose [default: %default]")
    (opt, args) = parser.parse_args()
    myPrint.Printer.verbose = opt.verbose

    # Pre-parse arguments
    (SC_args, SC_kwargs) = RTS.multiArgStringToArgs(opt.SC_args)

    # Detect whether input is an intensity file or a directory:
    if myRE.doesItemMatch(os.path.basename(opt.inFDN),
                          myRE.compile(names.intensityFNRE)):
        # Then input is an intensity filename
        # Read input:
        (data, time, index) = optoFluidsIO.readFromFile_Intensity(opt.inFDN)
        # Compute and output:
        print(computeSpeckleContrast(data, opt.SC_func, *SC_args, **SC_kwargs))
    else:
        # Else input is not an intensity filename. Check whether it is a result directory.
        # Get multiple result directories (if any):
        resultDNs = optoFluidsIO.getResultDirs(opt.inFDN)
        # Compute:
        SCarray = []
        for resDN in resultDNs:
            # TODO: How to select the appropriate intensity file? CLI?
            try:  # Prioritize blurred:
                argument = resDN + '/2D/blurred/Intensity2D_t0.0'