Commit 3effd624 authored by cponcele's avatar cponcele
Browse files

Proposal to fix pylint tests

parent 66a6356a
......@@ -7,6 +7,8 @@ import netCDF4 as nc
import numpy as np
# pylint issue with relative import ?
#pylint: disable=import-error
from .nc_tools import find_type
# pylint: disable=E1101
# pylint: disable=R0904
......@@ -9082,7 +9084,7 @@ class BathymetryVendorSpecificGrp:
"""create variable beam_incidence_angle_adjustment"""
v = group.createVariable(varname="beam_incidence_angle_adjustment", datatype=np.float32, dimensions=("ping_time", "detection"), fill_value=missing_value)
if "long_name" not in attributes:
v.long_name = "beam incidence angle adjustment, as given in .all datagram specification"#Extract from .all parameters : due to raybending, the beam incidence angle at the bottom hit will usually differ from the beam launch angle at the transducer and also from the angle given by a straight line between the transducer and the bottom hit. The difference from the latter is given by the beam incidence angle adjustment (IBA). The beam incidence angle re the horizontal, corrected for the ray bending, can be calculated as follows: Output datagrams BAC = atan( z / abs(y) ) + IBA. BAC is positive downwards and IBA will be positive when the beam is bending towards the bottom.
v.long_name = "beam incidence angle adjustment, as given in .all datagram specification"#Extract from .all parameters : due to raybending, the beam incidence angle at the bottom hit will usually differ from the beam launch angle at the transducer and also from the angle given by a straight line between the transducer and the bottom hit. The difference from the latter is given by the beam incidence angle adjustment (IBA). The beam incidence angle re the horizontal, corrected for the ray bending, can be calculated as follows: Output datagrams BAC = atan( z / abs(y) ) + IBA. BAC is positive downwards and IBA will be positive when the beam is bending towards the bottom.
if "unit" not in attributes:
v.unit = "degree"
......
......@@ -4,19 +4,24 @@ import tempfile as tmp
import netCDF4 as nc
import numpy as np
from ..sonar_groups import RootGrp,EnvironmentGrp,SonarGrp,BeamGroup1Grp
# pylint issue with relative import ?
# pylint:disable = import-error
from ..sonar_groups import RootGrp, EnvironmentGrp, SonarGrp, BeamGroup1Grp
def create_basic(file:nc.Dataset):
# pylint:enable = import-error
def create_basic(file: nc.Dataset):
"""create basic structure with a few fields for test"""
# create root Node
root_structure = RootGrp()
root = root_structure.create_group(file)
#create a variable
# create a variable
root_structure.create_crs(root)
#create environment
# create environment
env_structure = EnvironmentGrp()
env = env_structure.create_group(root)
env_structure.create_dimension(env, {EnvironmentGrp.FREQUENCY_DIM_NAME: 2})
......@@ -50,27 +55,28 @@ def test_add_attribute():
print(f"creating fake xsf file {filename}")
with nc.Dataset(filename, mode="w") as file:
root_structure = RootGrp()
root = root_structure.create_group(file,vlen_type_dict={},att_1="text",att_2=1.5)
assert root.att_1== "text"
assert root.att_2== 1.5
assert isinstance( root.att_2,float)
root = root_structure.create_group(file, vlen_type_dict={}, att_1="text", att_2=1.5)
assert root.att_1 == "text"
assert root.att_2 == 1.5
assert isinstance(root.att_2, float)
def test_change_type():
"""Add change a vlen type and add some attribute to a variable"""
filename = tmp.mktemp( suffix=".nc")
#filename = tmp.mktemp(suffix=".nc")
filename = tmp.mktemp(suffix=".nc")
# filename = tmp.mktemp(suffix=".nc")
print(f"creating fake xsf file {filename}")
with nc.Dataset(filename, mode="w") as file:
root_structure = RootGrp()
root = root_structure.create_group(file)
sonar_structure = SonarGrp()
#create sonar group, change sample_t type and it missing value
# create sonar group, change sample_t type and it missing value
sonar = sonar_structure.create_group(root)
beam_structure = BeamGroup1Grp()
beam = beam_structure.create_group(sonar,vlen_type_dict={
"sample_t":np.float32,
"angle_t":np.int16}, ident=f"Beam_group0")
beam = beam_structure.create_group(
sonar, vlen_type_dict={"sample_t": np.float32, "angle_t": np.int16}, ident=f"Beam_group0"
)
beam_structure.create_dimension(
beam,
{
......@@ -80,14 +86,19 @@ def test_change_type():
BeamGroup1Grp.PING_TIME_DIM_NAME: 100,
},
)
angle=beam_structure.create_echoangle_major(beam,missing_value = -32768, #missing value is not in CF convention and use of _FillValue not supported by netcdf API
valid_range=np.int16([-18000, 18000]),scale_factor= np.float32(0.01))
angle = beam_structure.create_echoangle_major(
beam,
missing_value=-32768, # missing value is not in CF convention and use of _FillValue not supported by netcdf API
valid_range=np.int16([-18000, 18000]),
scale_factor=np.float32(0.01),
)
assert np.all(angle.valid_range == np.int16([-18000, 18000]))
assert angle.scale_factor == np.float32(0.01)
assert angle.missing_value == -32768
os.remove(filename)
def test_append_ping():
filename = tmp.mktemp(suffix=".nc")
print(f"creating fake xsf file {filename}")
......@@ -98,7 +109,7 @@ def test_append_ping():
sonar_structure = SonarGrp()
sonar = sonar_structure.create_group(root)
beam_structure = BeamGroup1Grp()
beam = beam_structure.create_group(sonar,ident=f"Beam_group0")
beam = beam_structure.create_group(sonar, ident=f"Beam_group0")
beam_structure.create_dimension(
beam,
{
......@@ -108,15 +119,16 @@ def test_append_ping():
BeamGroup1Grp.PING_TIME_DIM_NAME: None,
},
)
bs=beam_structure.create_backscatter_r(beam)
#append two values and check that ping length is equal to 2
bs[0,0,0]=np.array([1,2,3],dtype=np.float32)
bs[0,1,0]=np.array([1,2,3],dtype=np.float32)
bs[1,0,0]=np.array([1,2,3],dtype=np.float32)
assert len(beam.dimensions[BeamGroup1Grp.PING_TIME_DIM_NAME])==2
bs = beam_structure.create_backscatter_r(beam)
# append two values and check that ping length is equal to 2
bs[0, 0, 0] = np.array([1, 2, 3], dtype=np.float32)
bs[0, 1, 0] = np.array([1, 2, 3], dtype=np.float32)
bs[1, 0, 0] = np.array([1, 2, 3], dtype=np.float32)
assert len(beam.dimensions[BeamGroup1Grp.PING_TIME_DIM_NAME]) == 2
def test_netcdf_basic():
""" sample test and use of sonar_groups.py file and methods"""
"""sample test and use of sonar_groups.py file and methods"""
filename = tmp.mktemp(suffix=".nc")
print(f"creating fake xsf file {filename}")
......
......@@ -244,7 +244,7 @@ class NcReader:
Print variable
:return: None
"""
header(f"\n\n")
header("\n\n")
header(f"Variable {variable_name} : {variable_path}")
pprint(f"{self.dataset[variable_path]}")
......
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