Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uf/#57-fixLineTypeMismatch #79

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0] - 2021-08-03
### Added
- Basic functionality to convert SimBench data sets to [PowerSystemDataModel](https://github.com/ie3-institute/powersystemdatamodel)

### Changed
- Line type can be mapped to more than one vRated voltage.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG should be cumulative. That means, that you please keep, what is written under [1.0.0] and add your Changed part beneath Unreleased


[Unreleased]: https://github.com/ie3-institute/simbench2psdm/compare/v1.0...HEAD
[1.0.0]: https://github.com/ie3-institute/simbench2psdm/releases/tag/1.0
26 changes: 26 additions & 0 deletions inputData/config/EHV.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
io {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the config. Those files should be kept locally.

input {
csv = {
fileEncoding = "UTF-8"
fileEnding = ".csv"
separator = ";"
directoryHierarchy = false
}
}

output {
csv = {
fileEncoding = "UTF-8"
fileEnding = ".csv"
separator = ";"
directoryHierarchy = false
}

targetFolder = "convertedData/ratedVoltageMismatch"
compress = false
}

simbenchCodes = [
"1-EHVHV-mixed-all-0-no_sw"
]
}
11 changes: 8 additions & 3 deletions src/main/scala/edu/ie3/simbench/convert/LineConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import edu.ie3.datamodel.utils.GridAndGeoUtils
import edu.ie3.simbench.exception.ConversionException
import edu.ie3.simbench.model.datamodel.types.LineType
import edu.ie3.simbench.model.datamodel.{Line, Node}
import edu.ie3.util.quantities.PowerSystemUnits.KILOMETRE
import edu.ie3.util.quantities.PowerSystemUnits.{KILOMETRE, KILOVOLT}
import javax.measure.quantity.ElectricPotential
import tech.units.indriya.ComparableQuantity
import tech.units.indriya.quantity.Quantities

import scala.collection.parallel.CollectionConverters._
Expand All @@ -29,15 +31,18 @@ case object LineConverter extends LazyLogging {
*/
def convert(
inputs: Vector[Line[_ <: LineType]],
types: Map[LineType, LineTypeInput],
types: Map[
(LineType, ComparableQuantity[ElectricPotential]),
LineTypeInput
],
nodes: Map[Node, NodeInput]
): Vector[LineInput] =
inputs.par.flatMap {
case acLine: Line.ACLine =>
val (nodeA, nodeB) =
NodeConverter.getNodes(acLine.nodeA, acLine.nodeB, nodes)
val lineType = types.getOrElse(
acLine.lineType,
(acLine.lineType, Quantities.getQuantity(acLine.nodeA.vmR, KILOVOLT)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use a composite key to access a map. However, the second part (the voltage) is set up from Doubles. Thus, it could be error prone. Maybe you may add a warning comment, that this only works, if you don't do any calculations with the voltage, that you provide here.

throw ConversionException(
s"Cannot find conversion result for line type ${acLine.lineType.id}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,14 @@ case object LineTypeConverter extends LazyLogging {
*/
def convert(
lines: Vector[Line[_ <: LineType]]
): Map[LineType, LineTypeInput] = {
val ratedVoltageMapping = getRatedVoltages(lines)
val lineTypes = lines.map(line => line.lineType).distinct

lineTypes
.map(
lineType =>
lineType -> convert(
lineType,
ratedVoltageMapping.getOrElse(
lineType,
throw SimbenchDataModelException(
s"Cannot find the rated voltage vor line type ${lineType}"
)
)
)
)
.toMap
): Map[(LineType, ComparableQuantity[ElectricPotential]), LineTypeInput] = {
assignRatedVoltages(lines).map {
case pair @ (lineType, vRated) =>
pair -> convert(
lineType,
vRated
)
}.toMap
}

/**
Expand Down Expand Up @@ -91,42 +81,10 @@ case object LineTypeConverter extends LazyLogging {
* @param lines [[Vector]] of [[Line]]s
* @return Mapping of [[LineType]] to [[ComparableQuantity]] of type [[ElectricPotential]]
*/
def getRatedVoltages(
def assignRatedVoltages(
lines: Vector[Line[_ <: LineType]]
): Map[LineType, ComparableQuantity[ElectricPotential]] = {
val rawMapping = lines
.distinctBy(line => line.lineType)
.map(line => determineRatedVoltage(line))
.groupMap(_._1)(_._2)

/* Sanity check, that there is no ambiguous mapping */
rawMapping.find {
case (_, ratedVoltages) if ratedVoltages.length > 1 =>
true
case _ =>
false
} match {
case Some(ambiguousEntry) =>
throw SimbenchDataModelException(
s"Found ambiguous rated voltages for at least one entry: $ambiguousEntry"
)
case None =>
logger.debug(
"Great! Found only unambiguous line type to rated voltage mappings."
)
}

/* Mapping the line type to the rated voltage of the first entry of the Vector of each raw mapping. That nothing
* is missed is ensured by the sanity check beforehand */
rawMapping.map {
case (lineType, lineTypeVRatedVector) =>
lineType -> lineTypeVRatedVector.headOption.getOrElse(
throw SimbenchDataModelException(
s"Cannot receive rated voltage for line type '$lineType'."
)
)
}
}
): Vector[(LineType, ComparableQuantity[ElectricPotential])] =
lines.map(line => determineRatedVoltage(line)).distinct

/**
* Maps the [[LineType]] of the specific line to it's rated voltage based on the line's nodes' rated voltages
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simbench/io/SimbenchReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ final case class SimbenchReader(
read(clazz, fields)
}
),
Duration("10 s")
Duration("100 s")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit this, as it was just an adaption to make it run on your PC.

)
.toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LineTypeConverterSpec extends UnitSpec with ConverterTestData {
}

"build line type to rated voltage mapping correctly" in {
val actual = LineTypeConverter.getRatedVoltages(lineVec)
val actual = LineTypeConverter.assignRatedVoltages(lineVec)
val expected = Map(
getACLineTypes("NAYY 4x150SE 0.6/1kV")._1 -> Quantities
.getQuantity(0.4, KILOVOLT),
Expand Down