Skip to content

Commit

Permalink
Fix Atlas sensor code, improve docstring (#19)
Browse files Browse the repository at this point in the history
* Remove abstract method from AtlasI2C class

* Update old docstrings to reflect code changes

Co-authored-by: Milind Sharma <[email protected]>
  • Loading branch information
utkarsh867 and Milind220 authored Jul 30, 2021
1 parent 0ed0e83 commit 023ca2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
5 changes: 0 additions & 5 deletions openoceancamera/sensors/atlasI2C.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ def address(self):
def moduletype(self):
return self.module

@abstractmethod
def get_header_row(self):
"""Get the header row for the data file, to show what data is being read."""
return

def __del__(self):
try:
self._file_read.close()
Expand Down
34 changes: 19 additions & 15 deletions openoceancamera/sensors/atlas_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class - AtlasI2C.
These classes are supposed to be instantiated. They initialise the sensors
and provide whatever functionality is unnique to each sensor.
There are also two functions in this script, that should be used with
the sensors:
getAllSensorData: Gets data from all sensors.
getAllHeaderRows: Gets headers from all sensors.
Note:
Code, docstrings, comments and type annotation formatting as
per Google Python Style Guide:
Expand Down Expand Up @@ -43,20 +38,22 @@ class EC_Sensor(AtlasI2C):
- Specific gravity (No unit)
Public Methods:
get_header_rows: Shows the measurement params and the units for them.
set_TDS_conv: Sets the conversion factor for total dissolved solids calculation.
get_TDS_conv: Shows the current conversion factor for TDS calculation.
set_temp_compensation: Sets the temperature in order to compensate for it.
set_params: Enables/disables measurement parameters.
set_probe: Sets the type/model of probe.
get_probe: Shows the probe model that is currently set.
get_conductivity: Gets the conductivity readings.
get_salinity: Gets the salinity readings.
get_tds: Gets the total dissolved solids readings.
get_salinity: Gets the salinity readings.
Example Use:
ec_sensor = EC_Sensor() # Sets up the class for the sensor, it automatically gets initialised.
ec_sensor.initialise_sensor() # To re initialise it if you want.
print(ec_sensor.get_header_rows()) # Shows a header row to start the data file with.
print(ec_sensor.get_data()) # Takes readings.
ec_sensor.get_conductivity() # Takes readings.
"""
_PARAMS = ['EC', 'TDS', 'S', 'SG']

Expand All @@ -69,6 +66,9 @@ def __init__(self,
See AtlasI2C's (super class) __init__ method for more information.
"""
# The .initialise method is called in AtlasI2C __init__
# to initialise the sensors.

super().__init__(moduletype=moduletype, name=name, address=address, bus=bus)

for param in self._PARAMS: # Ensures that all measurement params are enabled.
Expand Down Expand Up @@ -201,21 +201,22 @@ class DO_Sensor(AtlasI2C):
Official datasheet for this sensor: https://atlas-scientific.com/files/DO_EZO_Datasheet.pdf
Public Methods:
get_header_rows: Shows the measurement params and the units for them.
set_temp_compensation: Sets the temperature in order to compensate for it.
set_press_compensation: Sets the pressure in order to compensate for it.
set_sal_compensation: Sets the salinity in order to compensate for it.
set_params: Enables/disables measurement parameters.
get_do: Gets dissolved oxygen readings.
get_percentage_oxygen: Gets percentage oxygen readings.
This sensor can measure 2 parameters:
- Dissolved oxygen (Unit: mg/L)
- Percentage oxygen (Unit: % saturation)
Example Use:
do_sensor = DO_Sensor() # Sets up the class for the sensor, it automatically gets initialised.
do_sensor.initialise_sensor() # To re initialise it if you want.
print(do_sensor.get_header_rows()) # Shows a header row to start the data file with.
print(do_sensor.get_data()) # Takes readings.
do_sensor.get_do() # Takes readings.
"""
_PARAMS = ['DO', '%']

Expand All @@ -228,6 +229,8 @@ def __init__(self,
See AtlasI2C's (super class) __init__ method for more information.
"""
# The .initialise method is called in AtlasI2C __init__
# to initialise the sensors.
super().__init__(address=address, moduletype=moduletype, name=name, bus=bus)

for param in self._PARAMS: # Ensures that all measurement parameters are enabled.
Expand Down Expand Up @@ -332,16 +335,15 @@ class PH_Sensor(AtlasI2C):
- pH (Unit: pH)
Public Methods:
get_header_rows: Shows the measurement params and the units for them.
set_temp_compensation: Sets the temperature in order to compensate for it.
get_slope: Shows how well the probe is working compared to an ideal probe.
get_ph: Gets pH readings.
Example Use:
ph_sensor = PH_Sensor() # Sets up the class for the sensor, it automatically gets initialised.
ph_sensor.initialise_sensor() # To re initialise it if you want.
print(ph_sensor.get_header_rows()) # Shows a header row to start the data file with.
print(ph_sensor.get_data()) # Takes readings.
ph_sensor.get_ph() # Takes readings.
"""
# Only reads pH, so no _PARAMS or _UNITS class attributes.
def __init__(self,
Expand All @@ -353,8 +355,10 @@ def __init__(self,
See AtlasI2C's (super class) __init__ method for more information.
"""
# The .initialise method is called in AtlasI2C __init__
# to initialise the sensors.
super().__init__(moduletype=moduletype, name=name, bus=bus, address=address)

def get_ph(self) -> float:
"""Explicitly returns the pH measurement."""
try:
Expand Down

0 comments on commit 023ca2d

Please sign in to comment.