def create_variable_element(self, variableResult): clean_datatype = self.check_dataTypeEnum(variableResult.DataType) clean_medium = self.check_SampleMedium(variableResult.SampleMedium) clean_category = self.check_generalCategory( variableResult.GeneralCategory) # noqa clean_valuetype = self.check_valueType(variableResult.ValueType) variable = WaterML.VariableInfoType( variableName=variableResult.VariableName, valueType=clean_valuetype, dataType=clean_datatype, generalCategory=clean_category, sampleMedium=clean_medium, noDataValue=variableResult.NoDataValue, variableDescription=variableResult.VariableDescription, speciation=variableResult.Speciation) # For specimen data. v_code = variableResult.VariableCode v_code_i = v_code.find('::') if v_code_i != -1: v_code = v_code[0:v_code_i] variableCode = WaterML.variableCodeType() variableCode.vocabulary = self.vocabulary # TODO: What is this, should it always be true? variableCode.default = "true" variableCode.variableID = variableResult.VariableID variableCode.valueOf_ = v_code variable.add_variableCode(variableCode) clean_variableUnits = self.check_UnitsType( variableResult.VariableUnits.UnitsType) # noqa if variableResult.VariableUnits: units = WaterML.UnitsType( unitAbbreviation=variableResult.VariableUnits. UnitsAbbreviation, # noqa unitCode=variableResult.VariableUnitsID, unitType=clean_variableUnits, unitName=variableResult.VariableUnits.UnitsName) variable.set_unit(units) timeSupport = WaterML.timeScaleType() timeSupport.isRegular = variableResult.IsRegular if variableResult.TimeUnits: timeUnits = WaterML.UnitsType( unitID=variableResult.TimeUnits.UnitsID, unitName=variableResult.TimeUnits.UnitsName, unitDescription=variableResult.TimeUnits.UnitsName, unitType=variableResult.TimeUnits.UnitsType, unitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation) timeSupport.set_unit(timeUnits) # TODO: time interval is not the same as time support. # Time interval refers to a spacing between values for regular data, # which isn't stored in ODM. if variableResult.TimeSupport: # integer in WaterML 1.0 timeSupport.timeSupport = float(variableResult.TimeSupport) variable.set_timeScale(timeSupport) return variable
def create_variable_element(self, variableResult): # Flavio: # Checks data type, sample medium, general category and value type against # controlled vocabulary read from watermlcvs.json file # signals a warning case not found # returns the checked term or a default of "Unknown", case it is not found clean_datatype = voc.check_dataTypeEnum(variableResult.DataType) clean_medium = voc.check_SampleMedium(variableResult.SampleMedium) # GeneralCategoryValidate and ValueTypeValidate optional capability added to support ODM2 CV handling _GeneralCategoryValidate = True if hasattr(variableResult, 'GeneralCategoryValidate'): _GeneralCategoryValidate = variableResult.GeneralCategoryValidate clean_category = voc.check_generalCategory( variableResult.GeneralCategory, validate=_GeneralCategoryValidate) _ValueTypeValidate = True if hasattr(variableResult, 'ValueTypeValidate'): _ValueTypeValidate = variableResult.ValueTypeValidate clean_valuetype = voc.check_valueType(variableResult.ValueType, validate=_ValueTypeValidate) # Flavio: # Creates variable (a WaterML1.1 VariableInfoType object) # with VariableName and VariableDescrition, ValueType and DataType, # GeneralCategory, SampleMedium and NoDataValue variable = WaterML.VariableInfoType( variableName=variableResult.VariableName, valueType=clean_valuetype, dataType=clean_datatype, generalCategory=clean_category, sampleMedium=clean_medium, noDataValue=variableResult.NoDataValue, variableDescription=variableResult.VariableDescription, speciation=variableResult.Speciation) # For specimen data. # Flavio: # if VariableCode is in the format of xxx::yyy, # takes as VariableCode just the first part (xxx) v_code = variableResult.VariableCode v_code_i = v_code.find('::') if v_code_i != -1: v_code = v_code[0:v_code_i] # Flavio: # Creates variableCode, a variableCodeType element, # with vocabulary, variableID, default and valueOf # (the code itself) attributes # and adds it to variable variableCode = WaterML.variableCodeType() variableCode.vocabulary = self.vocabulary # TODO: What is this, should it always be true? variableCode.default = "true" variableCode.variableID = variableResult.VariableID variableCode.valueOf_ = v_code variable.add_variableCode(variableCode) # UnitsTypeValidate optional capability added to support ODM2 CV handling _UnitsTypeValidate = True if hasattr(variableResult.VariableUnits, 'UnitsTypeValidate'): _UnitsTypeValidate = variableResult.VariableUnits.UnitsTypeValidate clean_variableUnitsType = voc.check_UnitsType( variableResult.VariableUnits.UnitsType, validate=_UnitsTypeValidate) if variableResult.VariableUnits: units = WaterML.UnitsType( unitID=variableResult.VariableUnitsID, unitAbbreviation=variableResult.VariableUnits. UnitsAbbreviation, # noqa unitCode=variableResult.VariableUnitsID, unitType=clean_variableUnitsType, unitName=variableResult.VariableUnits.UnitsName) variable.set_unit(units) timeSupport = WaterML.timeScaleType() timeSupport.isRegular = variableResult.IsRegular if variableResult.TimeUnits: timeUnits = WaterML.UnitsType( unitID=variableResult.TimeUnits.UnitsID, unitName=variableResult.TimeUnits.UnitsName, unitDescription=variableResult.TimeUnits.UnitsName, unitType=variableResult.TimeUnits.UnitsType, unitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation, unitCode=variableResult.TimeUnits.UnitsID) timeSupport.set_unit(timeUnits) # TODO: time interval is not the same as time support. # Time interval refers to a spacing between values for regular data, # which isn't stored in ODM. if variableResult.TimeSupport: # integer in WaterML 1.0 timeSupport.timeSupport = float(variableResult.TimeSupport) variable.set_timeScale(timeSupport) return variable
def create_variable_element(self, variableResult): clean_datatype = voc.check_dataTypeEnum(variableResult.DataType) clean_medium = voc.check_SampleMedium(variableResult.SampleMedium) # GeneralCategoryValidate and ValueTypeValidate optional capability added to support ODM2 CV handling _GeneralCategoryValidate = True if hasattr(variableResult, 'GeneralCategoryValidate'): _GeneralCategoryValidate = variableResult.GeneralCategoryValidate clean_category = voc.check_generalCategory(variableResult.GeneralCategory, validate=_GeneralCategoryValidate) _ValueTypeValidate = True if hasattr(variableResult, 'ValueTypeValidate'): _ValueTypeValidate = variableResult.ValueTypeValidate clean_valuetype = voc.check_valueType(variableResult.ValueType, validate=_ValueTypeValidate) variable = WaterML.VariableInfoType( variableName=variableResult.VariableName, valueType=clean_valuetype, dataType=clean_datatype, generalCategory=clean_category, sampleMedium=clean_medium, noDataValue=variableResult.NoDataValue, variableDescription=variableResult.VariableDescription, speciation=variableResult.Speciation) # For specimen data. v_code = variableResult.VariableCode v_code_i = v_code.find('::') if v_code_i != -1: v_code = v_code[0:v_code_i] variableCode = WaterML.variableCodeType() variableCode.vocabulary = self.vocabulary # TODO: What is this, should it always be true? variableCode.default = "true" variableCode.variableID = variableResult.VariableID variableCode.valueOf_ = v_code variable.add_variableCode(variableCode) # UnitsTypeValidate optional capability added to support ODM2 CV handling _UnitsTypeValidate = True if hasattr(variableResult.VariableUnits, 'UnitsTypeValidate'): _UnitsTypeValidate = variableResult.VariableUnits.UnitsTypeValidate clean_variableUnitsType = voc.check_UnitsType(variableResult.VariableUnits.UnitsType, validate=_UnitsTypeValidate) if variableResult.VariableUnits: units = WaterML.UnitsType( unitID=variableResult.VariableUnitsID, unitAbbreviation=variableResult.VariableUnits.UnitsAbbreviation, # noqa unitCode=variableResult.VariableUnitsID, unitType=clean_variableUnitsType, unitName=variableResult.VariableUnits.UnitsName) variable.set_unit(units) timeSupport = WaterML.timeScaleType() timeSupport.isRegular = variableResult.IsRegular if variableResult.TimeUnits: timeUnits = WaterML.UnitsType( unitID=variableResult.TimeUnits.UnitsID, unitName=variableResult.TimeUnits.UnitsName, unitDescription=variableResult.TimeUnits.UnitsName, unitType=variableResult.TimeUnits.UnitsType, unitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation, unitCode=variableResult.TimeUnits.UnitsID) timeSupport.set_unit(timeUnits) # TODO: time interval is not the same as time support. # Time interval refers to a spacing between values for regular data, # which isn't stored in ODM. if variableResult.TimeSupport: # integer in WaterML 1.0 timeSupport.timeSupport = float(variableResult.TimeSupport) variable.set_timeScale(timeSupport) return variable