Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions mikecore/DfsuBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __init__(self, dfsuFileType):
# Dynamic item information
self.__dynamicItemData = []

# spectral
self.__frequencies = None
self.__directions = None

self.__dfsuFileType = dfsuFileType
if dfsuFileType == DfsuFileType.Dfsu2D:
self.FileTitle = "Area Series"
Expand Down Expand Up @@ -113,6 +117,13 @@ def SetNumberOfSigmaLayers(self, numberOfSigmaLayers: int):
else:
raise Exception("dfsuFileType")

def SetFrequencies(self, frequencies):
self.__frequencies = frequencies

def SetDirections(self, directions):
self.__directions = directions


#/ <summary>
#/ Set a non-standard temporal axis for the dfsu file. WARNING: The dfsu file will not be valid in all contexts.
#/ <para>
Expand Down Expand Up @@ -278,7 +289,7 @@ def Validate(self, dieOnError: bool = False):
errors.append("Nodes have not been set")
if (not self.__isSetConnectivity):
errors.append("Elements have not been set")
if (not self.__isSetNumberOfSigmaLayers and self.__dfsuFileType != DfsuFileType.Dfsu2D):
if (not self.__isSetNumberOfSigmaLayers and self.__dfsuFileType in (DfsuFileType.Dfsu3DSigma, DfsuFileType.Dfsu3DSigmaZ, DfsuFileType.DfsuVerticalColumn, DfsuFileType.DfsuVerticalProfileSigma, DfsuFileType.DfsuVerticalProfileSigmaZ)):
errors.append("Number of sigma layers has not been set")

# Check that all nodenumbers are within the range of
Expand Down Expand Up @@ -326,7 +337,11 @@ def Validate(self, dieOnError: bool = False):
minNumberOfLayers = DfsuUtil.FindMinNumberOfLayers(topLayerElements)
if (minNumberOfLayers < self.__numberOfSigmaLayers):
errors.append("The minimum number of layers is smaller than the number of sigma layers. Element table is invalid")
elif self.__dfsuFileType in (DfsuFileType.DfsuSpectral0D, DfsuFileType.DfsuSpectral1D, DfsuFileType.DfsuSpectral2D):
# TODO do we need to check frequency or directions?
pass
else:

raise Exception("Dfsu file type {} not supported".format(self.__dfsuFileType))


Expand Down Expand Up @@ -384,7 +399,15 @@ def SetupBuilder(self):
factory = DfsFactory()
dfsBuilder = DfsBuilder.Create(self.FileTitle, self.ApplicationTitle, self.ApplicationVersion)

dfsBuilder.SetDataType(2001)
if self.__dfsuFileType == DfsuFileType.DfsuSpectral1D:
dfsBuilder.SetDataType(2002)
elif self.__dfsuFileType == DfsuFileType.DfsuSpectral2D:
dfsBuilder.SetDataType(2003)
else:
dfsBuilder.SetDataType(2001)



dfsBuilder.SetGeographicalProjection(self.__dfsProjection)
if (self.__timeAxis != None):
dfsBuilder.SetTemporalAxis(self.__timeAxis)
Expand All @@ -410,6 +433,10 @@ def SetupBuilder(self):
elif self.__dfsuFileType == DfsuFileType.Dfsu3DSigmaZ:
maxNumberOfLayers = DfsuUtil.FindMaxNumberOfLayers(DfsuUtil.FindTopLayerElements(self.__connectivity))
dfsBuilder.AddCreateCustomBlock("MIKE_FM",np.array([ self.__x.size, len(self.__connectivity), 3, maxNumberOfLayers, self.__numberOfSigmaLayers ], np.int32))
elif self.__dfsuFileType == DfsuFileType.DfsuSpectral1D:
dfsBuilder.AddCreateCustomBlock("MIKE_FM",np.array([ self.__x.size, len(self.__connectivity), 1, 0, len(self.__frequencies), len(self.__directions)], np.int32))
elif self.__dfsuFileType == DfsuFileType.DfsuSpectral2D:
dfsBuilder.AddCreateCustomBlock("MIKE_FM",np.array([ self.__x.size, len(self.__connectivity), 2, 0, len(self.__frequencies), len(self.__directions)], np.int32))
else:
raise Exception()

