Пример #1
0
def main(*args, **kwargs):
    print 'Running "ms_merge" script'

    # Find all multispec (.*vms.asc) files
    specfiles = spec.find_multispec()
    specfiles.sort()

    # file reading and validating loop
    exp_spectype = None
    new_bundle = None
    type_lkup = {'zv': spec.ZVSTSBundle, 'iv': spec.IVSTSBundle}
    for file_path in specfiles:
        try:
            spectype = re.search(r'\.([zi]v)ms(?:\.asc)?$', file_path).group(1)
            if exp_spectype is None:
                exp_spectype = spectype
            elif exp_spectype != spectype:
                print 'Cannot mix spectroscopy types'
                print 'ms_merge failed.'
                return None
            # END if
        except AttributeError:
            print '"{}" is not a multispec file'.format(file_path)
            print 'ms_merge failed.'
            return None
        # END try

        ms_data = type_lkup[spectype](file_path)

        if new_bundle is None:
            new_bundle = ms_data
        elif list(new_bundle.X) != list(ms_data.X):
            print 'Cannot concatenate multispecs with different domains'
            print '{}:'.format(file_path)
            print '  x_0 = {}'.format(ms_data.X[0])
            print '  x_{} = {}'.format(ms_data.curve_len, ms_data.X[-1])
            print 'Expected:'.format(file_path)
            print '  x_0 = {}'.format(new_bundle.X[0])
            print '  x_{} = {}'.format(new_bundle.curve_len, new_bundle.X[-1])
            print 'ms_merge failed.'
            return None
        # END if

        print u'\u2714 {}'.format(file_path)
        new_bundle.concat(ms_data)
    # END for

    # Create file name
    # ask for file name from user
    new_name = raw_input('Please enter name for new multispec file:\n-->')
    # remove any path syntax, force save in '.'
    new_name = re.sub(r'^(.*?)([^/]+)$', r'\2', new_name)
    # ensure the correct file extention, ".[zi]vms"
    if not re.search(r'\.[zi]vms$', new_name):
        new_name += '.' + exp_spectype + 'ms'
    # END if
    new_bundle.save_multispec(new_name)
    print 'saved as "{}"'.format(new_name)

    print 'ms_merge is finished.'
Пример #2
0
def main(*args, **kwargs):
	print 'Running "ms_merge" script'
	
	# Find all multispec (.*vms.asc) files
	specfiles = spec.find_multispec()
	specfiles.sort()
	
	# file reading and validating loop
	exp_spectype = None
	new_bundle = None
	type_lkup = {'zv': spec.ZVSTSBundle, 'iv': spec.IVSTSBundle}
	for file_path in specfiles:
		try:
			spectype = re.search(r'\.([zi]v)ms(?:\.asc)?$', file_path).group(1)
			if exp_spectype is None:
				exp_spectype = spectype
			elif exp_spectype != spectype:
				print 'Cannot mix spectroscopy types'
				print 'ms_merge failed.'
				return None
			# END if
		except AttributeError:
			print '"{}" is not a multispec file'.format(file_path)
			print 'ms_merge failed.'
			return None
		# END try
		
		ms_data = type_lkup[spectype](file_path)
		
		if new_bundle is None:
			new_bundle = ms_data
		elif list(new_bundle.X) != list(ms_data.X):
			print 'Cannot concatenate multispecs with different domains'
			print '{}:'.format(file_path)
			print '  x_0 = {}'.format(ms_data.X[0])
			print '  x_{} = {}'.format(ms_data.curve_len, ms_data.X[-1])
			print 'Expected:'.format(file_path)
			print '  x_0 = {}'.format(new_bundle.X[0])
			print '  x_{} = {}'.format(new_bundle.curve_len, new_bundle.X[-1])
			print 'ms_merge failed.'
			return None
		# END if
		
		print u'\u2714 {}'.format(file_path)
		new_bundle.concat(ms_data)
	# END for
	
	# Create file name
	# ask for file name from user
	new_name = raw_input('Please enter name for new multispec file:\n-->')
	# remove any path syntax, force save in '.'
	new_name = re.sub(r'^(.*?)([^/]+)$', r'\2', new_name)
	# ensure the correct file extention, ".[zi]vms"
	if not re.search(r'\.[zi]vms$', new_name):
		new_name += '.'+exp_spectype+'ms'
	# END if
	new_bundle.save_multispec(new_name)
	print 'saved as "{}"'.format(new_name)
	
	print 'ms_merge is finished.'
