Skip to content

Commit

Permalink
Merge branch 'develop' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMakela-NOAA committed Aug 1, 2022
2 parents 0a9a3fa + de18247 commit 70fda83
Show file tree
Hide file tree
Showing 66 changed files with 10,272 additions and 247 deletions.
2 changes: 1 addition & 1 deletion adios_db/adios_db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import (basicConfig, getLogger, NullHandler,
DEBUG, INFO, WARNING, ERROR, CRITICAL)

__version__ = "1.0.0.b1"
__version__ = "1.0.1"


def initialize_console_log(level='debug'):
Expand Down
2 changes: 1 addition & 1 deletion adios_db/adios_db/data_sources/noaa_csv/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_from_csv(self, infile):
"ADIOS CSV file?\n"
f"First line of file: {header}")

if data_model_version != ADIOS_DATA_MODEL_VERSION:
if data_model_version > ADIOS_DATA_MODEL_VERSION:
raise ValueError("Version mismatch -- this file is: "
f"{data_model_version}\n"
"The code version is: "
Expand Down
67 changes: 65 additions & 2 deletions adios_db/adios_db/models/common/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from dataclasses import dataclass
from math import isclose
import copy
import warnings

import nucos
from nucos import convert

from ..common.utilities import dataclass_to_json
Expand Down Expand Up @@ -124,6 +126,22 @@ def _make_float(value):
pass
return value

def validate(self):

if self is None: # how can this happen?!?! -- but it does.
return []

msgs = []

if hasattr(nucos, 'is_supported_unit'):
if not nucos.is_supported_unit(self.unit_type, self.unit):
valid_units = nucos.get_supported_names(self.unit_type)
msgs.append(ERRORS["E045"].format(self.unit, self.unit_type, valid_units))
else:
warnings.warn("nucos version >= 3.1.0 required for unit validation")

return msgs

def py_json(self, sparse=True):
"""
unit_type is added here, as it's not a settable field
Expand Down Expand Up @@ -215,9 +233,10 @@ def convert_to(self, new_unit):
return self

def validate(self):
msgs = []
if self is None: # how can this happen?!?! -- but it does.
return msgs
return []

msgs = super().validate()

# only do this for C or K
if (self.unit is not None) and (self.unit.upper() not in {'C', 'K'}):
Expand Down Expand Up @@ -279,6 +298,11 @@ class Unitless(MeasurementBase):
def convert_to(self, *args, **kwargs):
raise TypeError("You can not convert a Unitless measurement")

def validate(self):
if (self is not None) and (self.unit is not None):
return [f"E045: Unitless measurements should have no unit. '{self.unit}' is not valid"]
return []


class Dimensionless(MeasurementBase):
"""
Expand Down Expand Up @@ -405,6 +429,18 @@ def __eq__(self, other):
return self.__dict__ == other.__dict__


def validate(self):
"""
a kludge -- this should probably create the correct Measurement
when created instead
"""
if self is None:
return []
if self.unit_type == "unitless":
return Unitless.validate(self)
return super().validate()


class Density(MeasurementBase):
unit_type = "density"

Expand All @@ -424,10 +460,37 @@ class Pressure(MeasurementBase):
class NeedleAdhesion(MeasurementBase):
unit_type = "needleadhesion"

def validate(self):
if (self is not None) and (self.unit.strip().lower() != "g/m^2"):
return [f'E045: Needle Adhesion can only have units of: "g/m^2". "{self.unit}" is not valid']
return []

class InterfacialTension(MeasurementBase):
unit_type = "interfacialtension"


class AngularVelocity(MeasurementBase):
unit_type = 'angularvelocity'


# def set_valid_units(cls):
# """
# sets the valid units for a Measurement class

# done by querying nucos
# """
# print("setting units on:", cls)

# cls.valid_units = nucos.get_all_valid_unit_names(cls.unit_type)

# print("valid units are:", cls.valid_units)


# for name, obj in dict(vars()).items():
# try:
# if issubclass(obj, MeasurementBase):
# print(name, "is a Measurement, with unit type:", obj.unit_type)
# set_valid_units(obj)
# except TypeError:
# pass

2 changes: 1 addition & 1 deletion adios_db/adios_db/models/oil/oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .version import Version
from .review_status import ReviewStatus

ADIOS_DATA_MODEL_VERSION = Version(0, 11, 0)
ADIOS_DATA_MODEL_VERSION = Version(0, 12, 0)

from .version_update import update_json # noqa: E402

Expand Down
3 changes: 2 additions & 1 deletion adios_db/adios_db/models/oil/physical_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def validate(self):
"""
points_list = self
data_str = self.__class__.__name__
msgs = []
msgs = super().validate()


# check for odd temperatures
for pt in points_list:
Expand Down
5 changes: 4 additions & 1 deletion adios_db/adios_db/models/oil/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
InterfacialTension,
Pressure,
AngularVelocity)

from .physical_properties import DynamicViscosityList, KinematicViscosityList

from ..common.validators import EnumValidator
from .validation.errors import ERRORS
Expand Down Expand Up @@ -71,6 +71,9 @@ class Emulsion:

complex_viscosity: DynamicViscosity = None

kinematic_viscosities: KinematicViscosityList = field(default_factory=KinematicViscosityList)
dynamic_viscosities: DynamicViscosityList = field(default_factory=DynamicViscosityList)

method: str = None
visual_stability: str = None

Expand Down
4 changes: 2 additions & 2 deletions adios_db/adios_db/models/oil/validation/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"E041": "Value for {}: {} must be between 0 and 1",
"E042": "Must have a value for {}",
"E043": "API, {} does not match density at 60F. API should be: {:.1f}",
"E044": "Value: {} for {} is not valid",

"E044": "Value: '{}' for '{}' is not valid",
"E045": "Unit: '{}' is not a valid unit for unit type: '{}'. Options are: {}",

# E05* -- duplicates, etc
"E050": "Duplicate {} in {}",
Expand Down
39 changes: 28 additions & 11 deletions adios_db/adios_db/models/oil/version_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def __call__(self, py_json):
elif this_ver != self.ver_from: # can't update this
return py_json
else: # we can do the update
return self.update(py_json)


class update_0_10_0_to_0_10_0(Updater):
ver_from = Version(0, 10, 0)
ver_to = Version(0, 11, 0)
self._version_check(py_json)
py_json = self.update(py_json)
py_json['adios_data_model_version'] = str(self.ver_to)
return py_json

def update(self, py_json):
# do-nothing updater for only additions.
return py_json

def _version_check(self, py_json):
# just in case
this_ver = Version(py_json.get('adios_data_model_version'))

Expand All @@ -36,6 +38,13 @@ def update(self, py_json):
f"JSON version: {this_ver}, this updater "
f"can update: {self.ver_from}")


class update_0_10_0_to_0_11_0(Updater):
ver_from = Version(0, 10, 0)
ver_to = Version(0, 11, 0)

def update(self, py_json):
# self._version_check(py_json)
# change the name of the fraction_weathered attribute
if 'sub_samples' in py_json: # very sparse records may not
for ss in py_json['sub_samples']:
Expand All @@ -46,15 +55,23 @@ def update(self, py_json):
md['fraction_evaporated'] = md.get('fraction_weathered')
md.pop('fraction_weathered', None)

py_json['adios_data_model_version'] = str(self.ver_to)

# py_json['adios_data_model_version'] = str(self.ver_to)
return py_json

class update_0_11_0_to_0_12_0(Updater):
"""
an updater for only additions
-- nothing to be done other than update the version
"""
ver_from = Version(0, 11, 0)
ver_to = Version(0, 12, 0)

# NOTE: updaters need to be in order
# not hard when there is only one :-)
UPDATERS = [update_0_10_0_to_0_10_0()]

# NOTE: updaters need to be in order
# this could be automated it if gets unwieldy
UPDATERS = [update_0_10_0_to_0_11_0(),
update_0_11_0_to_0_12_0(),
]

def update_json(py_json):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"oil_id": "EC02234",
"adios_data_model_version": "0.11.0",
"adios_data_model_version": "0.12.0",
"metadata": {
"name": "Access West Blend Winter",
"source_id": "2234",
Expand Down
Loading

0 comments on commit 70fda83

Please sign in to comment.