Merge remote-tracking branch 'origin/master'

This commit is contained in:
pilar 2020-06-09 11:34:19 -04:00
commit eea722d16d
14 changed files with 366 additions and 42 deletions

129
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,129 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
guillermo.gutierrezmorote@concordia.ca.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

88
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,88 @@
# Contributing guidelines
## Push Request Checklist
Before sending your pull requests, make sure you followed this list.
- Read [contributing guidelines](CONTRIBUTING.md).
- Read [Code of Conduct](CODE_OF_CONDUCT.md).
- Check if my changes are consistent with the [guidelines](CONTRIBUTING.md#user-content-general-guidelines-and-philosophy-for-contribution).
- Changes are consistent with the [Coding Style](CONTRIBUTING.md#user-content-coding-style).
- Manually test your code and add [Unit Tests](CONTRIBUTING.md#user-content-testing-best-practices).
- [Document your work](CONTRIBUTING.md#user-content-documentation).
## How to become a contributor and submit your own code
### Contributor License Agreements
CERC Libs is an [LGPL licensed](LICENSE.md) software, so even if we'd love to accept your patches, Before we can take them, please be sure that you are the intellectual property owner of your code and that do you fully understand and respect our software license.
***NOTE***: Only source code that you own will go into the main repository.
### Contributing code
If you have improvements to CERC Libs or want to extend the functionality, please send us your pull request as seen at [git pull request documentation](https://git-scm.com/docs/git-request-pull)
Once the pull requests are approved and pass continuous integration checks, a team member will merge your changes on CERC Libs, and your code will become an integral part of Insel4D platform.
If you prefer to contribute, instead of adding new functionality, you can also take a look at our ticket system and try to fix any of the listed issues.
### Contribution guidelines and standards
Before sending your pull request for review, make sure your changes are consistent with the guidelines, and follow the CERC Libs coding style.
#### General guidelines and philosophy for contribution
* Include unit tests when you contribute new features, as they help to:
* Prove that your code works correctly.
* Guard against future breaking changes to lower the maintenance cost.
* Bug fixes also generally require unit tests, because the presence of bugs usually indicates insufficient test coverage.
* Keep backward compatibility in mind when you change code in CERC Libs, and if you need to broke the backward compatibility, please ensure that you:
* Clearly indicate which features are affected by your changes.
* Technical reasons for the changes.
* Tests should follow the
[testing best practices](CONTRIBUTING.md#user-content-testing-best-practices)
guide.
* [Document your contribution](CONTRIBUTING.md#user-content-documentation)
#### License
Include a small header with contact information and the code license at the top of any new file like in the following example.
"""
Name module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author name mail@concordia.ca
"""
#### Coding style
Changes to CERC Libs python code should conform to our coding style [Cerc Python Style Guide](PYGUIDE.md)
As a general basis, all contributions need to be focused on the concept of code clarity and use pylint to check your Python changes.
To install pylint and check your files against Cerc custom style definition:
To install `pylint` and check a file
with `pylint` against Cerc custom style definition:
```bash
pip install pylint
pylint --rcfile=pylintrc myfile.py
```
#### Testing best practices
Before any pull request, the code must been manually and automatically tested to ensure at least some quality minimum. There are a few practices for unit tests that we believe are important, so we encourage you to follow it.
* The test should be self-contained, which implies that your tests will prepare and clean up everything before and after the test execution.
* We encourage you to create if possible functional tests that cover the complete workflow of the implemented functionality.
* Maximize your code coverage by ensuring that you are testing as much of your code as possible.
#### Documentation
In case of new functionality, a general overview, configuration, installation, and user manuals need to be provided by the developer; this will provide an excellent starting point for all the future users and help you detect any inconsistencies in your design.

View File

22
PYGUIDE.md Normal file
View File

@ -0,0 +1,22 @@
# Cerc Python Style Guide
## What's coding style and why it matters
Coding style is just how the code looks, it's incredibly personal, and everyone has their style.
Your preferred architectures, variable and function naming style all of then impacts in your code style and how the others read and understand it, so it could become a significant burden if everyone is coding on his own.
At CERC we are following the [PEP8](https://www.python.org/dev/peps/pep-0008/) with two spaces indentation instead of four.
## Tools.
We use [PyCharm](https://www.jetbrains.com/pycharm/) as an integrated development environment and follow the tool's overall advice but the space indentation, which we set to two spaces instead of default four spaces.
For code analysis, we enforce the usage of [pylint](https://www.pylint.org/) with our own [custom style definition](pylintrc)
## Naming convention
* Name your folders and files in lowercase.
* Your class names must start in capital letters and follow the python CapWords pattern.
* Methods and properties that return lists must end in "s".
* Constants names must be all capitals.
* Avoid the usage of "get_" and "set_" methods whenever possible, by using @property and @variable.setter decorators instead.

View File

@ -1,8 +1,19 @@
# libs
Libs is a generic repository containing the following classes
Libs is part of Insel4D architecture for the urban simulations, created by the CERC group at Concordia University.
Libs repository contains a set of classes modeling the data for urban environments in the form of:
* city_model_structure
* geometry
* physics
* usage
* usages
Released under [LGPL license](LICENSE.md), will provide an object-oriented, modular approach to urban simulations.
Our aims are:
* involve as many scientists and contributors as possible
* provide a complete set of classes that help scientists and students to model urban environments.
Please check the [contributing information](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md) if you want to contribute, and let us know any new feature you may be of interest for you or your team.

View File

@ -1,11 +1,22 @@
from city_model_structure.city_object import CityObject
"""
City module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
import sys
from typing import List, Union
import pyproj
from pyproj import Transformer
import reverse_geocoder as rg
from city_model_structure.city_object import CityObject
class City:
"""
City class
"""
def __init__(self, lower_corner, upper_corner, srs_name, city_objects=None):
self._city_objects = None
self._name = None
@ -16,16 +27,14 @@ class City:
# todo: right now extracted at city level, in the future should be extracted also at building level if exist
self._location = None
@property
def location(self):
def _get_location(self):
if self._location is None:
gps = pyproj.CRS('EPSG:4326') # LatLon with WGS84 datum used by GPS units and Google Earth
input_reference = None
try:
input_reference = pyproj.CRS(self.srs_name) # Projected coordinate system from input data
except pyproj.exceptions.CRSError:
print('Invalid projection reference system, please check the input data. (e.g. in CityGML files: srs_name)')
quit()
sys.exit()
transformer = Transformer.from_crs(input_reference, gps)
coordinates = transformer.transform(self.lower_corner[0], self.lower_corner[1])
self._location = rg.search(coordinates)
@ -33,33 +42,63 @@ class City:
@property
def country_code(self):
return self.location[0]['cc']
"""
City country code
:return: str
"""
return self._get_location()[0]['cc']
@property
def name(self):
"""
City name
:return: str
"""
if self._name is None:
self._name = self.location[0]['name']
self._name = self._get_location()[0]['name']
return self._name
@property
def city_objects(self) -> Union[List[CityObject], None]:
"""
CityObjects belonging to the city
:return: None or a list of CityObjects
"""
return self._city_objects
@property
def lower_corner(self):
"""
City lower corner
:return: [x,y,z]
"""
return self._lower_corner
@property
def upper_corner(self):
"""
City upper corner
:return: [x,y,z]
"""
return self._upper_corner
def city_object(self, name) -> Union[CityObject, None]:
for c in self.city_objects:
if c.name == name:
return c
"""
Retrieve the city CityObject with the given name
:param name:str
:return: None or CityObject
"""
for city_object in self.city_objects:
if city_object.name == name:
return city_object
return None
def add_city_object(self, new_city_object):
"""
Add a CityObject to the city
:param new_city_object:CityObject
:return: None
"""
if self._city_objects is None:
self._city_objects = []
for city_object in self.city_objects:
@ -70,8 +109,17 @@ class City:
@property
def srs_name(self):
"""
srs name
:return: str
"""
return self._srs_name
@name.setter
def name(self, value):
"""
Set the city name
:param value:
:return: None
"""
self._name = value

View File

@ -1,7 +1,7 @@
from city_model_structure.thermal_opening import ThermalOpening
from city_model_structure.surface import Surface
from city_model_structure.thermal_zone import ThermalZone
from city_model_structure.layer import Layer
import helpers.assumptions as assumptions
from helpers.configuration import Configuration
from typing import List
@ -21,7 +21,7 @@ class ThermalBoundary:
self._shortwave_reflectance = None
@property
def delimits(self) -> List[Surface]:
def delimits(self) -> List[ThermalZone]:
return self._delimits
@property
@ -108,8 +108,8 @@ class ThermalBoundary:
@property
def u_value(self):
if self._u_value is None:
h_i = assumptions.h_i
h_e = assumptions.h_e
h_i = Configuration().h_i
h_e = Configuration().h_e
r_value = 1.0/h_i + 1.0/h_e
try:
for layer in self.layers:

View File

@ -1,26 +1,17 @@
import helpers.assumptions as assumptions
from helpers.configuration import Configuration
class ThermalOpening:
def __init__(self):
self._area = None
self._openable_ratio = None
self._conductivity_w_mk = None
self._frame_ratio = assumptions.frame_ratio
self._frame_ratio = Configuration().frame_ratio
self._g_value = None
self._thickness_m = None
self._inside_reflectance = None
self._outside_reflectance = None
self._u_value = None
@property
def area(self):
return self._area
@area.setter
def area(self, value):
self._area = value
@property
def openable_ratio(self):
raise Exception('Not implemented')
@ -81,8 +72,8 @@ class ThermalOpening:
def u_value(self):
if self._u_value is None:
try:
h_i = assumptions.h_i
h_e = assumptions.h_e
h_i = Configuration().h_i
h_e = Configuration().h_e
r_value = 1 / h_i + 1 / h_e + float(self.conductivity_w_mk) / float(self.thickness_m)
self._u_value = 1 / r_value
except TypeError:

7
config/configuration.ini Normal file
View File

@ -0,0 +1,7 @@
# These values are intended as configurable assumptions
[convective_fluxes]
h_i = 10 # W/m2K
h_e = 25 # W/m2K
[windows]
frame_ratio = 0

View File

@ -1,9 +0,0 @@
# These values are intended as configurable assumptions
# ToDo: these values need to be changed into configurable parameters
# convective fluxes
h_i = 10 # W/m2K
h_e = 25 # W/m2K
# windows' default values
frame_ratio = 0

22
helpers/configuration.py Normal file
View File

@ -0,0 +1,22 @@
import configparser
from pathlib import Path
class Configuration:
def __init__(self):
base_path = Path().resolve().parent
config_file = Path(base_path / 'config/configuration.ini').resolve()
self._config = configparser.ConfigParser()
self._config.read(config_file)
@property
def h_i(self):
return self._config.getfloat('convective_fluxes', 'h_i')
@property
def h_e(self):
return self._config.getfloat('convective_fluxes', 'h_e')
@property
def frame_ratio(self):
return self._config.getint('windows', 'frame_ratio')

View File

@ -75,7 +75,6 @@ class UsBasePhysicsParameters:
if construction['window'] is None:
continue
w_lib = self.search_construction_type('window', construction['window'])
opening.area = '0.0'
opening.conductivity_w_mk = w_lib['conductivity']['#text']
opening.frame_ratio = w_lib['frame_ratio']['#text']
opening.g_value = w_lib['solar_transmittance_at_normal_incidence']['#text']

View File

@ -27,7 +27,6 @@ class TestGeometryFactory(TestCase):
self.assertIsNotNone(city.upper_corner, 'upper_corner is none')
self.assertIsNotNone(city.name, 'name is none')
self.assertIsNotNone(city.country_code, 'country code is none')
self.assertIsNotNone(city.location, 'location is none')
def test_citygml_city_objects(self):
city = self.get_citygml()

View File

@ -24,4 +24,21 @@ class TestPhysicsFactory(TestCase):
return self._nyc_with_physics
def test_city_with_physics(self):
city = self.get_city_with_physics()
city = self.get_city_with_physics()
for city_object in city.city_objects:
self.assertIsNotNone(city_object.average_storey_height, 'average_storey_height is none')
self.assertIsNotNone(city_object.storeys_above_ground, 'storeys_above_ground is none')
for thermal_zone in city_object.thermal_zones:
self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'effective_thermal_capacity is none')
self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value,
'additional_thermal_bridge_u_value is none')
self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio, 'indirectly_heated_area_ratio is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'infiltration_rate_system_on is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_off, 'infiltration_rate_system_off is none')
self.assertIsNotNone(thermal_zone.bounded, 'bounded is none')
for thermal_boundary in thermal_zone.bounded:
self.assertIsNotNone(thermal_boundary.outside_solar_absorptance, 'outside_solar_absorptance is none')
self.assertIsNotNone(thermal_boundary.outside_thermal_absorptance, 'outside_thermal_absorptance is none')
self.assertIsNotNone(thermal_boundary.outside_visible_absorptance, 'outside_visible_absorptance is none')
self.assertIsNotNone(thermal_boundary.window_ratio, 'window_ratio is none')
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')