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

Refining Sunpath #32

Merged
merged 4 commits into from
Nov 9, 2017
Merged

Refining Sunpath #32

merged 4 commits into from
Nov 9, 2017

Conversation

devang-chauhan
Copy link
Member

@devang-chauhan devang-chauhan commented Nov 5, 2017

These changes have mainly been directed towards improving the altitude and azimuth calculation. @mostaphaRoudsari This is my first PR for a [+] version. Kindly let me know if I am supposed to provide any other file.

These changes have mainly been directed towards improving the altitude and azimuth calculation.
@mostaphaRoudsari
Copy link
Member

@devngc thank you for the PR! This has been a long-time returning issue.

Do you have some test cases that compares the results of the code against NOAA solar calculator? I can also write the tests but I thought I should ask as you have probably already checked it during the process.

That are some PEP8 issues which I will comment them inside the code. Some of them are repetitive and all of them are easy to fix.

Copy link
Member

@mostaphaRoudsari mostaphaRoudsari left a comment

Choose a reason for hiding this comment

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

@devngc I added a couple of comments to your code. I'm not sure which editor are you using but most of them has their own plugins to check for style issues and there are plugins like autopep8 which will fix most of them for you. Thanks again for the PR. Cheers.


if hourAngle == 0.0 or hourAngle == -180.0 or hourAngle == 180.0:
# Degrees
zenith = math.degrees(math.acos(math.sin(self._latitude)*math.sin(math.radians(solDec))+math.cos(self._latitude)*math.cos(math.radians(solDec))*math.cos(math.radians(hourAngle))))
Copy link
Member

Choose a reason for hiding this comment

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

  1. Add a white space before and after * - / +
  2. Break down the line into smaller segments. We us 89 characters.


# Degrees
if hourAngle>0:
Copy link
Member

Choose a reason for hiding this comment

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

white space before and after >


# Degrees
if hourAngle>0:
azimuth = math.degrees(math.acos(((math.sin(self._latitude)*math.cos(math.raradians(zenith)))-math.sin(math.radians(solDec)))/(math.cos(self._l_latitude)*math.sin(math.radians(zenith)))))+180 % 360
Copy link
Member

Choose a reason for hiding this comment

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

The same here for white-space and the length of the line.


a = 1 if (month < 3) else 0
y = year + 4800 - a
m = month + 12 * a - 3

julianDay = day + math.floor((153 * m + 2) / 5) + 59
def findFractionOf24(hour,minute):
Copy link
Member

Choose a reason for hiding this comment

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

White space is missing after ,

"""
This function calculates the fraction of the 24 hour the provided time represents
1440 is total the number of minutes in a 24 hour cycle.
args
Copy link
Member

Choose a reason for hiding this comment

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

: is missing after args

"""

# Making a list of years from the year 1900
years = [item for item in range(1900, year)]
Copy link
Member

Choose a reason for hiding this comment

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

What about years = range(1900, year)

# Making a list of years from the year 1900
years = [item for item in range(1900, year)]

def is_leap_year(year):
Copy link
Member

Choose a reason for hiding this comment

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

The name of the method should be def isLeapYear

@devang-chauhan
Copy link
Member Author

devang-chauhan commented Nov 6, 2017

Hi @mostaphaRoudsari,
Thank you for comments. I use Atom editor. Will look into these comments. Also, will try to find a package to do this PEP8 checking.

Did you give it a try? Does it work at your end? and Does it produce more accurate altitude and azimuth?

@devang-chauhan
Copy link
Member Author

@mostaphaRoudsari,
I provided a link to GH file, which contains one test with NOAA results. I can document more cases in the code.

@mostaphaRoudsari
Copy link
Member

Didn't check the GH file. Will do later today after my class. If you're using Atom then here are the packages that I use which includes autopep8:

2017-10-31
2017-10-31
2017-10-31
2017-10-31

@devang-chauhan
Copy link
Member Author

@mostaphaRoudsari,
Thank you for sharing your list of packages. I installed them. Unfortunately, they crash at my end. I will keep looking for possible solutions.


if hourAngle == 0.0 or hourAngle == -180.0 or hourAngle == 180.0:
# Degrees
zenith = math.degrees(math.acos \
Copy link
Member

Choose a reason for hiding this comment

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

This is not major but you don't need \ inside parentheses.

@@ -683,3 +756,21 @@ def __repr__(self):
self.sunVector.y,
self.sunVector.z
)


# Following are test cases to compare altitude and azimuth values with NOAA calculator
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding these cases. They either need to be written as a proper test cases or at least we should make sure that they won't be execute on import. To achieve that you can use if __name__ == '__main__:. If you don't know the concept watch this video.

Once you add the if statement I can merge this. I will change them to proper test cases afterwards and you can follow that as an example for later.

Thanks again for all the great work @devngc!

I managed to run those packages eventuallly. So this file is checked for PEP8 for issues.

Now, speaking of test cases, the main() is not there in the file. Do you want me to create that function and put all the code inside it. I throught I may invite changes in other files that depend on this one so I thought I would ask first. Also, this will again raise line length related PEP8 issues.

For the time being, I commented out the test cases.

Pleaase let me know if I should put everything inside a main().

Also, In order to run this file to check everythng, I need to write
import __init__ as ladybug
or else it throws import errror. Just sharing. This is may be a gap in my understanding about the way core and [+] libraries are paired.
@devang-chauhan
Copy link
Member Author

I managed to run those packages eventually. So this file is checked for PEP8 for issues.

Now, speaking of test cases, the main() is not there in the file. Do you want me to create that function and put all the code inside it? I thought it may invite changes in other files that depend on this one so I thought I would ask first. Also, this will again raise line length related PEP8 issues.

For the time being, I commented out the test cases.

Please let me know if I should put everything in a main().

Also, In order to run this file to check everything, I need to write
import __init__ as ladybug
or else it throws import error. Just sharing. This is maybe a gap in my understanding of the way core and [+] libraries are paired.

@devang-chauhan
Copy link
Member Author

devang-chauhan commented Nov 7, 2017

noaacompare

@devang-chauhan devang-chauhan self-assigned this Nov 8, 2017
@mostaphaRoudsari
Copy link
Member

@devngc it all looks good. I'm going to merge this now and move your test cases to test folder later. Once we have that we can set-up call and discuss some of the details here and there. Great job overall!

@mostaphaRoudsari mostaphaRoudsari merged commit 7d9bbcc into ladybug-tools:master Nov 9, 2017
@devang-chauhan
Copy link
Member Author

@mostaphaRoudsari,
Thank you! Sure, it would be my pleasure to speak with you.

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.

None yet

2 participants