Skip to content

Commit

Permalink
Merge pull request #126 from SamuelDahlberg/master
Browse files Browse the repository at this point in the history
Issue #15717 - Makes pco2a_a new sba5 format compatible with parser, using new driver.
  • Loading branch information
SamuelDahlberg authored Mar 27, 2024
2 parents 575775e + 88fddc7 commit 9e47e9f
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python

"""
@package mi.dataset.driver.pco2a_a.sample.pco2a_a_sample_newsba5_telemetered_driver
@file mi/dataset/driver/pco2a_a/sample/pco2a_a_sample_newsba5_telemetered_driver.py
@author Samuel Dahlberg
@brief Telemetered driver for pco2a_a_sample data parser with the new sba5 format.
"""

from mi.dataset.driver.pco2a_a.sample.pco2a_a_sample_driver import process, \
TELEMETERED_PARTICLE_CLASSES
from mi.core.versioning import version

from mi.dataset.parser.pco2a_a_sample import Pco2aADclParticleClassKey, \
Pco2aADclTelemeteredInstrumentDataParticleAirNewSBA5, Pco2aADclTelemeteredInstrumentDataParticleWaterNewSBA5

TELEMETERED_PARTICLE_CLASSES_NEWSBA5 = {
Pco2aADclParticleClassKey.AIR_PARTICLE_CLASS: Pco2aADclTelemeteredInstrumentDataParticleAirNewSBA5,
Pco2aADclParticleClassKey.WATER_PARTICLE_CLASS: Pco2aADclTelemeteredInstrumentDataParticleWaterNewSBA5
}

@version("0.1.0")
def parse(unused, source_file_path, particle_data_handler):
process(source_file_path, particle_data_handler, TELEMETERED_PARTICLE_CLASSES_NEWSBA5)

return particle_data_handler
88 changes: 44 additions & 44 deletions mi/dataset/driver/turbd_a/dcl/turbd_a_dcl_driver.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/usr/bin/env python

"""
@package mi.dataset.driver.turbd_a
@file mi-dataset/mi/dataset/driver/turbd_a/dcl/turbd_a_dcl_driver.py
@author Samuel Dahlberg
@brief DCL driver for the turbd_a instrument
"""

from mi.dataset.dataset_driver import SimpleDatasetDriver
from mi.dataset.dataset_parser import DataSetDriverConfigKeys
from mi.dataset.parser.flort_dj_dcl import FlortDjDclParser

def parse(unused, source_file_path, particle_data_handler):
"""
This is the method called by Uframe
:param unused
:param source_file_path This is the full path and filename of the file to be parsed
:param particle_data_handler Java Object to consume the output of the parser
:return particle_data_handler
"""

with open(source_file_path, 'rb') as stream_handle:
TurbdADclDriver(unused, stream_handle, particle_data_handler).processFileStream()

return particle_data_handler


class TurbdADclDriver(SimpleDatasetDriver):
"""
The turbd_a driver class extends the SimpleDatasetDriver.
"""

def __init__(self, unused, stream_handle, particle_data_handler):
super(TurbdADclDriver, self).__init__(unused, stream_handle, particle_data_handler)

def _build_parser(self, stream_handle):
parser_config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.flort_dj_dcl',
DataSetDriverConfigKeys.PARTICLE_CLASS: 'TurbdADclDataParticle'}

parser = FlortDjDclParser(parser_config, stream_handle, self._exception_callback)

return parser
#!/usr/bin/env python

"""
@package mi.dataset.driver.turbd_a
@file mi-dataset/mi/dataset/driver/turbd_a/dcl/turbd_a_dcl_driver.py
@author Samuel Dahlberg
@brief DCL driver for the turbd_a instrument
"""

from mi.dataset.dataset_driver import SimpleDatasetDriver
from mi.dataset.dataset_parser import DataSetDriverConfigKeys
from mi.dataset.parser.flort_dj_dcl import FlortDjDclParser

def parse(unused, source_file_path, particle_data_handler):
"""
This is the method called by Uframe
:param unused
:param source_file_path This is the full path and filename of the file to be parsed
:param particle_data_handler Java Object to consume the output of the parser
:return particle_data_handler
"""

with open(source_file_path, 'rb') as stream_handle:
TurbdADclDriver(unused, stream_handle, particle_data_handler).processFileStream()

return particle_data_handler


class TurbdADclDriver(SimpleDatasetDriver):
"""
The turbd_a driver class extends the SimpleDatasetDriver.
"""

def __init__(self, unused, stream_handle, particle_data_handler):
super(TurbdADclDriver, self).__init__(unused, stream_handle, particle_data_handler)

