Commit 796e3dd2 authored by cponcele's avatar cponcele
Browse files

format with black

parent 451ba2ec
This diff is collapsed.
......@@ -117,8 +117,9 @@ class SonarChecker:
if __name__ == "__main__":
filename = "c:/data/datasets/netcdfInspector/PELGAS19_012_20190507_042828_01_1.xsf.nc"
checker= SonarChecker()
checker = SonarChecker()
checker.validate_file(filename)
checker.validate_file("c:/data/datasets/netcdfInspector/GLOBE_MERGED_GAZCOGNE3_003_20180829_061940_1.xsf_TO_GAZCOGNE3_003_20180829_070941_1.xsf_v783u7_w_ES333-7C-333000.nc")
checker.validate_file(
"c:/data/datasets/netcdfInspector/GLOBE_MERGED_GAZCOGNE3_003_20180829_061940_1.xsf_TO_GAZCOGNE3_003_20180829_070941_1.xsf_v783u7_w_ES333-7C-333000.nc"
)
checker.validate_file("C:\data\datasets\SonarNetcdf\HYDROMOMAR-D20200904-T093757.nc")
This diff is collapsed.
......@@ -7,8 +7,10 @@ import matplotlib.pyplot as plt
# ensure minimum size for figures
plt.rcParams["figure.dpi"] = 270
from sonar_netcdf.utils.print_color import header,warning,error,pprint
#pylint:disable=redefined-outer-name
from sonar_netcdf.utils.print_color import header, warning, error, pprint
# pylint:disable=redefined-outer-name
class NcReader:
"""
......@@ -27,7 +29,6 @@ class NcReader:
self.dataset = nc.Dataset(self.file_name)
self.quiet = False
def __del__(self):
# close the file
self.dataset.close()
......@@ -50,7 +51,7 @@ class NcReader:
slice_index = {}
if NcReader.is_variable_vlen(variable):
return self._get_vlen_variable(variable_path, slice_index)
return self._get_usual_variable(variable_path=variable_path,slice_index=slice_index)
return self._get_usual_variable(variable_path=variable_path, slice_index=slice_index)
def _get_variable(self, variable_path):
return self.dataset[variable_path]
......@@ -97,7 +98,6 @@ class NcReader:
values[mask] = np.nan
return values
def _get_usual_variable(self, variable_path, slice_index: dict):
l_variable = self.dataset[variable_path]
shape = l_variable.shape
......@@ -115,7 +115,7 @@ class NcReader:
for sh, dim in zip(reduced_shape, reduced_dimensions):
if dim in slice_index:
index = slice_index[dim]
slicing += (slice(index,index+1),) # we select the slice specified in index
slicing += (slice(index, index + 1),) # we select the slice specified in index
else:
reduced_shape_in_progress += (sh,)
reduced_dim_in_progress += (dim,)
......@@ -166,7 +166,7 @@ class NcReader:
for sh, dim in zip(reduced_shape, reduced_dimensions):
if dim in slice_index:
index = slice_index[dim]
slicing += (slice(index,index+1),) # we select the slice specified in index
slicing += (slice(index, index + 1),) # we select the slice specified in index
else:
reduced_shape_in_progress += (sh,)
reduced_dim_in_progress += (dim,)
......@@ -177,11 +177,13 @@ class NcReader:
reduced_dimensions = reduced_dim_in_progress
else:
# values = vlen_variable[:]
#values = np.empty(shape=reduced_shape, dtype=object)
values=np.squeeze(vlen_variable[:])
# values = np.empty(shape=reduced_shape, dtype=object)
values = np.squeeze(vlen_variable[:])
if not self.quiet:
pprint(f"Vlen variable {variable_path} : reduced shape for display is {reduced_dimensions} ({reduced_shape})")
pprint(
f"Vlen variable {variable_path} : reduced shape for display is {reduced_dimensions} ({reduced_shape})"
)
if len(reduced_shape) == 1:
# dimension is 1 like a ping indexed variable, we can parse all vlen data and build a matrix from it
values = np.squeeze(values)
......@@ -229,7 +231,6 @@ class NcReader:
return (f"{vpath}/{dataset.name}", dataset.name)
return None, None
def _display_variable(
self,
variable_name,
......@@ -371,7 +372,7 @@ class NcReader:
vmin=vmin,
vmax=vmax,
)
except: # pylint: disable=W0702
except: # pylint: disable=W0702
error("Error for variable :" + variable_path)
error(f"Unexpected error: {sys.exc_info()}")
traceback.print_exc()
......@@ -382,7 +383,7 @@ class NcReader:
):
last_variable = None
if ignored_variable_list is None:
ignored_variable_list=[]
ignored_variable_list = []
if isinstance(dataset, nc.Variable):
return self._print_variable(dataset, slice_index, ignored_variable_list, cmap=cmap, vmin=vmin, vmax=vmax)
if dataset.parent is not None:
......@@ -415,5 +416,6 @@ if __name__ == "__main__":
start = "/"
reader = NcReader(file_path)
values = reader.dump_content(root="Sonar/Grid_group_1/integrated_backscatter", slice_index={'frequency': 1},
cmap="jet", vmin=-80, vmax=-30)
values = reader.dump_content(
root="Sonar/Grid_group_1/integrated_backscatter", slice_index={"frequency": 1}, cmap="jet", vmin=-80, vmax=-30
)
class bcolors:
"""
Utility for color display in terminal or jupyter
......@@ -15,9 +14,11 @@ class bcolors:
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
def info(msg):
pprint(msg)
def pprint(msg, back_ground_color=None):
"""Intercept print call"""
if back_ground_color is None:
......@@ -36,4 +37,3 @@ def warning(msg: str):
def header(msg: str):
pprint(msg, back_ground_color=bcolors.BOLD)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment