Skip to content
Snippets Groups Projects

Draft: parse prefix as scale factor

Closed Henrike Fleischhack requested to merge issue_prefix into main

Siehe #17 (closed)

Klappt jetzt fast alles. Es kann sein, dass nicht alle Ausgabenmodi die Scale-Faktoren enthalten. Ich habe auch noch nicht die Integration mit dccQuantities getestet.

Die Umrechnung in Base-Einheiten hat auch noch ein paar Probleme, siehe Test-case unten. Bin aber nicht sicher, ob das in den gleichen PR gehört.

Test-Code
from dsiUnits import dsiUnit

u_cm = dsiUnit(r"\centi\metre")
u_m = dsiUnit(r"\metre")
u_s = dsiUnit(r"\second")


u_cm2 = dsiUnit(r"\centi\metre\tothe{2}")
u_mcm = dsiUnit(r"\metre\centi\metre")
u_cmm = dsiUnit(r"\centi\metre\metre")

u_cm1 = dsiUnit(r"\centi\metre\tothe{-1}")
u_pcm = dsiUnit(r"\one\per\centi\metre")


print(f"s * cm = {u_s*u_cm} = {(u_s*u_cm).toBaseUnitTree()}")
print(f"cm * s = {u_cm*u_s} = {(u_cm*u_s).toBaseUnitTree()}")
print(f"cm * m = {u_cm*u_m} = {(u_cm*u_m).toBaseUnitTree()}")
print(f"m * cm = {u_m*u_cm} = {(u_m*u_cm).toBaseUnitTree()}")
print("")

print(f"cm = {u_cm} = {u_cm.toBaseUnitTree()}" )
print(f"cm2 = {u_cm2} = {u_cm2.toBaseUnitTree()}" )
print("")

print(f"cm-1 = {u_cm1} = {u_cm1.toBaseUnitTree()}" )
print(f"1/cm = {u_pcm} = {u_pcm.toBaseUnitTree()}" )
print("")

print(f"cm2^-1 = {u_cm2**-1} = {(u_cm2**-1).toBaseUnitTree()} " )
print(f"cm / (cm2) = {u_cm/u_cm2} = {(u_cm/u_cm2).toBaseUnitTree()}" )

print("")
print(f"cm2 / m = {u_cm2/u_m} = {(u_cm2/u_m).toBaseUnitTree()}" )
print(f"m*cm / (cm2) = {u_mcm/u_cm2} = {(u_mcm/u_cm2).toBaseUnitTree()}" )
print("")

u_eV = dsiUnit(r"\electronvolt")
u_J = dsiUnit(r"\joule")
print(f"eV = {u_eV} = {u_eV.toBaseUnitTree()}")
print(f"J = {u_J} = {u_J.toBaseUnitTree()}")
print(f"eV/J = {(u_eV/u_J)} = {(u_eV/u_J).toBaseUnitTree()}")
print(f"J*eV = {u_J*u_eV} = {(u_J*u_eV).toBaseUnitTree()}")
Ausgabe
s * cm = 0.01*\metre\second = 0.01*\metre\second
cm * s = 0.01*\metre\second = 0.01*\metre\second
cm * m = 0.01*\metre\tothe{2} = 0.01*\metre\tothe{2}
m * cm = 0.01*\metre\tothe{2} = 0.01*\metre\tothe{2}

cm = 0.01*\metre = 0.01*\metre
cm2 = 0.0001*\metre\tothe{2} = 0.0001*\metre\tothe{2}

cm-1 = 100.0*\metre\tothe{-1} = 100.0*\metre\tothe{-1}
1/cm = \one\per0.01*\metre = 100.0*\metre\tothe{-1}

cm2^-1 = 10000.0*\metre\tothe{-2} = 10000.0*\metre\tothe{-2}
cm / (cm2) = \one\per0.01*\metre = 100.0*\metre\tothe{-1}

cm2 / m = 0.0001*\metre = 0.0001*\metre
m*cm / (cm2) = 100.0*\one = 100.0*\one

eV = \electronvolt = 1.602176634e-19*\joule
J = \joule = \kilogram\metre\tothe{2}\second\tothe{-2}
eV/J = \electronvolt\per\joule = 1.602176634e-19*\joule\kilogram\tothe{-1}\metre\tothe{-2}\second\tothe{2}
J*eV = \electronvolt\joule = 1.602176634e-19*\joule\kilogram\metre\tothe{2}\second\tothe{-2}

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Henrike Fleischhack requested review from @Seeger

    requested review from @Seeger

  • added 2 commits

    • 3bb02b52 - prefix in latex output and bug fix in node scaling
    • eb8f1b65 - force test pass

    Compare with previous version

  • We were able to reproduce the error and will have a look at this fix. In the next version (next week) we will change the behavior as suggested here (calculating scale factors instead of arithmetic on the Prefixes). We will ad a function to convert a scale Factor to an SI prefix if this is possible as well as an option to rest the scale factor.

    The use case for the scale factor reset is: The scale factor was applied to the data so it dosn't need to be stored in the unit any longer.

    The baseUnitConversion errors are strongly related to this bug and will be fixed with this.

    eV needs extra treatment (eV is converted to J in the base unit conversion) but (J wasn't equal in the first round so its converted to its base unit representation leading to inequality in the next conversion)

    Many thanks for your support :smile:

  • Benedikt mentioned in commit c919e272

    mentioned in commit c919e272

  • Benedikt mentioned in commit 6e4ba046

    mentioned in commit 6e4ba046

  • closed

Please register or sign in to reply
Loading