@@ -41,55 +41,75 @@ def import_file(dataset_path):
41
41
42
42
return dataset
43
43
44
- def get_case_id_from_image_name (url_database_pic_names_to_case_id , picture_second_wave ):
45
-
46
- #Read file
47
- df_pic_names_to_case_ids = import_file (url_database_pic_names_to_case_id )
44
+
45
+ def get_case_id_from_image_name (survey_path , midline_pic_path ):
46
+
47
+ #Read survey
48
+ survey_df = import_file (survey_path )
48
49
49
50
#Get row for given image url
50
- df_image = df_pic_names_to_case_ids [ df_pic_names_to_case_ids ['picture_url' ]== picture_second_wave ]
51
+ df_image = survey_df [ survey_df ['picture_url' ]== midline_pic_path ]
51
52
52
53
#Return value in case_id column
53
54
case_id = df_image ['case_id' ].iloc [0 ]
54
55
return case_id
55
56
56
- if __name__ == '__main__' :
57
+ def main (baseline_pics_dir_path , midline_pics_dir_path , survey_path , pic_files_extension = '.JPG' ):
58
+ # survey.dta aregument is given when midline pics names is not their case id, survey.dta is use to get their caseid
57
59
58
- #To work when running from .exe with arguments
59
- if (len (sys .argv )== 4 ):
60
- url_folder_baseline_pics = abspath (sys .argv [1 ])
61
- url_folder_second_wave_pics = abspath (sys .argv [2 ])
62
- pic_names_to_case_id_file_url = abspath (sys .argv [3 ])
63
- else :
64
- print ("Did not give arguments" )
65
- sys .exit ()
60
+ #Make file_pairings df to call analyze_images
61
+ file_pairings = pd .DataFrame (columns = ['Picture baseline' , 'Picture midline' ])
66
62
67
- print (url_folder_baseline_pics )
68
- print (url_folder_second_wave_pics )
69
- print (pic_names_to_case_id_file_url )
63
+ #Generate path to pictures in midline
70
64
65
+ midline_pics_names = [f for f in listdir (midline_pics_dir_path ) if isfile (join (midline_pics_dir_path , f ))]
71
66
72
- #Make file_pairings df to call analyze_images
73
- file_pairings = pd .DataFrame (columns = ['Picture baseline' , 'Picture second-wave' ])
67
+ #For every picture in midline, check if it matches with its corresponding in baseline
68
+ for index , midline_pic_name in enumerate (midline_pics_names ):
69
+ midline_pic_path = join (midline_pics_dir_path , midline_pic_name )
74
70
75
- #For every picture in second_wave, check if it matches with its corresponding in baseline
76
-
77
- pictures_second_wave = [f for f in listdir (url_folder_second_wave_pics ) if isfile (join (url_folder_second_wave_pics , f ))]
78
- for index , picture_second_wave in enumerate (pictures_second_wave ):
79
- picture_second_wave = join (url_folder_second_wave_pics , picture_second_wave )
80
- #Get case id for this picture
81
- case_id = get_case_id_from_image_name (pic_names_to_case_id_file_url , picture_second_wave )
71
+ #If midline_pic caseid is not present in file name, get get case id from survey
72
+ if survey_path :
73
+ baseline_pic_name = get_case_id_from_image_name (survey_path , midline_pic_path )+ pic_files_extension
74
+ else :
75
+ baseline_pic_name = midline_pic_name
82
76
83
- #Get url of picture in baseline
84
- picture_baseline = url_folder_baseline_pics + '\\ ' + case_id + '.jpg' #We sure they will all be .jpg?
85
-
86
- #Save in df
87
- file_pairings .loc [index ] = [picture_baseline , picture_second_wave ]
77
+ #Get url of picture in baseline
78
+ baseline_pic_path = baseline_pics_dir_path + '\\ ' + baseline_pic_name
88
79
80
+ #Save in df
81
+ file_pairings .loc [index ] = [baseline_pic_path , midline_pic_path ]
89
82
90
- status , file_pairings = fvp .process_images (file_pairings )
83
+ file_pairings .to_csv ('a.csv' , index = False )
84
+ print (file_pairings )
85
+
86
+ status , file_pairings = fvp .process_images (file_pairings )
87
+ file_pairings .to_csv ('b.csv' , index = False )
88
+
89
+ print (file_pairings )
90
+ #
91
+ status , file_pairings = fvp .compare_images (file_pairings )
92
+ #
93
+ # #Save result
94
+ print ('e' )
95
+ file_pairings .to_csv ('results.csv' , index = False )
96
+
97
+ if __name__ == '__main__' :
98
+
99
+ #If no arguments given, use default for testing
100
+ if (len (sys .argv )== 1 ):
101
+ print ("Using default folder locations" )
102
+ baseline_pics_dir_path = "C:\\ Users\\ felip\\ Desktop\\ GYS Pictures\\ GYS Pictures_baseline\\ test"
103
+ midline_pics_dir_path = "C:\\ Users\\ felip\Desktop\\ GYS Pictures\\ GYS Pictures_midline\\ test"
104
+ survey_path = None
105
+ #To work when running from .exe with arguments
106
+ if (len (sys .argv )>= 3 ):
107
+ baseline_pics_dir_path = abspath (sys .argv [1 ])
108
+ midline_pics_dir_path = abspath (sys .argv [2 ])
91
109
92
- status , file_pairings = fvp .compare_images (file_pairings )
110
+ if (len (sys .argv )== 4 ):
111
+ survey_path = abspath (sys .argv [3 ])
112
+ else :
113
+ survey_path = None
93
114
94
- #Save result
95
- file_pairings .to_csv ('results.csv' , index = False )
115
+ main (baseline_pics_dir_path , midline_pics_dir_path , survey_path )
0 commit comments