Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Return default value of fieldvalue when possible #252

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from

Conversation

samuelduchesne
Copy link
Contributor

@santoshphilip, @jamiebull1
Hi guys, completely unrelated to the decorators pull request; I encountered a situation where I needed the default value of a fieldvalue when it is not specified in the IDF file. For example, an OpaqueMaterial that does not have the Solar_Absorptance value defined will return "" instead if the default value set in the IDD for that field (0.7).

I simply added a condition in getattr to check if 'default' is in the fieldidd, and if so to return the value. Since the type of the value is also provided ('real', 'alpha', etc.), I created a simple type_parser that translates the idd-defined type to a Python type (eg.: 'real' => 'float')

The type_parser should probably include all possible types in an IDF file. Don't know how to get the complete list of possibilities. Ideas?

"""parse the fieldvalue type into a python type. eg.: 'real' returns
'float'"""
_type = next(iter(epbunch.getfieldidd(name)['type']), None)
if _type == 'real':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have integer as a type which can be handled here. There are also alpha, which you already handle, and choice and object-list which I'm not sure how (or if) they need handling.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you search an IDD for those last two, it might give you ideas on what we need do with them.

Also, watch out for "AUTOCALCULATE" value which can appear in fields with real (and maybe integer) type. Probably best to add it as a test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled in 7d3ccf4

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't resolved as it doesn't yet handle "AUTOCALCULATE".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand why returning the string "autocalculate" is not ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in fields which are marked as real, so will end up calling float("AUTOCALCULATE") which will raise a ValueError.

eppy/bunch_subclass.py Outdated Show resolved Hide resolved
@jamiebull1
Copy link
Collaborator

I encountered a situation where I needed the default value of a fieldvalue when it is not specified in the IDF file

Sounds like a useful addition to me.

Also, refactors the test_bunch_subclass so that pytest fixtures are used
…not provided, asserting that Do_Zone_Sizing_Calculation will return "No" weather or not defaultvalues=True or False. Although the repr() of the EpBunch still behaves properly and won't print the default values. I think this is the correct behavior.
… empty string

If an empty string is returned, will try to return the default value instead if it exists. This behavior is compatible with the the way EnergyPlus handles missing fields
…ifferent than "eplus"

Now uses glob with a wildcard to catch the first *out.err file
Running these tests locally with env var EPPY_INTEGRATION=1 would throw errors on EnergyPlus' side; it asks for the expandobject subroutine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants