Skip to content

Commit a83e4df

Browse files
Making code PEP8 compliant
1 parent f5e2b81 commit a83e4df

16 files changed

+1224
-948
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E501
4+
; extend-ignore = E203, E501, E231, E731, E741

LoopProjectFile/DataCollection.py

Lines changed: 213 additions & 155 deletions
Large diffs are not rendered by default.

LoopProjectFile/Extents.py

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
import netCDF4
1+
# import netCDF4
2+
23

34
# Check extents of Loop Project File is valid
45
def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
56
"""
67
**CheckExtentsValid** - Checks for valid extents (geodesic, utm, depth,
78
and spacing) and working format in project file
8-
9+
910
Parameters
1011
----------
1112
rootGroup: netCDF4.Group
1213
The root group node of a Loop Project File
13-
xyzGridSize: [int,int,int]
14+
xyzGridSize: [int, int, int]
1415
The 3D grid shape of expected data contained in this project file
1516
based on the extents contained within
1617
verbose: bool
1718
A flag to indicate a higher level of console logging (more if True)
18-
19+
1920
Returns
2021
-------
2122
bool
2223
True if valid extents in project file, False otherwise.
23-
24+
2425
"""
2526
valid = True
2627
# Check Projection Model
2728
if "workingFormat" in rootGroup.ncattrs():
28-
if verbose: print(" Working in ", "Geodesic" if rootGroup.workingFormat == 0 else "UTM", " Projection")
29+
if verbose:
30+
print(" Working in ", "Geodesic" if rootGroup.workingFormat == 0 else "UTM", " Projection")
2931
else:
3032
print("(INVALID) No working format (Geodesic or UTM selection) in project file")
3133
valid = False
3234

3335
# Check Geodesic extents
34-
if "minLatitude" in rootGroup.ncattrs() \
35-
and "maxLatitude" in rootGroup.ncattrs() \
36-
and "minLongitude" in rootGroup.ncattrs() \
37-
and "maxLongitude" in rootGroup.ncattrs():
38-
if verbose:
36+
if ("minLatitude" in rootGroup.ncattrs()
37+
and "maxLatitude" in rootGroup.ncattrs()
38+
and "minLongitude" in rootGroup.ncattrs()
39+
and "maxLongitude" in rootGroup.ncattrs()):
40+
if verbose:
3941
print(" Geodesic extents found (deg)")
4042
print("\t minLatitude = ", rootGroup.minLatitude)
4143
print("\t maxLatitude = ", rootGroup.maxLatitude)
@@ -46,12 +48,12 @@ def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
4648
valid = False
4749

4850
# Check UTM extents
49-
if "minNorthing" in rootGroup.ncattrs() \
50-
and "maxNorthing" in rootGroup.ncattrs() \
51-
and "minEasting" in rootGroup.ncattrs() \
52-
and "maxEasting" in rootGroup.ncattrs() \
53-
and "utmZone" in rootGroup.ncattrs() \
54-
and "utmNorthSouth" in rootGroup.ncattrs():
51+
if ("minNorthing" in rootGroup.ncattrs()
52+
and "maxNorthing" in rootGroup.ncattrs()
53+
and "minEasting" in rootGroup.ncattrs()
54+
and "maxEasting" in rootGroup.ncattrs()
55+
and "utmZone" in rootGroup.ncattrs()
56+
and "utmNorthSouth" in rootGroup.ncattrs()):
5557
if verbose:
5658
print(" UTM extents found (m)")
5759
print("\t minEasting = ", rootGroup.minEasting)
@@ -65,8 +67,8 @@ def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
6567
valid = False
6668

6769
# Check Depth Extents
68-
if "topDepth" in rootGroup.ncattrs() \
69-
and "bottomDepth" in rootGroup.ncattrs():
70+
if ("topDepth" in rootGroup.ncattrs()
71+
and "bottomDepth" in rootGroup.ncattrs()):
7072
if verbose:
7173
print(" Depth extents found (m)")
7274
print("\t bottomDepth = ", rootGroup.bottomDepth)
@@ -75,10 +77,10 @@ def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
7577
print("(INVALID) No Depth extents found")
7678
valid = False
7779

78-
# Check X/Y/Z spacing
79-
if "spacingX" in rootGroup.ncattrs() \
80-
and "spacingY" in rootGroup.ncattrs() \
81-
and "spacingZ" in rootGroup.ncattrs():
80+
# Check X/Y/Z spacing
81+
if ("spacingX" in rootGroup.ncattrs()
82+
and "spacingY" in rootGroup.ncattrs()
83+
and "spacingZ" in rootGroup.ncattrs()):
8284
if verbose:
8385
print(" Axis Spacing (m)")
8486
print("\t spacing X axis = ", rootGroup.spacingX)
@@ -87,79 +89,80 @@ def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
8789
else:
8890
print("(INVALID) No spacing information in project file")
8991
valid = False
90-
92+
9193
if valid:
92-
xyzGridSize[0] = int((rootGroup.maxEasting - rootGroup.minEasting) / rootGroup.spacingX + 1)
93-
xyzGridSize[1] = int((rootGroup.maxNorthing - rootGroup.minNorthing) / rootGroup.spacingY + 1)
94-
xyzGridSize[2] = int((rootGroup.topDepth - rootGroup.bottomDepth) / rootGroup.spacingZ + 1)
95-
94+
xyzGridSize[0] = int((rootGroup.maxEasting - rootGroup.minEasting) / rootGroup.spacingX + 1)
95+
xyzGridSize[1] = int((rootGroup.maxNorthing - rootGroup.minNorthing) / rootGroup.spacingY + 1)
96+
xyzGridSize[2] = int((rootGroup.topDepth - rootGroup.bottomDepth) / rootGroup.spacingZ + 1)
97+
9698
return valid
9799

