-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from C2SM-RCM/coli
unit conversion for wrf and some other day capabilities
- Loading branch information
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Molar mass in g / mol | ||
MOLAR_MASSES_ = { | ||
"CH4": 16.04, | ||
"CO2": 44.01, | ||
# This is a test value | ||
"test": 1.0, | ||
"test2": 2.0, | ||
} | ||
|
||
|
||
def get_molar_mass(substance: str) -> float: | ||
"""Get the molar mass of a substance in g/mol.""" | ||
if substance not in MOLAR_MASSES_: | ||
raise ValueError( | ||
f"Unknown molar mass for substance `{substance}`." | ||
f"Please add it to the MOLAR_MASSES_ dictionary in {__file__}." | ||
) | ||
return MOLAR_MASSES_[substance] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from emiproc.utilities import get_day_per_year | ||
|
||
|
||
def test_get_day_per_year(): | ||
days = get_day_per_year(2000) | ||
assert days == 366 | ||
|
||
|
||
def test_get_day_per_year_2(): | ||
days = get_day_per_year(2001) | ||
assert days == 365 | ||
|
||
|
||
def test_get_day_per_year_none(): | ||
days = get_day_per_year(None) | ||
assert days == 365.25 | ||
|
||
|
||
def test_get_day_per_year_century(): | ||
days_2100 = get_day_per_year(2100) | ||
days_2000 = get_day_per_year(2000) | ||
assert days_2100 == 365 | ||
assert days_2000 == 366 | ||
|
||
days_2400 = get_day_per_year(2400) | ||
assert days_2400 == 366 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
from emiproc.utils.constants import get_molar_mass | ||
|
||
|
||
def test_molar_mass(): | ||
|
||
mm_ch4 = get_molar_mass("CH4") | ||
|
||
assert mm_ch4 == 16.04 | ||
|
||
|
||
def test_no_molar_mass_raises(): | ||
|
||
with pytest.raises(ValueError): | ||
get_molar_mass("SOMETHING UNKNOWN") |