def setupDfs0():
  global shePath
  global dfs
  global dfsDataX
  global dfsDataY
  global nX
  global nY
  global nZ
  import clr
  global simStart
  global simStart
  now = MShePy.wm.currentTime()
  clr.AddReference("DHI.Mike.Install, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c513450b5d0bf0bf") # "fully qualified" name required!
  from DHI.Mike.Install import MikeImport, MikeProducts
  MikeImport.SetupLatest()
  clr.AddReference("DHI.Generic.MikeZero.DFS")
  clr.AddReference("DHI.Generic.MikeZero.EUM")
  clr.AddReference("System")
  import System
  from System import Array
  from DHI.Generic.MikeZero import eumUnit, eumItem, eumQuantity
  from DHI.Generic.MikeZero.DFS import DfsFactory, DfsBuilder, DfsSimpleType, DataValueType
  shePath = MShePy.wm.getSheFilePath()
  sheDir = os.path.dirname(shePath)
  filename = os.path.join(sheDir, 'BndFluxes.dfs2')
  builder = DfsBuilder.Create(filename, "MSHE SZ boundary fluxes output per layer", 0)
  builder.SetDataType(1)
  factory = DfsFactory()
  builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin("NON-UTM", 0, 0, 0))
  simStart = now
  nowSys = System.DateTime(now.year, now.month, now.day, now.hour, now.minute, now.second)
  # note: time unit given here has to be used in WriteItemTimeStepNext
  axis = factory.CreateTemporalNonEqCalendarAxis(eumUnit.eumUsec, nowSys)
  builder.SetTemporalAxis(axis)
  builder.DeleteValueFloat = -1e-30
  (startTime, endTime, values) = MShePy.wm.getValues(MShePy.paramTypes.SZ_X_FLO) # just for the geometry
  (nX, nY, nZ) = values.shape()
  (x0, y0) = MShePy.wm.gridCellToCoord(0, 0)
  (x1, y1) = MShePy.wm.gridCellToCoord(1, 1)
  dfsDataX = Array.CreateInstance(System.Single, nX * nY)
  dfsDataY = Array.CreateInstance(System.Single, nX * nY)
  for x in range(nX):
    for y in range(nY):
      if(not MShePy.wm.gridIsInModel(x, y)):
        dfsDataX[x + y * nX] = builder.DeleteValueFloat
        dfsDataY[x + y * nX] = builder.DeleteValueFloat
  dx = x1 - x0  # cell size, dx == dy
  axis = factory.CreateAxisEqD2(eumUnit.eumUmeter, nX, x0 - dx / 2, dx, nY, y0 - dx / 2, dx)
  itemBuilder = builder.CreateDynamicItemBuilder()
  itemBuilder.SetValueType(DataValueType.MeanStepBackward)
  itemBuilder.SetAxis(axis)
  for iz in range(nZ):
    for xy in ['x', 'y']:
      itemBuilder.Set('Boundary inflow layer {0}, {1}-direction'.format(iz + 1, xy), eumQuantity.Create(eumItem.eumIDischarge, eumUnit.eumUm3PerSec), DfsSimpleType.Float)
      builder.AddDynamicItem(itemBuilder.GetDynamicItemInfo()) 
  builder.CreateFile(filename)
  dfs = builder.GetFile()
# Writes times of DFS file to console (csv format)

import sys
import clr
from math import *
import array

# The SetupLatest method will make your script find the MIKE assemblies at runtime.
# This is required for MIKE Version 2019 (17.0) and onwards. For previous versions, the
# next three lines must be removed.
clr.AddReference("DHI.Mike.Install")
from DHI.Mike.Install import MikeImport, MikeProducts
MikeImport.SetupLatest(MikeProducts.MikeCore)

clr.AddReference("DHI.Generic.MikeZero.DFS")
clr.AddReference("DHI.Generic.MikeZero.EUM")
clr.AddReference("System")
import System
from System import Array, DateTime
from DHI.Generic.MikeZero import eumUnit, eumItem, eumQuantity
from DHI.Generic.MikeZero.DFS import *

if (len(sys.argv) == 1):
    print "Usage: Writes times of DFS file to console (csv format)"
    print "    ipy.exe PrintDfsTimes.py dfsFileName.dfs"
    sys.exit()

filename = sys.argv[1]

dfsFile = DfsFileFactory.DfsGenericOpen(filename)
# Example on how to take one of the result file types that is supported
# by MIKE 1D, and convert to res1d file. This example is converting
# a MOUSE RR file (.crf) to res1d.

import sys
import clr

# The SetupLatest method will make your script find the latest MIKE assemblies at runtime.
clr.AddReference(
    "DHI.Mike.Install, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c513450b5d0bf0bf"
)
from DHI.Mike.Install import MikeImport, MikeProducts
MikeImport.SetupLatest()
print('Found MIKE in: ' + MikeImport.ActiveProduct().InstallRoot)

clr.AddReference("DHI.Mike1D.ResultDataAccess")
clr.AddReference("DHI.Mike1D.Generic")
from DHI.Mike1D.ResultDataAccess import ResultData, ResultDataSearch
from DHI.Mike1D.Generic import Connection

resultData = ResultData()
resultData.Connection = Connection.Create("DemoBase.crf")
resultData.Load()

# For crf files, set Type to "" if None (null) - work-around for a bug
for c in resultData.Catchments:
    if (c.Type is None):
        c.Type = ""

resultData.Connection = Connection.Create("DemoBase-crf.res1d")
resultData.Save()
Exemple #4
0
import clr

clr.AddReference("System")
import System
from System import Array, StringComparer

# The SetupLatest method will make your script find the MIKE assemblies at runtime.
# This is required for MIKE Version 2019 (17.0) and onwards. For previous versions, the
# next three lines must be removed.
clr.AddReference(
    "DHI.Mike.Install, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c513450b5d0bf0bf"
)
from DHI.Mike.Install import MikeImport, MikeProducts

products = list(MikeImport.InstalledProducts())
product = products[0]
MikeImport.Setup(product)

clr.AddReference("DHI.Mike1D.ResultDataAccess")
clr.AddReference("DHI.Mike1D.Generic")
clr.AddReference("DHI.Generic.MikeZero.DFS")
clr.AddReference("DHI.Generic.MikeZero.EUM")
from DHI.Mike1D.ResultDataAccess import ResultData, ResultDataSearch, Filter, DataItemFilterName, ItemTypeGroup
from DHI.Mike1D.Generic import Diagnostics, Connection
from DHI.Generic.MikeZero import eumUnit, eumItem, eumQuantity
from DHI.Generic.MikeZero.DFS import DfsFactory, DfsBuilder, DfsSimpleType, DataValueType, StatType

#endregion .NET imports

"""
This is an example script showing how to export
from Mike+ setup file (mupp/slite) to Mike1D m1dx file.
"""

import clr

clr.AddReference(
    "DHI.Mike.Install, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c513450b5d0bf0bf"
)
from DHI.Mike.Install import MikeImport, MikeProducts

MikeImport.SetupLatest(MikeProducts.MikePlus)

clr.AddReference("DHI.Mike1D.Generic")
from DHI.Mike1D.Generic import Connection, FilePath, Diagnostics

clr.AddReference("DHI.Mike1D.Mike1DDataAccess")
from DHI.Mike1D.Mike1DDataAccess import Mike1DBridge


def CreateConnection(inputFileName, simulationId=None):
    connection = Connection.Create(inputFileName)
    # Choose a particular simulation ID from Mike+ setup
    # If this is not set then the active simulation is exported
    if simulationId is not None:
        connection.Options.Add("simulationId", simulationId)

    return connection