-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.py
59 lines (46 loc) · 2.4 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os, sys, time, json
from synthMD import MDimport, MDprepare, MDcreate, MDevaluate, MDutils
# censusAPIKey="put your api key here"
censusAPIKey= None
# if this script called directly,
if __name__ == "__main__":
# testing
if len(sys.argv) > 1:
print("input: ", sys.argv)
# #print(os.getcwd())
startTimeTotal = time.time()
cfgPath = os.path.join("config","configUSA.json")
resultsPath = "output"
# Folder and file paths
usaFolderPath = os.path.join("datasets", "usa")
usaRaceDataPath = os.path.join(usaFolderPath, "usa-2020-states-race.csv")
usaAgeSexDataFolderPath = os.path.join(usaFolderPath, "usaAge2020-2021")
usaAgeSexDataFilePath = os.path.join(usaFolderPath,"usa-2020-states-age-sex.csv")
usaAgeSexMaleDataFilePath = os.path.join(usaFolderPath,"usa-2020-states-age-sex-male.csv")
usaAgeSexFemaleDataFilePath = os.path.join(usaFolderPath,"usa-2020-states-age-sex-female.csv")
usaAgeSexTotalDataFilePath = os.path.join(usaFolderPath,"usa-2020-states-age-sex-total.csv")
usaAgeSexDataFilesPath = [usaAgeSexMaleDataFilePath,usaAgeSexFemaleDataFilePath,usaAgeSexTotalDataFilePath]
catlabels=["male","female","total"]
doImport = 1
doPrepare = 1
doCreate = 1
doEvaluation = 1
if doImport:
# Import/download USA census data
# Use proxy if needed
proxies ={}
MDimport.getUSACensusData(censusAPIKey=censusAPIKey, datasetFolder=usaFolderPath)
if doPrepare:
# Preprocessing
cfg = json.load(open(cfgPath))
MDprepare.getPreparedData(cfg, usaRaceDataPath, usaAgeSexDataFolderPath, usaAgeSexDataFilePath, usaAgeSexMaleDataFilePath, usaAgeSexFemaleDataFilePath, usaAgeSexTotalDataFilePath, catlabels)
if doCreate:
# ---------------- Creating Synthetic Datasets --------------------
cfg, RDsData, raceData, usaAgeSexData, usaAgeSexGroupData, paths = MDutils.readInputFiles(cfgPath)
MDcreate.createSyntheticDatasets(cfg, RDsData, raceData, usaAgeSexData, usaAgeSexGroupData, paths, doEvaluation= 0)
# Note evaluation can be done faster with createSyntheticDatasets function above
if doEvaluation:
MDevaluate.getAllEvaluation(cfgPath)
endTmTotal = time.time() - startTimeTotal
print("Total time = ", endTmTotal, " seconds")
print("------------------- All tasks are done! -------------------------")