Skip to content

Commit

Permalink
- Handle different types of value
Browse files Browse the repository at this point in the history
- Default to 1D list for `value`
  • Loading branch information
ndaelman committed Nov 12, 2024
1 parent de12d9f commit 7d7ed9a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/nomad_simulations/schema_packages/physical_property.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from functools import wraps
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any
from types import NoneType

import numpy as np
from nomad import utils
from nomad.units import ureg
from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.annotations import ELNAnnotation
from nomad.datamodel.metainfo.basesections import Entity
Expand Down Expand Up @@ -227,7 +229,10 @@ def full_shape(self) -> list:
Returns:
(list): The full shape of the physical property.
"""
return self.variables_shape + self.rank
if (full_rank := self.variables_shape + self.rank):
return full_rank
else:
return ['*']

def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
Expand Down Expand Up @@ -287,8 +292,15 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
description=self.m_def.all_quantities['_base_value'].description,
)
)
if value is not None: # ! pin down type
self.value = value.to(self.m_def.all_quantities['value'].unit).magnitude

if isinstance(value, NoneType):
self.value = None
elif isinstance(value, ureg.Quantity):
self.value = np.asarray(value.to(self.m_def.all_quantities['value'].unit).magnitude)
elif isinstance(value, np.ndarray) or isinstance(value, list):
self.value = value
else:
self.value = [value]


class PropertyContribution(PhysicalProperty):
Expand Down

0 comments on commit 7d7ed9a

Please sign in to comment.