Пример #3
0
def main(path='./', flags=set()):
	print 'Running "quick_plots_simple" script in {}'.format(path)
	
	# Handle recursive search option
	recursive = False
	if 'r' in flags:
		recursive = True
		print '*Including all sub-folders'
	# END if
	
	# Handle the no-rewrite option
	only_new = False
	if 'n' in flags:
		only_new = True
		print '*Making new plots only'
	# END if
	
	# Find all multispec (.*vms.asc) files
	specfiles = spec.find_multispec(path, recursive)
	specfiles.sort()
	
	# For no-rewrite option create a list of exclusions
	if only_new:
		skips = set()
		files_stack = ['./'+f for f in os.listdir(path)]
		while len(files_stack) > 0:
			target = files_stack.pop()
			name_match = re.search(
				r'^.*?([^/]+?)-(?:zv|dzdv|iv|didv|ndidv)\.png$', target
			)
			if recursive and os.path.isdir(target):
				for f in os.listdir(target): files_stack.append(target+'/'+f)
			elif name_match and name_match.group(1) not in skips:
				skips.add( name_match.group(1) )
			# END if
		# END while
	# END if
	
	# Plotting loop
	for file_path in specfiles:
		path_mat = re.search(r'^(.+?)([^/]+)$', file_path)
		path = path_mat.group(1)
		file_name = path_mat.group(2)
		
		if (only_new
		and re.sub(r'\.[zi]vms(?:\.asc)?', '', file_name) in skips):
			continue
		
		type_mat = re.search(r'\.([zi]v)ms(?:\.asc)?$', file_name)
		spectype = type_mat.group(1)
		if spectype == 'zv':
			zv_subroutine(path, file_name)
		elif spectype == 'iv':
			iv_subroutine(path, file_name)
		else:
			print "don't know what to do with {}".format(file_name)
		# END if
	# END for
	
	print 'quick_plots_simple is finished.'
Пример #4
0
def main(path='./', flags=set()):
    print 'Running "quick_plots_simple" script in {}'.format(path)

    # Handle recursive search option
    recursive = False
    if 'r' in flags:
        recursive = True
        print '*Including all sub-folders'
    # END if

    # Handle the no-rewrite option
    only_new = False
    if 'n' in flags:
        only_new = True
        print '*Making new plots only'
    # END if

    # Find all multispec (.*vms.asc) files
    specfiles = spec.find_multispec(path, recursive)
    specfiles.sort()

    # For no-rewrite option create a list of exclusions
    if only_new:
        skips = set()
        files_stack = ['./' + f for f in os.listdir(path)]
        while len(files_stack) > 0:
            target = files_stack.pop()
            name_match = re.search(
                r'^.*?([^/]+?)-(?:zv|dzdv|iv|didv|ndidv)\.png$', target)
            if recursive and os.path.isdir(target):
                for f in os.listdir(target):
                    files_stack.append(target + '/' + f)
            elif name_match and name_match.group(1) not in skips:
                skips.add(name_match.group(1))
            # END if
        # END while
    # END if

    # Plotting loop
    for file_path in specfiles:
        path_mat = re.search(r'^(.+?)([^/]+)$', file_path)
        path = path_mat.group(1)
        file_name = path_mat.group(2)

        if (only_new
                and re.sub(r'\.[zi]vms(?:\.asc)?', '', file_name) in skips):
            continue

        type_mat = re.search(r'\.([zi]v)ms(?:\.asc)?$', file_name)
        spectype = type_mat.group(1)
        if spectype == 'zv':
            zv_subroutine(path, file_name)
        elif spectype == 'iv':
            iv_subroutine(path, file_name)
        else:
            print "don't know what to do with {}".format(file_name)
        # END if
    # END for

    print 'quick_plots_simple is finished.'