def _build_parser(self, stream_handle):
parser_config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.flort_dj_dcl',
DataSetDriverConfigKeys.PARTICLE_CLASS: 'TurbdADclDataParticle'}

parser = FlortDjDclParser(parser_config, stream_handle, self._exception_callback)

return parser
111 changes: 111 additions & 0 deletions mi/dataset/parser/pco2a_a_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
SENSOR_DATA_PATTERN += FLOAT + COMMA # humidity [mbar]
SENSOR_DATA_PATTERN += FLOAT + COMMA # humidity sensor temperature [deg C]
SENSOR_DATA_PATTERN += UINT + COMMA # gas stream pressure [mbar]
SENSOR_DATA_PATTERN_NEWSBA5 = SENSOR_DATA_PATTERN + FLOAT # supply voltage
SENSOR_DATA_PATTERN_NEWSBA5 += END_OF_LINE_REGEX
SENSOR_DATA_PATTERN += FLOAT + COMMA # IRGA detector temperature [deg C]
SENSOR_DATA_PATTERN += FLOAT + COMMA # IRGA source temperature [deg C]
SENSOR_DATA_PATTERN += FLOAT # supply voltage
Expand All @@ -103,6 +105,16 @@
SENSOR_DATA_PATTERN_WATER += SENSOR_DATA_PATTERN
SENSOR_DATA_MATCHER_WATER = re.compile(SENSOR_DATA_PATTERN_WATER)

SENSOR_DATA_PATTERN_AIR_NEWSBA5 = TIMESTAMP + SPACE_REGEX # dcl controller timestamp
SENSOR_DATA_PATTERN_AIR_NEWSBA5 += CHAR_A + SPACE_REGEX
SENSOR_DATA_PATTERN_AIR_NEWSBA5 += SENSOR_DATA_PATTERN_NEWSBA5
SENSOR_DATA_MATCHER_AIR_NEWSBA5 = re.compile(SENSOR_DATA_PATTERN_AIR_NEWSBA5)

SENSOR_DATA_PATTERN_WATER_NEWSBA5 = TIMESTAMP + SPACE_REGEX # dcl controller timestamp
SENSOR_DATA_PATTERN_WATER_NEWSBA5 += CHAR_W + SPACE_REGEX
SENSOR_DATA_PATTERN_WATER_NEWSBA5 += SENSOR_DATA_PATTERN_NEWSBA5
SENSOR_DATA_MATCHER_WATER_NEWSBA5 = re.compile(SENSOR_DATA_PATTERN_WATER_NEWSBA5)

# SENSOR_DATA_MATCHER produces the following groups.
# The following are indices into groups() produced by SENSOR_DATA_MATCHER.
# i.e, match.groups()[INDEX]
Expand All @@ -117,6 +129,7 @@
SENSOR_GROUP_DETECTOR_TEMP = 17
SENSOR_GROUP_SOURCE_TEMP = 18
SENSOR_GROUP_SUPPLY_VOLTAGE = 19
SENSOR_GROUP_SUPPLY_VOLTAGE_NEWSBA5 = 17
SENSOR_GROUP_SAMPLE_TYPE = 8

INSTRUMENT_PARTICLE_AIR_MAP = [
Expand Down Expand Up @@ -145,6 +158,28 @@
('supply_voltage', SENSOR_GROUP_SUPPLY_VOLTAGE, float)
]

INSTRUMENT_PARTICLE_AIR_MAP_NEWSBA5 = [
('zero_a2d', SENSOR_GROUP_ZERO_A2D, int),
('current_a2d', SENSOR_GROUP_CURRENT_A2D, int),
('measured_air_co2', SENSOR_GROUP_CO2, float),
('avg_irga_temperature', SENSOR_GROUP_AVG_IRGA_TEMP, float),
('humidity', SENSOR_GROUP_HUMIDITY, float),
('humidity_temperature', SENSOR_GROUP_HUMIDITY_TEMP, float),
('gas_stream_pressure', SENSOR_GROUP_STREAM_PRESSURE, int),
('supply_voltage', SENSOR_GROUP_SUPPLY_VOLTAGE_NEWSBA5, float)
]

INSTRUMENT_PARTICLE_WATER_MAP_NEWSBA5 = [
('zero_a2d', SENSOR_GROUP_ZERO_A2D, int),
('current_a2d', SENSOR_GROUP_CURRENT_A2D, int),
('measured_water_co2', SENSOR_GROUP_CO2, float),
('avg_irga_temperature', SENSOR_GROUP_AVG_IRGA_TEMP, float),
('humidity', SENSOR_GROUP_HUMIDITY, float),
('humidity_temperature', SENSOR_GROUP_HUMIDITY_TEMP, float),
('gas_stream_pressure', SENSOR_GROUP_STREAM_PRESSURE, int),
('supply_voltage', SENSOR_GROUP_SUPPLY_VOLTAGE_NEWSBA5, float)
]


