Skip to content

Commit

Permalink
Merge pull request #84 from mitchute/DevUpdates
Browse files Browse the repository at this point in the history
Dev Updates 2024
  • Loading branch information
mitchute authored Apr 10, 2024
2 parents f0c0005 + 61cd5e8 commit 139cf90
Show file tree
Hide file tree
Showing 54 changed files with 519 additions and 340 deletions.
6 changes: 3 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
source =
glhe/
tests/
source = glhe

[report]
omit =
/usr/*
21 changes: 21 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Flake8

on: [push]

jobs:
flake8:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4.5.0
with:
python-version: '3.11'

- name: Install Pip Dependencies
run: pip install flake8

- name: Run Flake8
run: flake8 glhe
33 changes: 33 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PyPIRelease

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4.1.1

- name: Set up Python
uses: actions/setup-python@v4.5.0
with:
python-version: 3.10

- name: Install Pip Dependencies
shell: bash
run: pip install -r requirements.txt

- name: Build the Wheel
shell: bash
run: python3 setup.py bdist_wheel sdist

- name: Deploy on Test PyPi
uses: pypa/gh-action-pypi-publish@v1.8.14
with:
user: __token__
password: ${{ secrets.TEST_PYPIPW }}
repository-url: https://test.pypi.org/legacy/
28 changes: 28 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run Tests

on: [push]

defaults:
run:
shell: bash

jobs:
unit_tests:
strategy:
matrix:
os: [ windows-latest, macos-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4.5.0
with:
python-version: '3.11'
- name: Install Pip Dependencies
run: pip install -r requirements.txt
- name: Run Tests
run: coverage run -m pytest
- name: Coveralls
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 13 additions & 10 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Use the latest build image to get access to the most Python versions
build:
image: latest
version: 2

# Must use 3.4+ to get the ABC modules
python:
version: 3.6
sphinx:
configuration: docs/conf.py
builder: html

# Don't build any extra formats
formats: []
build:
os: ubuntu-22.04
tools:
python: "3.11"
apt_packages:
- doxygen

# You could potentially use a separate requirements file for doc-building - one that doesn't have CoolProp
requirements_file: requirements.txt
python:
install:
- requirements: requirements.txt
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Docs are hosted [here](https://glhe.readthedocs.io/en/latest/) by [ReadTheDocs](https://readthedocs.org/)

## Testing [![Build Status](https://travis-ci.org/mitchute/GLHE.svg?branch=master)](https://travis-ci.org/mitchute/GLHE)
## Testing [![Run Tests](https://github.com/mitchute/GLHE/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/mitchute/GLHE/actions/workflows/unit_tests.yml) [![Flake8](https://github.com/mitchute/GLHE/actions/workflows/flake8.yml/badge.svg)](https://github.com/mitchute/GLHE/actions/workflows/flake8.yml)

Tests are run by [Travis-ci.org](https://travis-ci.org/mitchute/GLHE)
Tests are run by [GitHub Actions](https://travis-ci.org/mitchute/GLHE)


## Coverage [![Coverage Status](https://coveralls.io/repos/github/mitchute/GLHE/badge.svg?branch=master)](https://coveralls.io/github/mitchute/GLHE?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = []

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand Down
2 changes: 1 addition & 1 deletion glhe/aggregation/agg_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def make_agg_method(inputs: dict, ip: InputProcessor):
"""
Factory method for creating load aggregation objects
:param inputs: load aggregation inputs
:param inputs: load aggregation input dictionary
:param ip: input processor instance
:return: load aggregation object
"""
Expand Down
15 changes: 7 additions & 8 deletions glhe/aggregation/base_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from abc import ABC, abstractmethod

import numpy as np
from scipy.interpolate import interp1d

from glhe.utilities.functions import load_interp1d
from glhe.utilities.functions import load_interp2d
from glhe.utilities.functions import Interpolator1D, Interpolator1DFromFile
from glhe.utilities.functions import Interpolator2DFromFile

join = os.path.join
norm = os.path.normpath
Expand All @@ -18,23 +17,23 @@ def __init__(self, inputs: dict):
# g-function values
if 'g-function-path' in inputs:
path_g = norm(join(cwd, inputs['g-function-path']))
self.interp_g = load_interp1d(path_g)
self.interp_g = Interpolator1DFromFile(path_g)
elif 'lntts' and 'g-values' in inputs:
data_g = np.transpose(np.array([inputs['lntts'], inputs['g-values']]))
self.interp_g = interp1d(data_g[:, 0], data_g[:, 1], fill_value='extrapolate')
self.interp_g = Interpolator1D(data_g[:, 0], data_g[:, 1])
else:
raise KeyError('g-function data not found.')

# g_b-function values
self.interp_g_b = None
if 'g_b-function-path' in inputs:
if 'g_b-flow-rates' in inputs:
self.interp_g_b = load_interp2d(inputs['g_b-function-path'], inputs['g_b-flow-rates'])
self.interp_g_b = Interpolator2DFromFile(inputs['g_b-function-path'], inputs['g_b-flow-rates'])
else:
self.interp_g_b = load_interp1d(inputs['g_b-function-path'])
self.interp_g_b = Interpolator1DFromFile(inputs['g_b-function-path'])
elif 'lntts_b' and 'g_b-values' in inputs:
data_g_b = np.transpose(np.array([inputs['lntts_b'], inputs['g_b-values']]))
self.interp_g_b = interp1d(data_g_b[:, 0], data_g_b[:, 1], fill_value='extrapolate')
self.interp_g_b = Interpolator1D(data_g_b[:, 0], data_g_b[:, 1])

self.ts = inputs['time-scale']

Expand Down
14 changes: 6 additions & 8 deletions glhe/aggregation/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Union

import numpy as np

from glhe.aggregation.agg_types import AggregationTypes
Expand Down Expand Up @@ -92,7 +90,7 @@ def aggregate(self, time: int, energy: float):
# update time
self.prev_update_time = time

def calc_temporal_superposition(self, time_step: int, flow_rate: float = None) -> Union[float, tuple]:
def calc_temporal_superposition(self, time_step: int, flow_rate: float = None) -> float | tuple[float, float]:

# compute temporal superposition
# this includes all thermal history before the present time
Expand All @@ -105,13 +103,13 @@ def calc_temporal_superposition(self, time_step: int, flow_rate: float = None) -
dts = np.append(np.concatenate((self.dts, self.sub_hr.dts)), time_step)
times = np.flipud(np.cumsum(np.flipud(dts)))[:-1]
lntts = np.log(times / self.ts)
g = self.interp_g(lntts)
g = self.interp_g.interpolate(lntts)

# convolution of delta_q and the g-function values
if self.interp_g_b:
# convolution for "g" and "g_b" g-functions
if not flow_rate:
g_b = self.interp_g_b(lntts)
g_b = self.interp_g_b.interpolate(lntts)
else:
g_b = np.flipud(self.interp_g_b(lntts, flow_rate))
return float(np.dot(dq, g)), float(np.dot(dq, g_b))
Expand All @@ -121,14 +119,14 @@ def calc_temporal_superposition(self, time_step: int, flow_rate: float = None) -

def get_g_value(self, time_step: int) -> float:
lntts = np.log(time_step / self.ts)
return float(self.interp_g(lntts))
return float(self.interp_g.interpolate(lntts))

def get_g_b_value(self, time_step: int, flow_rate: float = None) -> float:
lntts = np.log(time_step / self.ts)
if not flow_rate:
return float(self.interp_g_b(lntts))
return float(self.interp_g_b.interpolate(lntts))
else:
return float(self.interp_g_b(lntts, flow_rate))
return float(self.interp_g_b.interpolate(lntts, flow_rate))

def get_q_prev(self) -> float:
return float(self.sub_hr.energy[-1] / self.sub_hr.dts[-1])
10 changes: 5 additions & 5 deletions glhe/aggregation/no_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class NoAgg(BaseAgg):
"""
No aggregation. Just keep all of the values.
No aggregation. Just keep all the values.
"""

Type = AggregationTypes.NO_AGG

def __init__(self, inputs):
def __init__(self, inputs: dict):
BaseAgg.__init__(self, inputs)

def aggregate(self, time: int, energy: float):
Expand All @@ -27,7 +27,7 @@ def aggregate(self, time: int, energy: float):
# update time
self.prev_update_time = time

def calc_temporal_superposition(self, time_step: int) -> float:
def calc_temporal_superposition(self, time_step: int, _: float = None) -> float:
# compute temporal superposition
# this includes all thermal history before the present time
q = self.energy / self.dts
Expand All @@ -37,7 +37,7 @@ def calc_temporal_superposition(self, time_step: int) -> float:
dts = np.append(self.dts, time_step)
times = np.flipud(np.cumsum(np.flipud(dts)))[:-1]
lntts = np.log(times / self.ts)
g = self.interp_g(lntts)
g = self.interp_g.interpolate(lntts)

# convolution of delta_q and the g-function values
if self.interp_g_b:
Expand All @@ -51,7 +51,7 @@ def calc_temporal_superposition(self, time_step: int) -> float:
def get_g_value(self, time_step: int) -> float:
pass # pragma: no cover

def get_g_b_value(self, time_step: int) -> float:
def get_g_b_value(self, time_step: int, _: float = None) -> float:
pass # pragma: no cover

def get_q_prev(self) -> float:
Expand Down
17 changes: 15 additions & 2 deletions glhe/aggregation/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,25 @@ def aggregate(self, time: int, energy: float):
return
else:
# aggregate
dts_flip = np.flipud(self.dts)
vals, idxs, cnts = np.unique(dts_flip, return_counts=True, return_index=True)
# TODO: The next two lines are showing as unused in Pycharm, is this IF block needed then?
# dts_flip = np.flipud(self.dts)
# vals, idxs, cnts = np.unique(dts_flip, return_counts=True, return_index=True)
self.energy[-1] += e_1

# numpy split will do a lot of work too

# update times
self.prev_update_time = time
self.prev_update_time_hr = int(time / SEC_IN_HOUR)

def calc_temporal_superposition(self, time_step: int, flow_rate: float = None) -> float:
pass

def get_g_value(self, time_step: int) -> float:
pass

def get_g_b_value(self, time_step: int, flow_rate: float = None) -> float:
pass

def get_q_prev(self) -> float:
pass
Loading

0 comments on commit 139cf90

Please sign in to comment.