├── .gitattributes ├── .gitignore └── St-dbscan.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /St-dbscan.py: -------------------------------------------------------------------------------- 1 | import math 2 | from xlrd import * 3 | Noise = 999999 4 | Unmarked = 99999 5 | filename = input('Enter file location:') 6 | book = open_workbook(filename) 7 | csheet = book.sheet_by_index(0) 8 | rw = csheet.nrows 9 | #rw = 30 10 | D = {} 11 | C = {} 12 | X = {} 13 | T = {} 14 | K = {} 15 | Cluster_Label = 0 16 | Minpts = math.log(rw) 17 | #print(Minpts) 18 | count = 0 19 | stack = 0 20 | 21 | print(Minpts) 22 | 23 | def eps1(x, y): 24 | return math.sqrt((x.lat - y.lat)**2 + (x.lon - y.lon)**2) 25 | 26 | def eps2(x, y): 27 | return math.sqrt((x.y1 - y.y1)**2 + (x.y2 - y.y2)**2) 28 | 29 | def Retrieve_Neighbours(x, n): 30 | T = {} 31 | Y = {} 32 | count = 0 33 | for r in range(rw): 34 | if n == r: 35 | continue 36 | else: 37 | e1 = eps1(x, D[r]) 38 | e2 = eps2(x, D[r]) 39 | print(e1, e2) 40 | if(e1 < 0.8 and e2 < 0.4): 41 | Y[count] = Data(D[r].acode, D[r].lat, D[r].lon, D[r].y1, D[r].y2, D[r].value) 42 | T[count] = r 43 | count += 1 44 | # print(count) 45 | return Y 46 | 47 | 48 | def push(x): 49 | Y = {} 50 | for j in range(count): 51 | Y[stack] = Data(D[T[j]].acode, D[T[j]].lat, D[T[j]].lon, D[T[j]].y1, D[T[j]].y2, D[T[j]].value) 52 | K[stack] = T[j] 53 | stack = stack + 1 54 | 55 | def pop(): 56 | stack = stack - 1 57 | return Y[stack] 58 | 59 | class Data: 60 | acode = 0.0 61 | lat = 0.0 62 | lon = 0.0 63 | y1 = 0.0 64 | y2 = 0.0 65 | value = 0.0 66 | clabel = Unmarked 67 | def __init__(self, acode, lat, lon, y1, y2, value): 68 | self.lat = lat 69 | self.lon = lon 70 | self.y1 = y1 71 | self.y2 = y2 72 | self.acode = acode 73 | self.value = value 74 | 75 | for r in range(rw): 76 | r0 = float(csheet.cell(r,0).value) 77 | r1 = float(csheet.cell(r,3).value) 78 | r2 = float(csheet.cell(r,4).value) 79 | r3 = float(csheet.cell(r,1).value) 80 | r4 = float(csheet.cell(r,2).value) 81 | r5 = float(csheet.cell(r,5).value) 82 | D[r] = Data(r0, r1, r2, r3, r4, r5) 83 | 84 | for r in range(rw): 85 | if D[r].clabel == Unmarked: 86 | X = Retrieve_Neighbours(D[r], r) 87 | if count < Minpts: 88 | D[r].clabel = Noise 89 | else : 90 | Cluster_label = Cluster_label + 1 91 | for j in range(count): 92 | D[T[j]].clabel = Cluster_label 93 | #print(D[T[j]].acode, D[T[j]].clabel) 94 | push(D[T[j]]) 95 | 96 | while(stack < 0): 97 | CurrentObj = pop() 98 | X = Retrieve_Neighbors(CurrentObj, K[stack]) 99 | 100 | if count < Minpts: 101 | for j in range(count): 102 | if D[T[j]].clabel != Noise or D[T[j]].clabel == Unmarked: 103 | D[T[j]].clabel = Cluster_label 104 | Push(D[T[j]]) 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | --------------------------------------------------------------------------------