Giter Site home page Giter Site logo

sg2's Introduction

Solar Geometry 2

Solar Geometry 2 (SG2) is the second generation of library for computing the relative position of the sun and the earth. Valid over the time period 1980-2100, the algorithm is 20 times faster than the well-know SPA algorithm, with an accuracy order of approx. 0.005°. Reference article: Blanc P. and L. Wald, The SG2 algorithm for a fast and accurate computation of the position of the sun for multi-decadal time period. Solar Energy 88, 3072-3083, 2012, doi: 10.1016/j.solener.2012.07.018.

License

Solar Geometry 2 is released under LGPLv3.

Python binding

Python installation

We provide wheel binary package that can be installed using pip:

pip install sg2

To compile it see README.linux or README.win.

Python usage

see help(sg2)

$ python3
>>> import sg2
>>> help(sg2)

sg2's People

Contributors

gschwind-mines avatar pblanc-mines avatar gschwind avatar

Stargazers

 avatar  avatar Origin Zhang avatar Max avatar  avatar Ryan Wu avatar Mike Song avatar Rodrigo Amaro e Silva avatar xuemei.chen avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

sg2's Issues

ARM64 architecture library for Raspberry pi compute module 4 use

Hello @gschwind

I'm trying to run your python script to get the sun position on a raspberry pi CM4 board as I've succefully done on my windows computer within an ubuntu terminal.
When entering "pip install sg2 -f https://pip.oie-lab.net/python/", it returns as bellow:

$ pip install sg2 -f https://pip.oie-lab.net/python/
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Looking in links: https://pip.oie-lab.net/python/
> ERROR: Could not find a version that satisfies the requirement sg2
ERROR: No matching distribution found for sg2

My current python version is 3.9.2

Raspberry CM4 has an ARM64 architecture processor.
Do you think it's a problem to install and use your binary package ?

If yes, would you be able to publish your binary packages compatibles with ARM64? please

Thank you in advance
Best regards

Pierre C.
IMT Mines Albi

any test case?

After clone the source code, I managed to rebuild the "configure" file used in build-wheel.sh in given docker container by:
autoreconf -fiv

However, the build-wheel.sh failed at:
./configure --with-pic CXXFLAGS="-O3" CFLAGS="-O3"

Why the build-wheel.sh must run directory extracted from "sg2-2.3.0.tar.gz" ?

Can you append test cases on sun_position and sun_rise so that users of SG2 can verify the building process is correct?

sun_position() non-deterministic results

Hey Benoît,

running sg2.sun_position() I found non-deterministic output in its first invocation in a script.

Environment

Ubuntu Linux

$ uname -a
Linux dell 6.5.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 10:22:43 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Python 3.10.12

$ python3 --version
Python 3.10.12

Libraries

$ pip3 freeze
numpy==1.26.4
pandas==2.2.1
python-dateutil==2.9.0.post0
pytz==2024.1
sg2==2.3.1
six==1.16.0
tzdata==2024.1

Bug reproduction

Files:
sg2_bugreport.zip

To reproduce using a virtual environment run python3 -m venv venv and source venv/bin/activate to activate it. Then install the required packages: pip3 install -r sg2_bug_requirements.txt (file attached).

Now run python3 reproduce_sg2_bug.py (file attached) which runs sg2.sun_position() 10 times in a for loop with exactly the same inputs:

--- INPUTS
        geopoints= [[ 16.33157639  48.23785726 249.        ]]
        timestamp= [['2024-04-04T11:00:00']]
        fields= ['geoc.tt', 'topoc.alpha_S', 'topoc.gamma_S0']
--- OUTPUTS
        invoaction geoc.tt topoc.alpha_S topoc.gamma_S0
        0 5029-05-06T19:35:40.896 nan nan
        1 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        2 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        3 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        4 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        5 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        6 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        7 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        8 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526
        9 1970-01-01T00:00:00.000 -19.26934217225915 256.61815818540526

Notice the first invocation result is different from the rest? The timestamp in the first line also keeps changing when running the script repeatedly in the terminal, the values are always nan though.

Also, given the input (time around noon, in Vienna) the elevation and azimuth angles in the invocations after the first one seem wrong to me.

I have no clue what is going on here. Could the be some uninitialized memory?

Fatal error in topocentric_correction_refraction_ZIM

Hello,
There is an error in the topocentric_correction_refraction_ZIM function that prevents it from working correctly.
In that function, tan_gamma_S0 is initialized to 0.0, and then used without assigning the correct value (tan_gamma_S0 = tan(gamma_S0);).
There is also another error in the calculation of gamma_S0_4. It is calculated as gamma_S0_4 = gamma_S0_4 + gamma_S0
when the correct is gamma_S0_4 = gamma_S0_3 + gamma_S0

inline double topocentric_correction_refraction_ZIM(double const gamma_S0, double const P, double const T)
{
	static const double gamma_S0_seuil = -0.010035643198967;
	static const double R = 0.029614018235657;
	/*(tan(gamma_S0_seuil + 0.0031376 / (gamma_S0_seuil+ 0.089186))) */
	double K;
	double tan_gamma_S0 = 0.0; // <= Initialized to 0.0
	double gamma_S0_2 = 0.0, gamma_S0_3 = 0.0, gamma_S0_4 = 0.0;
	unsigned long k;

	K = (P / 1013.0) * (283. / (273. + T)) * 4.848136811095360e-006;

	if (gamma_S0 <= -0.010036) {
		return gamma_S0 + (-20.774 / tan_gamma_S0) * K; // Error: Use tan_gamma_S0 without calculating its value!
	} else if (gamma_S0 <= 0.087266) {
		gamma_S0_2 = gamma_S0 * gamma_S0;
		gamma_S0_3 = gamma_S0_2 * gamma_S0;
		gamma_S0_4 = gamma_S0_4 * gamma_S0; // Error: must be gamma_S0_3 * gamma_S0
		return gamma_S0
				+ (1735 - 2.969067e4 * gamma_S0 + 3.394422e5 * gamma_S0_2
				+ -2.405683e6 * gamma_S0_3 + 7.66231727e6 * gamma_S0_4) * K;
	} else if (gamma_S0 <= 1.483529864195180) {
		return gamma_S0 + K * (58.1 / tan_gamma_S0 - 0.07 / pow(tan_gamma_S0, 3.0) + 0.000086 / pow(tan_gamma_S0, 5.0)); // Error: Use tan_gamma_S0 without calculating its value!
	} else {
		return NAN;
	}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.