本文整理汇总了Python中lofarpipe.support.data_map.DataMap.save方法的典型用法代码示例。如果您正苦于以下问题:Python DataMap.save方法的具体用法?Python DataMap.save怎么用?Python DataMap.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lofarpipe.support.data_map.DataMap
的用法示例。
在下文中一共展示了DataMap.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Prunes entries from a mapfile
Parameters
----------
mapfile_in : str
Filename of datamap to trim
prune_str : str
Entries starting with this string will be removed.
Returns
-------
result : dict
New datamap filename
"""
mapfile_in = kwargs['mapfile_in']
prune_str = kwargs['prune_str'].lower()
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
prunelen = len(prune_str)
map_out = DataMap([])
map_in = DataMap.load(mapfile_in)
for i, item in enumerate(map_in):
if item.file[:prunelen].lower() != prune_str:
map_out.data.append(DataProduct(item.host, item.file, item.skip))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例2: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile for selfcal images (assuming standard naming conventions)
Parameters
----------
selfcal_dir : str
Full path of selfcal directory
hosts : list or str
List of hosts/nodes. May be given as a list or as a string (e.g.,
'[host1, host2]'
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
Output datamap filename
"""
selfcal_dir = kwargs['selfcal_dir']
if type(kwargs['hosts']) is str:
hosts = kwargs['hosts'].strip('[]').split(',')
hosts = [h.strip() for h in hosts]
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
if os.path.exists(selfcal_dir):
selfcal_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image[01]2-MFS-image.fits'))
tec_iter_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image22_iter*-MFS-image.fits'))
if len(tec_iter_images) == 0:
tec_iter_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image22-MFS-image.fits'))
selfcal_images += tec_iter_images
selfcal_images += glob.glob(os.path.join(selfcal_dir, '*.wsclean_image[3]2-MFS-image.fits'))
selfcal_images += glob.glob(os.path.join(selfcal_dir, '*.wsclean_image42_iter*-MFS-image.fits'))
if len(selfcal_images) == 0:
selfcal_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image[01]2-image.fits'))
tec_iter_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image22_iter*-image.fits'))
if len(tec_iter_images) == 0:
tec_iter_images = glob.glob(os.path.join(selfcal_dir, '*.wsclean_image22-image.fits'))
selfcal_images += tec_iter_images
selfcal_images += glob.glob(os.path.join(selfcal_dir, '*.wsclean_image[3]2-image.fits'))
selfcal_images += glob.glob(os.path.join(selfcal_dir, '*.wsclean_image42_iter*-image.fits'))
selfcal_images.sort()
else:
selfcal_images = []
# Save image list as a string to the output mapfile
image_list = '[{0}]'.format(','.join(selfcal_images))
map_out = DataMap([])
map_out.data.append(DataProduct(hosts[0], image_list, False))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例3: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Copies each entry of mapfile_in as often as the the length of the corresponding
group into a new mapfile
Parameters
----------
mapfile_in : str
Name of the input mapfile to be expanded. (E.g. with the skymodels for the
different groups.)
mapfile_groups : str
Name of the multi-mapfile with the given groups. Number of groups need
to be the same as the number of files in mapfile_in.
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
ignore_dummies: str (optional)
If true, do not count dummy entries when expanding
Returns
-------
result : dict
Output datamap filename
"""
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
try:
ignore_dummies = str(kwargs['ignore_dummies']) # if the user has defined a dummy preference, follow it, otherwise count dummies as usual
ignore_dummies = ignore_dummies in ['true', 'True', '1', 'T', 't']
except:
ignore_dummies = False
inmap = DataMap.load(kwargs['mapfile_in'])
groupmap = MultiDataMap.load(kwargs['mapfile_groups'])
if len(inmap) != len(groupmap):
raise ValueError('PipelineStep_mapfileSingleToGroup: length of {0} and {1} differ'.format(kwargs['mapfile_in'],kwargs['mapfile_groups']))
map_out = DataMap([])
inindex = 0
if ignore_dummies:
for groupID in xrange(len(groupmap)):
for fileID in xrange(len(groupmap[groupID].file)):
if (groupmap[groupID].file)[fileID] != 'dummy_entry':
map_out.data.append(DataProduct(inmap[groupID].host, inmap[groupID].file, (inmap[groupID].skip or groupmap[groupID].skip) ))
else:
for groupID in xrange(len(groupmap)):
for fileID in xrange(len(groupmap[groupID].file)):
map_out.data.append(DataProduct(inmap[groupID].host, inmap[groupID].file, (inmap[groupID].skip or groupmap[groupID].skip) ))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例4: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Appends a string to filenames in a mapfile
Parameters
----------
mapfile_in : str
Filename of datamap to append to
append : str
String to append
append_index : bool
If True, append a unique index to each file
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
New datamap filename
"""
mapfile_in = kwargs['mapfile_in']
if 'append_index' in kwargs:
append_index = kwargs['append_index']
if type(append_index) is str:
if append_index.lower() == 'true':
append_index = True
else:
append_index = False
else:
append_index = False
append_str = kwargs['append']
if append_str == 'None':
append_str = ''
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
map_out = DataMap([])
map_in = DataMap.load(mapfile_in)
for i, item in enumerate(map_in):
if append_index:
map_out.data.append(DataProduct(item.host, item.file+append_str+'_{}'.format(i), item.skip))
else:
map_out.data.append(DataProduct(item.host, item.file+append_str, item.skip))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例5: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile for list of files
Parameters
----------
files : list or str
List of files or mapfile with such a list as the only entry. May be
given as a list of strings or as a string (e.g.,
'[s1.skymodel, s2.skymodel]'
hosts : list or str
List of hosts/nodes. May be given as a list or as a string (e.g.,
'[host1, host2]'
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
Output datamap filename
"""
if type(kwargs['files']) is str:
try:
# Check if input is mapfile containing list as a string
map_in = DataMap.load(kwargs['files'])
in_files = [item.file for item in map_in]
files = []
for f in in_files:
files += f.strip('[]').split(',')
except:
files = kwargs['files']
files = files.strip('[]').split(',')
files = [f.strip() for f in files]
if type(kwargs['hosts']) is str:
hosts = kwargs['hosts'].strip('[]').split(',')
hosts = [h.strip() for h in hosts]
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
for i in range(len(files)-len(hosts)):
hosts.append(hosts[i])
map_out = DataMap([])
for h, f in zip(hosts, files):
map_out.data.append(DataProduct(h, f, False))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例6: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile by compressing input mapfile items into one item
Parameters
----------
mapfile_in : str
Filename of datamap containing MS files
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
list_format : bool, optional
If True, the compreseed item will use a Python list format (e.g.,
'[file1, file2, ...]'. If False, it will be a space-separated list (e.g.,
'file1 file2 ...'
Returns
-------
result : dict
New parmdb datamap filename
"""
mapfile_in = kwargs['mapfile_in']
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
if 'list_format' in kwargs:
list_format = kwargs['list_format']
else:
list_format = True
if type(list_format) is str:
if list_format.lower() == 'true':
list_format = True
else:
list_format = False
map_in = DataMap.load(mapfile_in)
map_out = DataMap([])
map_in.iterator = DataMap.SkipIterator
file_list = [item.file for item in map_in]
if list_format:
newlist = '[{0}]'.format(','.join(file_list))
else:
newlist = '{0}'.format(' '.join(file_list))
# Just assign host of first file to compressed file
hosts = [item.host for item in map_in]
map_out.data.append(DataProduct(hosts[0], newlist, False))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例7: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Trims a string from filenames in a mapfile
Note that everything from the last instance of the matching string to the
end is trimmed.
Parameters
----------
mapfile_in : str
Filename of datamap to trim
trim_str : str
String to remove
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
counter : int
If counter is greater than 0, replace "image32" with "image42". This is
a special argument for facetselfcal looping only
Returns
-------
result : dict
New datamap filename
"""
mapfile_in = kwargs['mapfile_in']
trim_str = kwargs['trim']
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
if 'counter' in kwargs:
counter = int(kwargs['counter'])
else:
counter = 0
map_out = DataMap([])
map_in = DataMap.load(mapfile_in)
for i, item in enumerate(map_in):
index = item.file.rfind(trim_str)
if index >= 0:
item_trim = item.file[:index]
if counter > 0:
item_trim = item_trim.replace('image32', 'image42')
map_out.data.append(DataProduct(item.host, item_trim,
item.skip))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例8: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile by uncompressing input mapfile list item into separate items
Parameters
----------
mapfile_in : str
Filename of datamap containing list of MS files
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
hosts : str
List of hosts/nodes. May be given as a list or as a string
(e.g., '[host1, host2]'
Returns
-------
result : dict
New parmdb datamap filename
"""
mapfile_in = kwargs['mapfile_in']
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
if type(kwargs['hosts']) is str:
hosts = kwargs['hosts'].strip('[]').split(',')
hosts = [h.strip() for h in hosts]
map_in = DataMap.load(mapfile_in)
map_out = DataMap([])
files = map_in[0].file.strip('[]').split(',')
files = [f.strip() for f in files]
for i in range(len(files)-len(hosts)):
hosts.append(hosts[i])
for file, host in zip(files, hosts):
map_out.data.append(DataProduct(host, file, False))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例9: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Copies each entry of mapfile_in as often as the the length of the corresponding
group into a new mapfile
Parameters
----------
mapfile_in : str
Name of the input mapfile to be expanded. (E.g. with the skymodels for the
different groups.)
mapfile_groups : str
Name of the multi-mapfile with the given groups. Number of groups need
to be the same as the number of files in mapfile_in.
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
Output datamap filename
"""
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
inmap = DataMap.load(kwargs['mapfile_in'])
groupmap = MultiDataMap.load(kwargs['mapfile_groups'])
if len(inmap) != len(groupmap):
raise ValueError('PipelineStep_mapfileSingleToGroup: length of {0} and {1} differ'.format(kwargs['mapfile_in'],kwargs['mapfile_groups']))
map_out = DataMap([])
inindex = 0
for groupID in xrange(len(groupmap)):
for fileID in xrange(len(groupmap[groupID].file)):
map_out.data.append(DataProduct(inmap[groupID].host, inmap[groupID].file, (inmap[groupID].skip or groupmap[groupID].skip) ))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例10: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Selects those files from mapfile_in that have the same filename-base as the one in
mapfile_reference.
Parameters
----------
mapfile_in : str
Name of the input mapfile from which to select files.
mapfile_reference : str
Name of the reference mapfile
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
Output datamap filename
"""
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
inmap = DataMap.load(kwargs['mapfile_in'])
refmap = DataMap.load(kwargs['mapfile_reference'])
map_out = DataMap([])
basenames = [ os.path.splitext(os.path.basename(item.file))[0] for item in inmap]
for refitem in refmap:
refbase = os.path.splitext(os.path.basename(refitem.file))[0]
idx = basenames.index(refbase)
map_out.append(inmap[idx])
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例11: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile by filtering input mapfile items into one item (the middle
one)
Parameters
----------
mapfile_in : str
Filename of datamap containing MS files
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
New parmdb datamap filename
"""
mapfile_in = kwargs['mapfile_in']
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
map_in = DataMap.load(mapfile_in)
map_out = DataMap([])
map_in.iterator = DataMap.SkipIterator
files = [item.file for item in map_in]
hosts = [item.host for item in map_in]
if 'index' in kwargs:
index = int(kwargs['index'])
else:
index = len(files)/2
map_out.data.append(DataProduct(hosts[index], files[index], False))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例12: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Appends a string to filenames in a mapfile
Parameters
----------
mapfile_in : str
Filename of datamap to append to
append_str : str
String to append
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
New datamap filename
"""
mapfile_in = kwargs['mapfile_in']
append_str = kwargs['append']
if append_str == 'None':
append_str = ''
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
map_out = DataMap([])
map_in = DataMap.load(mapfile_in)
for i, item in enumerate(map_in):
map_out.data.append(DataProduct(item.host, item.file+append_str, item.skip))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例13: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Makes a mapfile by expanding single input mapfile item into many items
Parameters
----------
mapfile_in : str
Filename of datamap containing single item
mapfile_to_match : str
Filename of datamap containing multiple items
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
New parmdb datamap filename
"""
mapfile_in = kwargs['mapfile_in']
mapfile_to_match = kwargs['mapfile_to_match']
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
map_in = DataMap.load(mapfile_in)
map_match = DataMap.load(mapfile_to_match)
map_out = DataMap([])
map_match.iterator = DataMap.SkipIterator
for item in map_match:
map_out.data.append(DataProduct(item.host, map_in[0].file, item.skip))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例14: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Takes in mapfile_in, containing many files, and returns only one
Parameters
----------
mapfile_in : str
Parmdbs containing phase solutions
mapfile_dir : str
mapfile directory
filename : str
output filename
mapfile_comp : str
target MSs
Returns
-------
result : dict
Output datamap filename
"""
mapfile_dir = kwargs['mapfile_dir']
mapfile_in = kwargs['mapfile_in']
mapfile_comp = kwargs['mapfile_comp']
filename = kwargs['filename']
value = DataMap.load(mapfile_in)[0] # this the the single mapfile to be expanded
n = len(DataMap.load(mapfile_comp)) # these are actual MS files
map_out = DataMap([])
for i in range(n):
map_out.data.append(DataProduct(value.host,value.file, value.skip ))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result
示例15: plugin_main
# 需要导入模块: from lofarpipe.support.data_map import DataMap [as 别名]
# 或者: from lofarpipe.support.data_map.DataMap import save [as 别名]
def plugin_main(args, **kwargs):
"""
Takes in mapfile_in, containing many files, and returns only one
Parameters
----------
mapfile_in : str
Name of the input mapfile to be trimmed back.
mapfile_dir : str
Directory for output mapfile
filename: str
Name of output mapfile
Returns
-------
result : dict
Output datamap filename
"""
mapfile_dir = kwargs['mapfile_dir']
filename = kwargs['filename']
inmap = DataMap.load(kwargs['mapfile_in'])
if len(inmap)<1:
print('ERROR: GroupToSingle: mapfile_in has size < 1.')
return(1)
map_out = DataMap([])
map_out.data.append(DataProduct(inmap[0].host, inmap[0].file, inmap[0].skip ))
fileid = os.path.join(mapfile_dir, filename)
map_out.save(fileid)
result = {'mapfile': fileid}
return result