def test_config_path_helper(self): # if it's none, return the default del os.environ['herd_config_path'] self.assertEqual(config_path(), os.path.expanduser("~/.herdconfig")) # if it's something return that os.environ['herd_config_path'] = "/mock/path/.herdconfig" self.assertEqual(config_path(), "/mock/path/.herdconfig")
def setconfig(section, key, value): """ set the key to the value in .herdconfig """ conf = ConfigParser() with open(config_path(), 'r') as configfile: conf.readfp(configfile) conf.add_section(section) conf.set(section, key, value) with open(config_path(), 'w') as configfile: conf.write(configfile)
def get_past_diagnosis(patient_id): config = config_path() patients_files = json.loads(open(config.patient_dict).read()) history = patients_files[patient_id] return (history)
def test_init(): path = cfg.config_path() run = cfg.config_run() param = cfg.config_param() test_param = cfg.param_test() csv_path = os.path.join(path.data_dir_top, test_param.csv_outs) if os.path.exists(csv_path): print("%s is exist!" % (csv_path)) else: os.makedirs(csv_path) print("creat the dir %s!" % (csv_path)) event_path = os.path.join(path.data_dir_top, path.event_top_dir, test_param.event_dir) if os.path.exists(event_path): print("%s is exist!" % (event_path)) else: os.makedirs(event_path) print("creat the dir %s!" % (event_path)) FLAGS.subset = str(run.mode) ## new param mode FLAGS.test_dir = str(event_path) FLAGS.checkpoint_dir = str( os.path.join(path.data_dir_top, test_param.model_dir)) FLAGS.data_dir = str( os.path.join(path.data_dir_top, test_param.tfrecord_dir)) FLAGS.csv_dir = csv_path FLAGS.input_queue_memory_factor = test_param.input_queue_memory_factor FLAGS.num_examples = test_param.num_example FLAGS.batch_size = test_param.batch_size FLAGS.run_once = test_param.run_once FLAGS.test_gpu_id = test_param.gpu_id return 0
def main(): path = cfg.config_path() if main_init() != 0: return 1 tmpl_param = get_tmpl_param() #tmpl land_mask computer raw_dir = os.path.join(path.top_dir, path.raw_dir) list_dir = os.listdir(raw_dir) for name in list_dir: name_path = os.path.join(path.top_dir, path.raw_dir, name) img_dat = mpimg.imread(name_path) hsd_dat = hsd_t.rgb2hsd(img_dat) he_label = pixc.patch_pixel_cluster(img_dat, 3) #ing_info include img_param and img_lm_label img_info = get_param(hsd_dat, he_label) #change mean and angle img_mean = img_info[0] img_angle = img_info[1] an_chg_hsd_h, an_chg_hsd_e = mean_angel_perprocess( hsd_dat, he_label, img_mean, img_angle) #get land mask ,and get img landmask label lm = exfeat.get_all_landmask(an_chg_hsd_h, an_chg_hsd_e, he_label) lm_label = lm_lab.get_all_lm_label() hsd_out = transform.transform_to_tmpl(hsd_dat, he_label, img_info, tmpl_param) save_hsd_img(hsd_out, name) return 0
def save_hsd_img(hsd, name): path = cfg.config_path() outs_path = os.path.join(path.top_dir, path.hsd_dir, name) img_dat = hsd_t.hsd2rgb(hsd) mpimg.imsave(outs_path, img_dat) return 0
def get_tmpl_param(): path = cfg.config_path() tmpl_path = os.path.join(path.top_dir, path.tmpl_name) img_dat = mpimg.imread(tmpl_path) hsd_dat = hsd_t.rgb2hsd(img_dat) he_label = pixc.patch_pixel_cluster(hsd_dat) return get_param(hsd_dat, he_label)
def get_current_goals(): config = config_path() goals_file = json.loads(open(config.goals_dict).read()) goals = goals_file[config.patient_id] if len(goals) == 0: return (('example: Hba1c level < 7;')) else: return (('\n'.join(goals) + ';'))
def eval_init(): path = cfg.config_path() #run = cfg.config_run() param = cfg.config_param() eavl_param = cfg.param_eval() FLAGS.num_gpus = param.gpu_num FLAGS.eval_dir = str( os.path.join(path.data_dir_top, path.event_top_dir, eavl_param.event_dir)) FLAGS.data_dir = str( os.path.join(path.data_dir_top, eavl_param.tfrecord_dir)) FLAGS.checkpoint_dir = str( os.path.join(path.data_dir_top, eavl_param.model_dir)) FLAGS.input_queue_memory_factor = eavl_param.input_queue_memory_factor FLAGS.num_examples = eavl_param.num_example FLAGS.batch_size = eavl_param.batch_size FLAGS.subset = eavl_param.mode_name FLAGS.run_once = eavl_param.run_once return 0
def train_init(): path = cfg.config_path() run = cfg.config_run() param = cfg.config_param() save_models_path = os.path.join(path.data_dir_top, path.save_models_dir) if os.path.exists(save_models_path): print("save models dir exist!") else: print("creat save models dir!") os.makedirs(save_models_path) FLAGS.train_dir = str(save_models_path) FLAGS.data_dir = str(os.path.join(path.data_dir_top, path.data_dir)) FLAGS.fine_tune = param.fine_tune FLAGS.initial_learning_rate = param.init_learning_rate FLAGS.input_queue_memory_factor = param.input_queue_memory_factor FLAGS.checkpoint_dir = str(os.path.join(path.data_dir_top, path.models_dir)) FLAGS.method_name = str(run.method_name) #FLAGS.pretrained_model_checkpoint_path = str(os.path.join(path.data_dir_top,path.models_dir,path.model_checkpoint)) FLAGS.batch_size = param.train_batch_size FLAGS.num_gpus = param.gpu_num FLAGS.max_steps = param.max_step FLAGS.subset = str(run.mode)
#!/usr/bin/env python3 import json import os import numpy as np import pandas as pd import networkx as nx from config import config_path config = config_path() def graph_sugg(): transcripts_dir = 'Transcripts' with open(config.transcript_D, 'r') as f: current_diagnoses = f.read() def neighbours_suggestions(graph, current_diagnoses, past_diagnoses): # Neighbours of the current diagnosis try: first = sum( [list(nx.all_neighbors(graph, v)) for v in current_diagnoses], []) except nx.exception.NetworkXError: first = [] # give weight 1 first = list(zip(first, np.repeat(1, len(first)))) # Neighbours of the past diagnoses try: second = sum(