# Recovered data will go to these streams now vs "recovered" streams
class DataParticleType(BaseEnum):
Expand Down Expand Up @@ -230,6 +265,82 @@ class Pco2aADclRecoveredInstrumentDataParticleWater(Pco2aADclInstrumentDataParti
_data_particle_type = DataParticleType.PCO2A_INSTRUMENT_WATER_RECOVERED_PARTICLE


"""
Adjusted particle classes to work with the new pco2a SBA5 format, being used in pioneer MAB deployment.
"""



class Pco2aADclInstrumentDataParticleAirNewSBA5(DclInstrumentDataParticle):
"""
Class for generating the Pco2a_a_dcl instrument particles.
"""
data_matcher = SENSOR_DATA_MATCHER_AIR_NEWSBA5

def __init__(self, raw_data, *args, **kwargs):
super(Pco2aADclInstrumentDataParticleAirNewSBA5, self).__init__(
raw_data, INSTRUMENT_PARTICLE_AIR_MAP_NEWSBA5, *args, **kwargs)

# instrument_timestamp is the internal_timestamp
instrument_timestamp = self.raw_data[SENSOR_GROUP_SENSOR_DATE_TIME]
elapsed_seconds_useconds = \
timestamp_yyyy_mm_dd_hh_mm_ss_csv_to_ntp(instrument_timestamp)
self.set_internal_timestamp(elapsed_seconds_useconds)

# instrument clock is not accurate so, use port_timestamp as the preferred_ts
self.contents[DataParticleKey.PREFERRED_TIMESTAMP] = DataParticleKey.PORT_TIMESTAMP


class Pco2aADclInstrumentDataParticleWaterNewSBA5(DclInstrumentDataParticle):
"""
Class for generating the Pco2a_a_dcl instrument particles.
"""
data_matcher = SENSOR_DATA_MATCHER_WATER_NEWSBA5

def __init__(self, raw_data, *args, **kwargs):
super(Pco2aADclInstrumentDataParticleWaterNewSBA5, self).__init__(
raw_data, INSTRUMENT_PARTICLE_WATER_MAP_NEWSBA5, *args, **kwargs)

# Instrument timestamp is the internal timestamp
instrument_timestamp = self.raw_data[SENSOR_GROUP_SENSOR_DATE_TIME]
elapsed_seconds_useconds = \
timestamp_yyyy_mm_dd_hh_mm_ss_csv_to_ntp(instrument_timestamp)
self.set_internal_timestamp(elapsed_seconds_useconds)

# instrument clock is not accurate so, use port_timestamp as the preferred_ts
self.contents[DataParticleKey.PREFERRED_TIMESTAMP] = DataParticleKey.PORT_TIMESTAMP


class Pco2aADclTelemeteredInstrumentDataParticleAirNewSBA5(Pco2aADclInstrumentDataParticleAirNewSBA5):
"""
Class for generating Offset Data Particles from Telemetered air data.
"""
_data_particle_type = DataParticleType.PCO2A_INSTRUMENT_AIR_PARTICLE


class Pco2aADclTelemeteredInstrumentDataParticleWaterNewSBA5(Pco2aADclInstrumentDataParticleWaterNewSBA5):
"""
Class for generating Offset Data Particles from Telemetered water data.
"""
_data_particle_type = DataParticleType.PCO2A_INSTRUMENT_WATER_PARTICLE


class Pco2aADclRecoveredInstrumentDataParticleAirNewSBA5(Pco2aADclInstrumentDataParticleAirNewSBA5):
"""
Class for generating Offset Data Particles from Recovered air data.
"""
_data_particle_type = DataParticleType.PCO2A_INSTRUMENT_AIR_RECOVERED_PARTICLE


class Pco2aADclRecoveredInstrumentDataParticleWaterNewSBA5(Pco2aADclInstrumentDataParticleWaterNewSBA5):
"""
Class for generating Offset Data Particles from Recovered water data.
"""
_data_particle_type = DataParticleType.PCO2A_INSTRUMENT_WATER_RECOVERED_PARTICLE




class Pco2aADclParser(DclFileCommonParser):
"""
This is the entry point for the parser.
Expand Down

0 comments on commit 9e47e9f

Please sign in to comment.