100+
98101
# Get Extents and return in a dict
99102
def GetExtents(rootGroup):
100103
"""
101104
**GetExtents** - Extracts Loop Project region of interest extents given a
102105
netCDF root node
103-
106+
104107
Parameters
105108
----------
106109
rootGroup: netCDF4.Group
107110
The root group node of a Loop Project File
108-
111+
109112
Returns
110113
-------
111-
dict {"errorFlag","errorString"/"value"}
112-
value is a dict{"geodesic":[double,double,double, double],
113-
"utm":[int,int,double,double,double,double],"depth":[double,double],
114-
"spacing":[double,double,double]} containing the extents of this
114+
dict {"errorFlag", "errorString"/"value"}
115+
value is a dict{"geodesic":[double, double, double, double],
116+
"utm":[int, int, double, double, double, double], "depth":[double, double],
117+
"spacing":[double, double, double]} containing the extents of this
115118
project file
116-
119+
117120
"""
118-
response = {"errorFlag":False}
119-
if "minLatitude" in rootGroup.ncattrs() \
120-
and "maxLatitude" in rootGroup.ncattrs() \
121-
and "minLongitude" in rootGroup.ncattrs() \
122-
and "maxLongitude" in rootGroup.ncattrs():
121+
response = {"errorFlag": False}
122+
if ("minLatitude" in rootGroup.ncattrs()
123+
and "maxLatitude" in rootGroup.ncattrs()
124+
and "minLongitude" in rootGroup.ncattrs()
125+
and "maxLongitude" in rootGroup.ncattrs()):
123126
geodesic = [
124-
rootGroup.minLongitude,rootGroup.maxLongitude,
125-
rootGroup.minLatitude,rootGroup.maxLatitude,
127+
rootGroup.minLongitude, rootGroup.maxLongitude,
128+
rootGroup.minLatitude, rootGroup.maxLatitude,
126129
]
127130
else:
128131
errStr = "(ERROR) No or incomplete geodesic boundary in loop project file"
129132
print(errStr)
130-
response = {"errorFlag":True,"errorString":errStr}
131-
if "utmZone" in rootGroup.ncattrs() \
132-
and "utmNorthSouth" in rootGroup.ncattrs() \
133-
and "minEasting" in rootGroup.ncattrs() \
134-
and "maxEasting" in rootGroup.ncattrs() \
135-
and "minNorthing" in rootGroup.ncattrs() \
136-
and "maxNorthing" in rootGroup.ncattrs():
133+
response = {"errorFlag": True, "errorString": errStr}
134+
if ("utmZone" in rootGroup.ncattrs()
135+
and "utmNorthSouth" in rootGroup.ncattrs()
136+
and "minEasting" in rootGroup.ncattrs()
137+
and "maxEasting" in rootGroup.ncattrs()
138+
and "minNorthing" in rootGroup.ncattrs()
139+
and "maxNorthing" in rootGroup.ncattrs()):
137140
utm = [
138-
rootGroup.utmZone,rootGroup.utmNorthSouth,
139-
rootGroup.minEasting,rootGroup.maxEasting,
140-
rootGroup.minNorthing,rootGroup.maxNorthing
141+
rootGroup.utmZone, rootGroup.utmNorthSouth,
142+
rootGroup.minEasting, rootGroup.maxEasting,
143+
rootGroup.minNorthing, rootGroup.maxNorthing
141144
]
142145
else:
143146
errStr = "(ERROR) No or incomplete UTM boundary in loop project file"
144147
print(errStr)
145-
response = {"errorFlag":True,"errorString":errStr}
146-
if "topDepth" in rootGroup.ncattrs() \
147-
and "bottomDepth" in rootGroup.ncattrs():
148-
depth = [rootGroup.bottomDepth,rootGroup.topDepth]
148+
response = {"errorFlag": True, "errorString": errStr}
149+
if ("topDepth" in rootGroup.ncattrs()
150+
and "bottomDepth" in rootGroup.ncattrs()):
151+
depth = [rootGroup.bottomDepth, rootGroup.topDepth]
149152
else:
150153
errStr = "(ERROR) No or incomplete depth boundary in loop project file"
151154
print(errStr)
152-
response = {"errorFlag":True,"errorString":errStr}
153-
if "spacingX" in rootGroup.ncattrs() \
154-
and "spacingY" in rootGroup.ncattrs() \
155-
and "spacingZ" in rootGroup.ncattrs():
156-
spacing = [rootGroup.spacingX,rootGroup.spacingY,rootGroup.spacingZ]
155+
response = {"errorFlag": True, "errorString": errStr}
156+
if ("spacingX" in rootGroup.ncattrs()
157+
and "spacingY" in rootGroup.ncattrs()
158+
and "spacingZ" in rootGroup.ncattrs()):
159+
spacing = [rootGroup.spacingX, rootGroup.spacingY, rootGroup.spacingZ]
157160
else:
158161
errStr = "(ERROR) No or incomplete spacing data in loop project file"
159162
print(errStr)
160-
response = {"errorFlag":True,"errorString":errStr}
161-
if response["errorFlag"] == False:
162-
response["value"] = {"geodesic":geodesic,"utm":utm,"depth":depth,"spacing":spacing}
163+
response = {"errorFlag": True, "errorString": errStr}
164+
if response["errorFlag"] is False:
165+
response["value"] = {"geodesic": geodesic, "utm": utm, "depth": depth, "spacing": spacing}
163166
return response
164167