Пример #5
0
def main(*args, **kwargs):
	print 'Running "inspect" script'
	
	# Find all multispec (.*vms.asc) files
	specfiles = spec.find_multispec()
	specfiles.sort()
	
	# Curve plotting loop
	type_lkup = {'zv': spec.ZVSTSBundle, 'iv': spec.IVSTSBundle}
	for file_path in specfiles:
		print 'Plotting all from "{}"'.format(file_path)
		path_mat = re.search(r'^(.*?)\.([zi]v)ms(?:\.asc)?$', file_path)
		new_foldername = path_mat.group(1)
		spectype = path_mat.group(2)
		all_curves = type_lkup[spectype](file_path)
		
		# Make new folder for saving individual plots
		if not os.path.exists(new_foldername):
			os.makedirs(new_foldername)
		
		X = all_curves.X
		for i in range(all_curves.N):
			save_path = new_foldername+'/curve_{0:03d}.png'.format(i)
			if os.path.exists(save_path): continue
			
			Y = all_curves.allY[i]
			fig = plt.figure()
			ax = fig.add_subplot(111)
			ax.plot(X, Y)
			spec.pltformat_basic(ax)
			ax.set_title( 'Curve i={}'.format(i) )
			
			fig.savefig(save_path, dpi=100)
			plt.close(fig)
		# END for
	# END for
	
	print 'inspect is finished.'
Пример #6
0
def main_alt(path='./', flags=set()):
	print 'Running "filename_fix" script'
	
	# Simulate flag
	simulate = False
	if 's' in flags:
		simulate = True
		print '*Simulating file name changes'
	# END if
	
	# Find all multispec (.*vms.asc or .*vms) files
	specfiles = spec.find_multispec(path)
	specfiles.sort()
	
	# file renaming loop
	for file_path in allfiles:
		fname = os.path.basename(file_path)
		print '"{}"'.format(fname)
		
		tags = re.search(r'''
			^( \d{6}                                         ) #0 date
			(  (?:-\d{4})?                                   ) #1 time
			(  (?:-[^-]+)*?                                  ) #2 pre-index
			(  -\d+ (?:_\d+ (?:_[fubd]+)?)? (?:-[A-Z]{1,2})? ) #3 index
			(  (?: -[^-]+ )*                                 ) #4 post-index
			(  \.[zi]vms (?:\.asc)?                         )?$ #5 file-extention
			''', fname, re.VERBOSE
		).groups()
		
		new_name = tags[0] + tags[1] + tags[2] + tags[4]
		new_name += re.sub(r'(?<!^)-', '_', tags[3])
		new_name += re.sub(r'\.asc', '', tags[5])
		
		print '  -->"{}"'.format(new_name)
		if not simulate and new_name != fname: os.rename(fname, new_name)
	# END for
	
	print 'filename_fix is finished.'
Пример #7
0
def main_alt(path='./', flags=set()):
    print 'Running "filename_fix" script'

    # Simulate flag
    simulate = False
    if 's' in flags:
        simulate = True
        print '*Simulating file name changes'
    # END if

    # Find all multispec (.*vms.asc or .*vms) files
    specfiles = spec.find_multispec(path)
    specfiles.sort()

    # file renaming loop
    for file_path in allfiles:
        fname = os.path.basename(file_path)
        print '"{}"'.format(fname)

        tags = re.search(
            r'''
			^( \d{6}                                         ) #0 date
			(  (?:-\d{4})?                                   ) #1 time
			(  (?:-[^-]+)*?                                  ) #2 pre-index
			(  -\d+ (?:_\d+ (?:_[fubd]+)?)? (?:-[A-Z]{1,2})? ) #3 index
			(  (?: -[^-]+ )*                                 ) #4 post-index
			(  \.[zi]vms (?:\.asc)?                         )?$ #5 file-extention
			''', fname, re.VERBOSE).groups()

        new_name = tags[0] + tags[1] + tags[2] + tags[4]
        new_name += re.sub(r'(?<!^)-', '_', tags[3])
        new_name += re.sub(r'\.asc', '', tags[5])

        print '  -->"{}"'.format(new_name)
        if not simulate and new_name != fname: os.rename(fname, new_name)
    # END for

    print 'filename_fix is finished.'
