本文整理汇总了Python中pygeoc.utils.FileClass.get_filename_by_suffixes方法的典型用法代码示例。如果您正苦于以下问题:Python FileClass.get_filename_by_suffixes方法的具体用法?Python FileClass.get_filename_by_suffixes怎么用?Python FileClass.get_filename_by_suffixes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygeoc.utils.FileClass
的用法示例。
在下文中一共展示了FileClass.get_filename_by_suffixes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scenario_from_texts
# 需要导入模块: from pygeoc.utils import FileClass [as 别名]
# 或者: from pygeoc.utils.FileClass import get_filename_by_suffixes [as 别名]
def scenario_from_texts(cfg, main_db, scenario_db):
"""Import BMPs Scenario data to MongoDB
Args:
cfg: SEIMS configuration object
main_db: climate database
scenario_db: scenario database
Returns:
False if failed, otherwise True.
"""
if not cfg.use_scernario:
return False
print('Import BMP Scenario Data... ')
bmp_files = FileClass.get_filename_by_suffixes(cfg.scenario_dir, ['.txt'])
bmp_tabs = list()
bmp_tabs_path = list()
for f in bmp_files:
bmp_tabs.append(f.split('.')[0])
bmp_tabs_path.append(cfg.scenario_dir + os.path.sep + f)
# initialize if collection not existed
c_list = scenario_db.collection_names()
for item in bmp_tabs:
if not StringClass.string_in_list(item.upper(), c_list):
scenario_db.create_collection(item.upper())
else:
scenario_db.drop_collection(item.upper())
# Read subbasin.tif and dist2Stream.tif
subbasin_r = RasterUtilClass.read_raster(cfg.spatials.subbsn)
dist2stream_r = RasterUtilClass.read_raster(cfg.spatials.dist2stream_d8)
# End reading
for j, bmp_txt in enumerate(bmp_tabs_path):
bmp_tab_name = bmp_tabs[j]
data_array = read_data_items_from_txt(bmp_txt)
field_array = data_array[0]
data_array = data_array[1:]
for item in data_array:
dic = dict()
for i, field_name in enumerate(field_array):
if MathClass.isnumerical(item[i]):
v = float(item[i])
if v % 1. == 0.:
v = int(v)
dic[field_name.upper()] = v
else:
dic[field_name.upper()] = str(item[i]).upper()
if StringClass.string_in_list(ImportScenario2Mongo._LocalX, list(dic.keys())) and \
StringClass.string_in_list(ImportScenario2Mongo._LocalY, list(dic.keys())):
subbsn_id = subbasin_r.get_value_by_xy(
dic[ImportScenario2Mongo._LocalX.upper()],
dic[ImportScenario2Mongo._LocalY.upper()])
distance = dist2stream_r.get_value_by_xy(
dic[ImportScenario2Mongo._LocalX.upper()],
dic[ImportScenario2Mongo._LocalY.upper()])
if subbsn_id is not None and distance is not None:
dic[ImportScenario2Mongo._SUBBASINID] = int(subbsn_id)
dic[ImportScenario2Mongo._DISTDOWN] = float(distance)
scenario_db[bmp_tab_name.upper()].find_one_and_replace(dic, dic,
upsert=True)
else:
scenario_db[bmp_tab_name.upper()].find_one_and_replace(dic, dic,
upsert=True)
# print('BMP tables are imported.')
# Write BMP database name into Model workflow database
c_list = main_db.collection_names()
if not StringClass.string_in_list(DBTableNames.main_scenario, c_list):
main_db.create_collection(DBTableNames.main_scenario)
bmp_info_dic = dict()
bmp_info_dic[ImportScenario2Mongo._FLD_DB] = cfg.bmp_scenario_db
main_db[DBTableNames.main_scenario].find_one_and_replace(bmp_info_dic, bmp_info_dic,
upsert=True)
return True