165168

@@ -168,38 +171,38 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
168171
"""
169172
**SetExtents** - Saves the extents of the region of interest as specified into
170173
the netCDF Loop Project File
171-
174+
172175
Parameters
173176
----------
174177
rootGroup: netCDF4.Group
175178
The root group node of a Loop Project File
176-
geodesic: [double,double,double,double]
179+
geodesic: [double, double, double, double]
177180
The latitude and longitude limits of the region in format:
178-
[minLong,maxLong,minLat,maxLat]
179-
utm: [int,int,double,double,double,double]
181+
[minLong, maxLong, minLat, maxLat]
182+
utm: [int, int, double, double, double, double]
180183
The utmZone, utmNorth/South, easting and northing extents in format:
181-
[utmZone,utmNorthSouth,minEasting,maxEasting,minNorthing,maxNorthing]
182-
depth: [double,double]
183-
The depth minimum and maximums in format: [bottomDepth,topDepth]
184+
[utmZone, utmNorthSouth, minEasting, maxEasting, minNorthing, maxNorthing]
185+
depth: [double, double]
186+
The depth minimum and maximums in format: [bottomDepth, topDepth]
184187
spacing: [double, double, double]
185188
The spacing of adjacent points in the grid for X/Y/Z. This corresponds
186-
to [longitude/easting,latitude/northing,depth]
189+
to [longitude/easting, latitude/northing, depth]
187190
preference: string (optional)
188191
A string ("utm" or "geodesic") which specifies which format the Loop GUI
189192
region of interest should be displayed
190-
193+
191194
Returns
192195
-------
193-
dict {"errorFlag","errorString"}
196+
dict {"errorFlag", "errorString"}
194197
errorString exist and contains error message only when errorFlag is
195198
True
196-
199+
197200
"""
198-
response = {"errorFlag":False}
201+
response = {"errorFlag": False}
199202
if len(geodesic) != 4:
200203
errStr = "(ERROR) Invalid number of geodesic boundary values (" + str(len(geodesic)) + ")"
201204
print(errStr)
202-
response = {"errorFlag":True,"errorString":errStr}
205+
response = {"errorFlag": True, "errorString": errStr}
203206
else:
204207
rootGroup.minLongitude = geodesic[0]
205208
rootGroup.maxLongitude = geodesic[1]
@@ -208,7 +211,7 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
208211
if len(utm) != 6:
209212
errStr = "(ERROR) Invalid number of UTM boundary values (" + str(len(utm)) + ")"
210213
print(errStr)
211-
response = {"errorFlag":True,"errorString":errStr}
214+
response = {"errorFlag": True, "errorString": errStr}
212215
else:
213216
rootGroup.utmZone = utm[0]
214217
rootGroup.utmNorthSouth = 0 if utm[1] == "S" or utm[1] == "s" or utm[1] == 0 else 1
@@ -219,14 +222,14 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
219222
if len(depth) != 2:
220223
errStr = "(ERROR) Invalid number of depth boundary values (" + str(len(depth)) + ")"
221224
print(errStr)
222-
response = {"errorFlag":True,"errorString":errStr}
225+
response = {"errorFlag": True, "errorString": errStr}
223226
else:
224227
rootGroup.bottomDepth = depth[0]
225228
rootGroup.topDepth = depth[1]
226229
if len(spacing) != 3:
227230
errStr = "(ERROR) Invalid number of spacing values (" + str(len(depth)) + ")"
228231
print(errStr)
229-
response = {"errorFlag":True,"errorString":errStr}
232+
response = {"errorFlag": True, "errorString": errStr}
230233
else:
231234
rootGroup.spacingX = spacing[0]
232235
rootGroup.spacingY = spacing[1]
@@ -256,4 +259,3 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
256259
rootGroup.topDepth = tmp
257260

258261
return response
259-

0 commit comments

Comments
 (0)