Пример #8
0
def main(*args, **kwargs):
    print 'Running "inspect" script'

    # Find all multispec (.*vms.asc) files
    specfiles = spec.find_multispec()
    specfiles.sort()

    # Curve plotting loop
    type_lkup = {'zv': spec.ZVSTSBundle, 'iv': spec.IVSTSBundle}
    for file_path in specfiles:
        print 'Plotting all from "{}"'.format(file_path)
        path_mat = re.search(r'^(.*?)\.([zi]v)ms(?:\.asc)?$', file_path)
        new_foldername = path_mat.group(1)
        spectype = path_mat.group(2)
        all_curves = type_lkup[spectype](file_path)

        # Make new folder for saving individual plots
        if not os.path.exists(new_foldername):
            os.makedirs(new_foldername)

        X = all_curves.X
        for i in range(all_curves.N):
            save_path = new_foldername + '/curve_{0:03d}.png'.format(i)
            if os.path.exists(save_path): continue

            Y = all_curves.allY[i]
            fig = plt.figure()
            ax = fig.add_subplot(111)
            ax.plot(X, Y)
            spec.pltformat_basic(ax)
            ax.set_title('Curve i={}'.format(i))

            fig.savefig(save_path, dpi=100)
            plt.close(fig)
        # END for
    # END for

    print 'inspect is finished.'
Пример #9
0
def main(path='./', flags=set()):
	print sys.version
	print 'Running "quick_plots" script in {}'.format(path)
	
	# Handle recursive search option
	recursive = False
	if 'r' in flags:
		recursive = True
		print '*Including all sub-folders'
	# END if
	
	# Handle the no-rewrite option
	only_new = False
	if 'n' in flags:
		only_new = True
		print '*Making new plots only'
	# END if
	
	# Handle the multiprocessing options
	top_gear = False
	first_gear = False
	if 'm' in flags:
		first_gear = True
		print '*Optioned to run everything under a single process'
	elif 'M' in flags:
		top_gear = True
		print '*Optioned to run full number of processes'
	# END if
	
	# Find all multispec (.*vms.asc) files
	specfiles = spec.find_multispec(path, recursive)
	specfiles.sort()
	
	# For no-rewrite option create a list of exclusions
	if only_new:
		skips = set()
		files_stack = ['./'+f for f in os.listdir(path)]
		while len(files_stack) > 0:
			target = files_stack.pop()
			name_match = re.search(
				r'^.*?([^/]+?)-(?:zv|dzdv|iv|didv|ndidv)\.png$', target
			)
			if recursive and os.path.isdir(target):
				for f in os.listdir(target): files_stack.append(target+'/'+f)
			elif name_match and name_match.group(1) not in skips:
				skips.add( name_match.group(1) )
			# END if
		# END while
	# END if
	
	# Setup the worker processes pool
	N_procs = mproc.cpu_count()
	if first_gear:
		N_procs = 1
	elif not top_gear:
		# Default to using one less process than the total number of processors,
		# for safety
		N_procs -= 1
		if N_procs == 0:
			N_procs = 1
			print (
				'*Default safe running conditions will only use'
				+ 'a single process on this system'
			)
		# END if
	# END if
	pool = mproc.Pool(processes=N_procs, maxtasksperchild=12)
	
	# Plotting loop
	for file_path in specfiles:
		path_mat = re.search(r'^(.+?)([^/]+)$', file_path)
		path = path_mat.group(1)
		file_name = path_mat.group(2)
		
		if (only_new
		and re.sub(r'\.[zi]vms(?:\.asc)?', '', file_name) in skips):
			continue
		
		type_mat = re.search(r'\.([zi]v)ms(?:\.asc)?$', file_name)
		spectype = type_mat.group(1)
		if spectype == 'zv':
			pool.apply_async(zv_subroutine, args=(path, file_name))
		elif spectype == 'iv':
			if os.path.exists(re.sub(r'\.ivms', '.gvms', file_path)):
				pool.apply_async(giv_subroutine, args=(path, file_name))
			else:
				pool.apply_async(iv_subroutine, args=(path, file_name))
		else:
			print "don't know what to do with {}".format(file_name)
		# END if
	# END for
	
	pool.close()
	pool.join()
	
	print 'quick_plots is finished.'