Skip to content

Commit 5a33bb6

Browse files
authored
Merge pull request #21 from BuildingEnergySimulationTools/module-rework
Module rework
2 parents d97e949 + ffe4e3f commit 5a33bb6

28 files changed

Lines changed: 437 additions & 3161 deletions

.github/workflows/build.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: build
2+
on:
3+
push:
4+
branches: ["main"]
5+
tags: ["*"]
6+
pull_request:
7+
jobs:
8+
lint:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.11
16+
- run: python -m pip install --upgrade pip wheel
17+
- run: pip install tox
18+
- run: tox -elint
19+
tests:
20+
name: ${{ matrix.name }}
21+
runs-on: ubuntu-latest
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- {name: '3.10', python: '3.10', tox: py310}
27+
- {name: '3.12', python: '3.12', tox: py312}
28+
- {name: 'min', python: '3.10', tox: min}
29+
steps:
30+
- uses: actions/checkout@v3
31+
- uses: actions/setup-python@v4
32+
with:
33+
python-version: ${{ matrix.python }}
34+
- name: Run test
35+
run: |
36+
python -m pip install --upgrade pip wheel
37+
pip install tox
38+
tox -e${{ matrix.tox }}
39+
- name: Upload coverage
40+
uses: codecov/codecov-action@v3
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}
43+
files: ./coverage.xml
44+
release:
45+
needs: [lint, tests]
46+
name: PyPI release
47+
if: startsWith(github.ref, 'refs/tags')
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v3
51+
- uses: actions/setup-python@v4
52+
- run: python -m pip install --upgrade pip wheel
53+
- run: pip install twine
54+
- run: python setup.py sdist bdist_wheel
55+
- run: twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/*

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ci:
2+
skip: [pip-compile]
3+
4+
repos:
5+
- repo: https://github.com/asottile/pyupgrade
6+
rev: v3.3.1
7+
hooks:
8+
- id: pyupgrade
9+
args: [--py310-plus]
10+
- repo: https://github.com/psf/black
11+
rev: 23.3.0
12+
hooks:
13+
- id: black
14+
language_version: python3
15+
- repo: https://github.com/pycqa/flake8
16+
rev: 6.0.0
17+
hooks:
18+
- id: flake8
19+
additional_dependencies: [flake8-bugbear==23.1.14]

LICENCE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**Modelitool Copyright (c) 2023, Nobatek-INEF4**
2+
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
1- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
2- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
3- Neither the name of Nobatek-INEF4 nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 1 addition & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,3 @@
11
# Modelitool
22

3-
Python tools for modelica.
4-
Use only UTC in datetime index.
5-
6-
## modelitool.measures.MeasuredDats
7-
8-
<span style="background-color: #ffe600">***class modelitool.measures.***<span style="color: #ff0040; font-size:1em">**MeasuredDats**</span>***(data=None, data_type=\{\}, corr_dict=\{\})***</span>
9-
10-
11-
Handle time series of measured data with missing or incorrect values.
12-
13-
Modelica CombiTimeTable input file can be generated from raw data or corrected data.
14-
15-
16-
**Parameters:**
17-
>**data :** *DataFrame* index must be a UTC timezone aware datetime index.
18-
19-
>**data_type :** *Dictionary* keys are data_type name (eg. temperatures, power), item is a list of columns
20-
21-
>**corr_dict :** *Dictionary* keys are data_type name. Item is a dictionary holding correction methods properties
22-
23-
24-
>**Available corrections :**
25-
- <code>minmax</code> : Remove values beyond or below specific threshold. Arguments : <code>upper, lower</code>
26-
- <code>derivative</code> : Remove values when absolute variation between to timstep is beyond defined threshold. Arguments : <code>lower_rate, upper_rate</code>
27-
- <code>fill_nan</code> : Fill <code>nan</code> values. Argument is a list of method :
28-
- <code>bfill</code> : Back propagates the next not nan value
29-
- <code>ffill</code> : Front propagates the last not nan value
30-
- <code>linear_interpolation</code>: Interpolate value with <code>linear</code> method.
31-
32-
**Attributes**
33-
- **data :** copy of raw data
34-
- **data_type_dict :** dictionary of data_type
35-
- **corrected_data :** corrected data. Copy of data if no correction is applied
36-
- **corr_dict :** dictionary of corrections
37-
- **correction_journal :** History of measures properties. Gaps and missing values
38-
39-
**Methods**
40-
- **remove_anomalies**_()_ : apply minmax and derivative corrections described in <code>corr_dict</code>. Update correction journal with dict of missing values and measure gaps resume
41-
- **fill_nan**_()_ : apply <code>fill_nan</code> corrections described in <code>corr_dict</code>. Update correction journal with dict of missing values and measure gaps resume
42-
- **resample**_(timestep)_ : resample <code>corrected_data</code> to specify timestep. If no timestep is specified, the function uses the DataFrame mean difference of its time index.
43-
- **generate_combitimetable_input**_(file_path, corrected_data=True)_ : generate a modelica CombiTimeTable input file based on <code>data</code> or <code>corrected_data</code>
44-
- **auto_correct**_()_ : apply <code>remove_anomalies(), fill_nan(), resample()</code> in that order, using default arguments
45-
46-
47-
**Example**
48-
49-
<pre><code>
50-
my_measures = MeasuredDats(
51-
data = my_dirty_measure_df,
52-
data_type_dict = {
53-
"power": ["Power1", "Power2"],
54-
"temperatures": ["Temperature1", "Temperature2"]
55-
},
56-
corr_dict = {
57-
"power": {
58-
"minmax": {
59-
"upper": 40000,
60-
"lower": 0
61-
},
62-
"derivative": {
63-
"upper_rate": 5000,
64-
"lower_rate": 0,
65-
},
66-
"fill_nan": [
67-
"linear_interpolation",
68-
"bfill",
69-
"ffill"
70-
],
71-
"resample": np.mean,
72-
},
73-
"temperatures": {
74-
"minmax": {
75-
"upper": 50,
76-
"lower": -2
77-
},
78-
"derivative": {
79-
"upper_rate": 5,
80-
"lower_rate": 0,
81-
},
82-
"fill_nan": [
83-
"linear_interpolation",
84-
"bfill",
85-
"ffill"
86-
],
87-
"resample": np.sum,
88-
}
89-
}
90-
)
91-
</code></pre>
92-
93-
## modelitool.weather.OikolabWeatherData
94-
95-
<span style="background-color: #ffe600">***class modelitool.weather.***<span style="color: #ff0040; font-size:1em">**OikolabWeatherData**</span>***(location_name=None, location_lat=None, location_long=None, start=None, end=None, api_key=None)***</span>
96-
97-
Get meteorological data from oikolab API. Transforms it to epw and TMY5 file
98-
Available data are:
99-
- Dry bulb temperatures [°C]
100-
- Dew point temperatures [°C]
101-
- Relative humidity [%]
102-
- Atmospheric pressure [Pa]
103-
- Global horizontal radiation [W/m²]
104-
- Direct normal radiation [W/m²]
105-
- Diffuse solar radiation [W/m²]
106-
- Wind direction [deg]
107-
- Wind speed [m/s]
108-
- Total cloud cover [0-1]
109-
- Snowfall [mm of water equivalent]
110-
- Total precipitation [mm of water]
111-
112-
113-
114-
**Parameters:**
115-
>**location_name :** *String* Name of the meteo station.
116-
117-
>**location_lat :** *Float* Meteo site location latitude
118-
119-
>**location_long :** *Float* Meteo site location longitude
120-
121-
>**start :** *String* starting point date time format : <code>"YYYY-MM-DDThh:mm:ss"</code> provite UTC
122-
123-
>**end :** *String* ending point date time format : <code>"YYYY-MM-DDThh:mm:ss"</code> provite UTC
124-
125-
>**api_key :** *String* Oikolab API key
126-
127-
**Attributes**
128-
- **data :** DataFrame holding meteo data
129-
130-
**Methods**
131-
- **get_data**_()_ : Fetch meteorological data from Oikolab API
132-
- **generate_tmy5**_(file_path)_ : generate a TMY5 *.mos file compatible with Modelica Building library reader
133-
- **generate_epw**_(file_path)_ : generate a EPW *.epw file compatible with energyPlus
134-
135-
**Example**
136-
<pre><code>
137-
my_weather = OikolabWeatherData(
138-
location_name="Anglet",
139-
location_lat=43.47414153237001,
140-
location_long=-1.5095114151032965,
141-
start='2017-01-01T00:00:00',
142-
end='2017-12-31T23:00:00',
143-
api_key="d414d453fb0f496fb6dfa1c3xxxxxxxx"
144-
)
145-
</code></pre>
3+
Python tools for modelica.

modelitool/combitabconvert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def seconds_to_datetime(index_second, ref_year):
1111
def datetime_to_seconds(index_datetime):
1212
time_start = dt.datetime(index_datetime[0].year, 1, 1, tzinfo=dt.timezone.utc)
1313
new_index = index_datetime.to_frame().diff().squeeze()
14-
new_index[0] = dt.timedelta(
14+
new_index.iloc[0] = dt.timedelta(
1515
seconds=index_datetime[0].timestamp() - time_start.timestamp()
1616
)
1717
sec_dt = [elmt.total_seconds() for elmt in new_index]
@@ -36,7 +36,8 @@ def df_to_combitimetable(df, filename):
3636
"""
3737
Write a text file compatible with modelica Combitimetables object from a
3838
Pandas DataFrame with a DatetimeIndex. DataFrames with non monotonically increasing
39-
datetime index will raise a ValueError to prevent bugs when file is used in Modelica.
39+
datetime index will raise a ValueError to prevent bugs when file is used in
40+
Modelica.
4041
@param df: DataFrame with DatetimeIndex
4142
@param filename: string or Path to the output file
4243
@return: None

0 commit comments

Comments
 (0)