Expand Down Expand Up @@ -446,7 +473,21 @@ def SetupBuilder(self):
# dfsItem.SetAxis(factory.CreateAxisDummy(len(self.__connectivity)))
#else
# Set axis to have meter unit (not necessary, just to make file exactly equal)
dfsItem.SetAxis(factory.CreateAxisEqD1(eumUnit.eumUmeter, len(self.__connectivity), 0, 1))

if self.__dfsuFileType in (DfsuFileType.DfsuSpectral1D, DfsuFileType.DfsuSpectral2D):
if self.__dfsuFileType == DfsuFileType.DfsuSpectral1D:
size = self.__x.size
if self.__dfsuFileType == DfsuFileType.DfsuSpectral2D:
size = len(self.__connectivity)

if self.__frequencies is not None:
size *= len(self.__frequencies)
if self.__directions is not None:
size *= len(self.__directions)

dfsItem.SetAxis(factory.CreateAxisEqD1(eumUnit.eumUmeter, size, 0, 1))
else:
dfsItem.SetAxis(factory.CreateAxisEqD1(eumUnit.eumUmeter, len(self.__connectivity), 0, 1))
# Set to default ufs delete values (not used anyway, just to make file exactly equal)
dfsItem.SetReferenceCoordinates(-1e-35, -1e-35, -1e-35)
dfsItem.SetOrientation(-1e-35, -1e-35, -1e-35)
Expand Down Expand Up @@ -479,6 +520,7 @@ def CreateDfsu(self, dfsBuilder, elementType, nodesPerElmt, connectivityArray):

intCode = eumQuantity(eumItem.eumIIntegerCode, eumUnit.eumUintCode)
xyQuantity = eumQuantity(eumItem.eumIGeographicalCoordinate, eumUnit.eumUmeter)

# TODO: reenable:
#if (MapProjection.IsValid(self.__dfsProjection.WKTString)):
# if (MapProjection.IsGeographical(self.__dfsProjection.WKTString)):
Expand Down Expand Up @@ -511,6 +553,12 @@ def CreateDfsu(self, dfsBuilder, elementType, nodesPerElmt, connectivityArray):
# Connectivity
connectivityItem = dfsBuilder.AddCreateStaticItem("Connectivity", intCode, connectivityArray)

# Spectral
frequencyItem = dfsBuilder.AddCreateStaticItem("Frequency", eumQuantity(eumItem.eumIFrequency, eumUnit.eumUhertz), self.__frequencies) if self.__frequencies is not None else None

# TODO unit
directionItem = dfsBuilder.AddCreateStaticItem("Direction", eumQuantity(eumItem.eumIDirection, eumUnit.eumUradian), self.__directions) if self.__directions is not None else None

dfsFile = dfsBuilder.GetFile()

dfsuFile = DfsuFile()
Expand All @@ -530,7 +578,9 @@ def CreateDfsu(self, dfsBuilder, elementType, nodesPerElmt, connectivityArray):
self.__elementIds,
elementType,
self.__connectivity,
self.__zUnit
self.__zUnit,
frequencyItem,
directionItem
)

return (dfsuFile)
Expand Down
9 changes: 8 additions & 1 deletion mikecore/DfsuFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, dfsFile = None):

self.__elmtIdItem = None;

self.__freqItem = None
self.__dirItem = None

# Node variables
self.NodeIds = None;
self.X = None;
Expand Down Expand Up @@ -326,7 +329,9 @@ def DfsuFileBuild(
elementIds,
elementType,
connectivity,
zUnit
zUnit,
freqItem,
dirItem,
):

self.dfsFile = dfsFile;
Expand All @@ -345,6 +350,8 @@ def DfsuFileBuild(
self.ElementType = elementType;
self.ElementTable = connectivity;
self.ZUnit = zUnit;
self.__freqItem = freqItem
self.__dirItem = dirItem
self.__Init(dfsFile, build = True)


Expand Down
2 changes: 1 addition & 1 deletion mikecore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import platform
from pathlib import Path

__version__ = "0.2.2"
__version__ = "0.3.0a0"

p = platform.architecture()
if not "64" in p[0]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="mikecore",
version="0.2.2",
version="0.3.0a0",
install_requires=["numpy"],
author="DHI",
author_email="mike@dhigroup.com",
Expand Down
Loading