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

surface.area is zero when the first 3 vertices of the surface are in one line #384

Closed
VanroyKato opened this issue May 3, 2022 · 19 comments

Comments

@VanroyKato
Copy link

I created a geometry in OpenStudio exported the .idf and wanted to edit some things in python using eppy.

When creating a geometry in OS apparently the floor vertices aren't simplified and if there are multiple zones adjacent to a wall, it will keep all the coordinates, creating situations where there's 3 or more vertices in one line.

This causes a problem when wanting to calculate the surface area. I assume the problem is in the unit_normal function since it takes just the 3 first vertices of the surface, returning 0 when these are in one line.

Example of a surface that caused this problem:

BuildingSurface:Detailed,
Face 161, !- Name
Floor, !- Surface Type
Offices_ZN_1_FLR_1_Floor_Ffactor, !- Construction Name
Offices_ZN_1_FLR_1, !- Zone Name
GroundFCfactorMethod, !- Outside Boundary Condition
, !- Outside Boundary Condition Object
NoSun, !- Sun Exposure
NoWind, !- Wind Exposure
AutoCalculate, !- View Factor to Ground
5, !- Number of Vertices
19, !- Vertex 1 Xcoordinate
0, !- Vertex 1 Ycoordinate
0, !- Vertex 1 Zcoordinate
19, !- Vertex 2 Xcoordinate
9, !- Vertex 2 Ycoordinate
0, !- Vertex 2 Zcoordinate
19, !- Vertex 3 Xcoordinate
16.95, !- Vertex 3 Ycoordinate
0, !- Vertex 3 Zcoordinate
45.02, !- Vertex 4 Xcoordinate
16.95, !- Vertex 4 Ycoordinate
0, !- Vertex 4 Zcoordinate
45.02, !- Vertex 5 Xcoordinate
0, !- Vertex 5 Ycoordinate
0; !- Vertex 5 Zcoordinate

@santoshphilip
Copy link
Owner

You may have identified the problem correctly. Let me see if the code can be updated to fix that issue.

santoshphilip pushed a commit that referenced this issue May 3, 2022
Problem: surface.area (for Building:Surface:Detailed) does not work when first 3 points are linear
Solution: Try the other points. Area will be calculated if any points are non-linear
@santoshphilip
Copy link
Owner

I have fixed this in branch i384_area

Once I cleanup the code, I'll merge it into develop and master branch

Basically I try all the points in the polygon until it hits a non-linear sequence of points. Then it can finish the area calculation. If all points are linear, an area of zero is returned

@santoshphilip
Copy link
Owner

santoshphilip commented May 4, 2022

I have made a new release in pypi and in github.
This issue is resolved

@VanroyKato
Copy link
Author

I updated my eppy version but the bug still seems to be there, the area of surfaces like these still calculates as zero.

I saw in the tests that a case like this was added, so in theory it should be fine right? But even when I use the coordinates of the test case in my code, it also gives me zero. So I'm not sure what's going on.

@santoshphilip
Copy link
Owner

that's unexpected. I'll check.

@santoshphilip santoshphilip reopened this May 26, 2022
@santoshphilip
Copy link
Owner

@VanroyKato , It seems to work on my end. See below.
Not sure why it is not working for you. Can you show me your code ?

idf file a.idf

Version,
    9.1;                      !- Version Identifier

BuildingSurface:Detailed,
    Face 161, !- Name
    Floor, !- Surface Type
    Offices_ZN_1_FLR_1_Floor_Ffactor, !- Construction Name
    Offices_ZN_1_FLR_1, !- Zone Name
    GroundFCfactorMethod, !- Outside Boundary Condition
    , !- Outside Boundary Condition Object
    NoSun, !- Sun Exposure
    NoWind, !- Wind Exposure
    AutoCalculate, !- View Factor to Ground
    5, !- Number of Vertices
    19, !- Vertex 1 Xcoordinate
    0, !- Vertex 1 Ycoordinate
    0, !- Vertex 1 Zcoordinate
    19, !- Vertex 2 Xcoordinate
    9, !- Vertex 2 Ycoordinate
    0, !- Vertex 2 Zcoordinate
    19, !- Vertex 3 Xcoordinate
    16.95, !- Vertex 3 Ycoordinate
    0, !- Vertex 3 Zcoordinate
    45.02, !- Vertex 4 Xcoordinate
    16.95, !- Vertex 4 Ycoordinate
    0, !- Vertex 4 Zcoordinate
    45.02, !- Vertex 5 Xcoordinate
    0, !- Vertex 5 Ycoordinate
    0; !- Vertex 5 Zcoordinate

code:

In [1]: import eppy
In [2]: idf = eppy.openidf('a.idf')
In [3]: surfs = idf.idfobjects['BuildingSurface:Detailed']
In [4]: surf = surfs[0]
In [7]: surf.area
Out[7]: 441.03900000000004

@VanroyKato
Copy link
Author

The first two lines aren't necessarily relevant: I'm just selecting the floor associated to a given construction.

Screenshot 2022-05-26 162752

@santoshphilip
Copy link
Owner

I am mystified.
What is your python version?

@VanroyKato
Copy link
Author

It's 3.8.13

@santoshphilip
Copy link
Owner

OK .. let me try a couple of things

@santoshphilip
Copy link
Owner

Since I can't recreate the error, you will have to help me here.

The code should get to line 58 in eppy/geometry/surface.py
Here it calls function get_an_unit_normal

The function get_an_unit_normal will do the following:
"try all the points in the polygon until it hits a non-linear sequence of points."

It is either not hitting this function OR something is going wrong in the function.

Download the eppy code and put some print statements in eppy/geometry/surface.py to see if you can track down what is going on.

If you are familiar with the python debugger pdb, you can use that without downloading the source code. The debugger has a steep learning cure, so don't use it if you have not done it before. (I prefer using print statements)

@VanroyKato
Copy link
Author

Alright, I'll see if I can find out more!

@VanroyKato
Copy link
Author

So it turns out I'm not even getting to the line where it calls get_an_unit_normal
I suppose because I'm not getting a ZeroDivisionError but instead the RuntimeWarning
`
image

image

@santoshphilip
Copy link
Owner

OK ... I think I see where the problem is coming from.

eppy can run with and without numpy installed.
This may give different exceptions or error messages.

Let me check this out.

@santoshphilip
Copy link
Owner

Yes !!!
if numpy is installed it will give area = 0 (what you have)
without numpy, it will give area = 441.03900000000004

@santoshphilip
Copy link
Owner

I'll work on fixing this.

@santoshphilip
Copy link
Owner

fixed this in issue #386

Problem: surface.area (for Building:Surface:Detailed) does not work when first 3 points are linear and numpy is installed.
Solution: This is because numpy does not throw a ZeroDivisionError but raises a RuntimeWarning. Ensure that a ZeroDivisionError is raised in geometry.surface.unit_normal

@santoshphilip
Copy link
Owner

@VanroyKato ,
thanks for your input. You were able to identify why the issue was occurring. That made it easy for me to fix the problem.

@santoshphilip
Copy link
Owner

released a new version on pypi
new tag on github - this is the latest master

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

No branches or pull requests

2 participants