-
Notifications
You must be signed in to change notification settings - Fork 65
/
pyswisseph.c
6422 lines (5998 loc) · 262 KB
/
pyswisseph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Pyswisseph.
Copyright (c) 2007-2023 Stanislas Marquis <[email protected]>
Pyswisseph is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pyswisseph is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Pyswisseph. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file pyswisseph.c
*
* Python extension to the Swiss Ephemeris
*
* Author/maintainer: Stanislas Marquis <[email protected]>
* Homepage: https://astrorigin.com/pyswisseph
*
* Swisseph authors: Alois Treindl, Dieter Koch (et al.)
* Swisseph homepage: https://www.astro.com/swisseph
*
* Swisseph version: 2.10.03
*/
#define PYSWISSEPH_VERSION 20230604
/* Set the default argument for set_ephe_path function */
#ifndef PYSWE_DEFAULT_EPHE_PATH
#ifdef WIN32
#define PYSWE_DEFAULT_EPHE_PATH "C:\\sweph\\ephe"
#else
#define PYSWE_DEFAULT_EPHE_PATH "/usr/share/swisseph:/usr/local/share/swisseph"
#endif
#endif /* PYSWE_DEFAULT_EPHE_PATH */
/* Wether to automaticly set ephemeris path on module import */
#ifndef PYSWE_AUTO_SET_EPHE_PATH
#define PYSWE_AUTO_SET_EPHE_PATH 1
#endif
/* Wether to build swephelp functions */
#ifndef PYSWE_USE_SWEPHELP
#define PYSWE_USE_SWEPHELP 1
#endif
/* Dont modify below */
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <swephexp.h>
#if PYSWE_USE_SWEPHELP
#include <swephelp.h>
#endif
/* Needed for compilation with Python < 2.4 */
#if PY_MAJOR_VERSION < 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 3)
#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
#define Py_RETURN_TRUE Py_INCREF(Py_True); return Py_True;
#define Py_RETURN_FALSE Py_INCREF(Py_False); return Py_False;
#endif
/* Macros */
#define FUNCARGS_SELF (PyObject *self)
#define FUNCARGS_KEYWDS (PyObject *self, PyObject *args, PyObject *kwds)
#define PyModule_AddFloatConstant(m, nam, d) \
PyModule_AddObject(m, nam, Py_BuildValue("d", d))
/* Helper functions */
/* Take a sequence and extract double
* Return > 0 on error:
* 1 (not a seq)
* 2 (bad seq length)
* 3 (bad item type)
* => must raise TypeError
* Return 4 if an exception is already raised (overflow)
*/
int py_seq2d(PyObject* seq, int len, double* res, char err[128])
{
int i;
PyObject* o;
/* check it is a sequence */
if (!PySequence_Check(seq)) {
memset(err, 0, sizeof(char) * 128);
strncpy(err, "is not a sequence object", 127);
return 1;
}
/* check sequence length */
if (PySequence_Length(seq) < len) {
memset(err, 0, sizeof(char) * 128);
snprintf(err, 127, "is not a sequence of length >= %d", len);
return 2;
}
for (i = 0; i < len; ++i) {
/* check there are numbers */
o = PySequence_ITEM(seq, i);
if (!PyNumber_Check(o)) {
memset(err, 0, sizeof(char) * 128);
snprintf(err, 127, "item %d is not a number", i);
Py_DECREF(o);
return 3;
}
/* extract number */
if (PyFloat_Check(o)) {
res[i] = PyFloat_AsDouble(o);
if (res[i] == -1 && PyErr_Occurred()) {
Py_DECREF(o);
return 4;
}
}
#if PY_MAJOR_VERSION < 3
else if (PyInt_Check(o)) {
res[i] = (double) PyInt_AsLong(o);
if (res[i] == -1 && PyErr_Occurred()) {
Py_DECREF(o);
return 4;
}
}
#endif
else if (PyLong_Check(o)) {
res[i] = PyLong_AsDouble(o);
if (res[i] == -1 && PyErr_Occurred()) {
Py_DECREF(o);
return 4;
}
}
else { /* not an int or a float */
memset(err, 0, sizeof(char) * 128);
snprintf(err, 127, "item %d must be a float or int", i);
Py_DECREF(o);
return 3;
}
Py_DECREF(o);
}
return 0;
}
/* Take pyobject and extract planet id or star name
* Return > 0 on error, raise TypeError invalid body type
*/
int py_obj2plstar(PyObject* body, int* pl, char** star)
{
*pl = 0;
*star = NULL;
if (PyLong_CheckExact(body)) /* long -> planet */
*pl = (int) PyLong_AsLong(body);
#if PY_MAJOR_VERSION >= 3
else if (PyUnicode_CheckExact(body)) /* unicode -> fixed star */
*star = (char*) PyUnicode_AsUTF8(body);
#elif PY_MAJOR_VERSION < 3
else if (PyInt_CheckExact(body)) /* int -> planet */
*pl = (int) PyInt_AsLong(body);
else if (PyString_CheckExact(body)) /* str -> fixed star */
*star = PyString_AsString(body);
#endif
else
return 1;
return 0;
}
/* swisseph.Error (module exception type) */
static PyObject * pyswe_Error;
/* swisseph.azalt */
PyDoc_STRVAR(pyswe_azalt__doc__,
"Calculate horizontal coordinates (azimuth and altitude) of a planet or a star"
" from either ecliptical or equatorial coordinates.\n\n"
":Args: float tjdut, int flag, seq geopos, float atpress, float attemp,"
" seq xin\n\n"
" - tjdut: input time, Julian day number, Universal Time\n"
" - flag: either ECL2HOR (from ecliptical coord) or EQU2HOR (equatorial)\n"
" - geopos: a sequence with:\n"
" - 0: geographic longitude, in degrees (eastern positive)\n"
" - 1: geographic latitude, in degrees (northern positive)\n"
" - 2: geographic altitude, in meters above sea level\n"
" - atpress: atmospheric pressure in mbar (hPa)\n"
" - attemp: atmospheric temperature in degrees Celsius\n"
" - xin: a sequence with:\n"
" - ECL2HOR: ecl. longitude, ecl. latitude, distance\n"
" - EQU2HOR: right ascension, declination, distance\n\n"
":Return: float azimuth, true_altitude, apparent_altitude\n\n"
" - azimuth: position degree, measured from south point to west\n"
" - true_altitude: true altitude above horizon in degrees\n"
" - apparent_altitude: apparent (refracted) altitude above horizon in"
" degrees\n\n"
"The apparent altitude of a body depends on the atmospheric pressure and"
" temperature. If only the true altitude is required, these parameters can be"
" neglected.\n\n"
"If ``atpress`` is given the value 0, the function estimates the pressure from"
" the geographical altitude given in ``xin[3]`` and ``attemp``. If ``xin[3]``"
" is 0, ``atpress`` will be estimated for sea level.");
static PyObject * pyswe_azalt FUNCARGS_KEYWDS
{
double jd, geo[3], xin[3], press, temp, xaz[3];
int i, flag;
PyObject *pygeo, *pyxin;
char err[128] = {0};
static char *kwlist[] = {"tjdut", "flag", "geopos", "atpress", "attemp",
"xin", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "diOddO", kwlist, &jd,
&flag, &pygeo, &press, &temp, &pyxin))
return NULL;
/* extract geopos */
i = py_seq2d(pygeo, 3, geo, err);
if (i > 0)
return i > 3 ? NULL : PyErr_Format(PyExc_TypeError,
"swisseph.azalt: geopos: %s", err);
/* extract xin */
i = py_seq2d(pyxin, 3, xin, err);
if (i > 0)
return i > 3 ? NULL : PyErr_Format(PyExc_TypeError,
"swisseph.azalt: xin: %s", err);
swe_azalt(jd, flag, geo, press, temp, xin, xaz);
return Py_BuildValue("ddd", xaz[0], xaz[1], xaz[2]);
}
/* swisseph.azalt_rev */
PyDoc_STRVAR(pyswe_azalt_rev__doc__,
"Calculate either ecliptical or equatorial coordinates from azimuth and true"
" altitude.\n\n"
":Args: float tjdut, int flag, seq geopos, double azimuth, double"
" true_altitude\n\n"
" - tjdut: input time, Julian day number, Universal Time\n"
" - flag: either HOR2ECL (to ecliptical coord) or HOR2EQU (to equatorial)\n"
" - geopos: a sequence with:\n"
" - 0: geographic longitude, in degrees (eastern positive)\n"
" - 1: geographic latitude, in degrees (northern positive)\n"
" - 2: geographic altitude, in meters above sea level)\n"
" - azimuth: position degree, measured from south point to west\n"
" - true_altitude: true altitude above horizon in degrees\n\n"
":Return: float x1, x2\n\n"
" - x1, x2: ecliptical or equatorial coordinates, depending on flag\n\n"
"This function is not precisely the reverse of ``azalt()``. It computes either"
" ecliptical or equatorial coordinates from azimuth and true altitude. If"
" only an apparent altitude is given, the true altitude has to be computed"
" first with the function ``refrac()``.");
static PyObject * pyswe_azalt_rev FUNCARGS_KEYWDS
{
double jd, geo[3], xin[2], xout[2];
int i, flag;
char err[128] = {0};
PyObject *pygeo;
static char *kwlist[] = {"tjdut", "flag", "geopos", "azimuth",
"true_altitude", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "diOdd", kwlist, &jd,
&flag, &pygeo, &xin[0], &xin[1]))
return NULL;
/* extract geopos */
i = py_seq2d(pygeo, 3, geo, err);
if (i > 0)
return i > 3 ? NULL : PyErr_Format(PyExc_TypeError,
"swisseph.azalt_rev: geopos: %s", err);
swe_azalt_rev(jd, flag, geo, xin, xout);
return Py_BuildValue("dd", xout[0], xout[1]);
}
/* swisseph.calc */
PyDoc_STRVAR(pyswe_calc__doc__,
"Calculate planetary positions (ET).\n\n"
":Args: float tjdet, int planet, int flags=FLG_SWIEPH|FLG_SPEED\n\n"
" - tjdet: Julian day, Ephemeris Time, where tjdet == tjdut + deltat(tjdut)\n"
" - planet: body number\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function can raise swisseph.Error in case of fatal error.");
static PyObject * pyswe_calc FUNCARGS_KEYWDS
{
double jd, xx[6];
int ret, pl, flag = SEFLG_SWIEPH|SEFLG_SPEED;
char err[256] = {0};
static char *kwlist[] = {"tjdet", "planet", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "di|i", kwlist,
&jd, &pl, &flag))
return NULL;
ret = swe_calc(jd, pl, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.calc: %s", err);
return Py_BuildValue("(dddddd)i",xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],ret);
}
/* swisseph.calc_pctr */
PyDoc_STRVAR(pyswe_calc_pctr__doc__,
"Calculate planetocentric positions of planets (ET).\n\n"
":Args: float tjd, int planet, int center, int flags=FLG_SWIEPH|FLG_SPEED\n\n"
" - tjdet: julian day in ET (TT)\n"
" - planet: body number of target object\n"
" - center: body number of center object\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function can raise swisseph.Error in case of fatal error.");
static PyObject * pyswe_calc_pctr FUNCARGS_KEYWDS
{
double jd, xx[6];
int ret, pl, plctr, flag = SEFLG_SWIEPH|SEFLG_SPEED;
char err[256] = {0};
static char* kwlist[] = {"tjdet", "planet", "center", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dii|i", kwlist,
&jd, &pl, &plctr, &flag))
return NULL;
ret = swe_calc_pctr(jd, pl, plctr, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.calc_pctr: %s", err);
return Py_BuildValue("(dddddd)i",xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],ret);
}
/* swisseph.calc_ut */
PyDoc_STRVAR(pyswe_calc_ut__doc__,
"Calculate planetary positions (UT).\n\n"
":Args: float tjdut, int planet, int flags=FLG_SWIEPH|FLG_SPEED\n\n"
" - tjdut: julian day number, universal time\n"
" - planet: body number\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function can raise swisseph.Error in case of fatal error.");
static PyObject * pyswe_calc_ut FUNCARGS_KEYWDS
{
double jd, xx[6];
int ret, pl, flag = SEFLG_SWIEPH|SEFLG_SPEED;
char err[256] = {0};
static char *kwlist[] = {"tjdut", "planet", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "di|i", kwlist,
&jd, &pl, &flag))
return NULL;
ret = swe_calc_ut(jd, pl, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.calc_ut: %s", err);
return Py_BuildValue("(dddddd)i",xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],ret);
}
/* swisseph.close */
PyDoc_STRVAR(pyswe_close__doc__,
"Close Swiss Ephemeris.\n\n"
":Args: --\n"
":Return: None\n\n"
"At the end of your computations you can release all resources (open files and"
" allocated memory) used by the swisseph module.\n\n"
"After ``close()``, no swisseph functions should be used unless you call"
" ``set_ephe_path()`` again and, if required, ``set_jpl_file()``.");
static PyObject * pyswe_close FUNCARGS_SELF
{
swe_close();
Py_RETURN_NONE;
}
/* swisseph.cotrans */
PyDoc_STRVAR(pyswe_cotrans__doc__,
"Coordinate transformation from ecliptic to equator or vice-versa.\n\n"
":Args: seq coord, float eps\n\n"
" - coord: tuple of 3 float for coordinates:\n"
" - 0: longitude\n"
" - 1: latitude\n"
" - 2: distance (unchanged, can be set to 1)\n"
" - eps: obliquity of ecliptic, in degrees\n\n"
":Return: float retlon, retlat, retdist\n\n"
" - retlon: converted longitude\n"
" - retlat: converted latitude\n"
" - retdist: converted distance\n\n"
"For equatorial to ecliptical, obliquity must be positive. From ecliptical to"
" equatorial, obliquity must be negative. Longitude, latitude and obliquity"
" are in positive degrees.");
static PyObject * pyswe_cotrans FUNCARGS_KEYWDS
{
double xpo[3], xpn[3], eps;
PyObject *o;
int i;
char err[128] = {0};
static char *kwlist[] = {"coord", "eps", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Od", kwlist, &o, &eps))
return NULL;
/* extract coord */
i = py_seq2d(o, 3, xpo, err);
if (i > 0)
return i > 3 ? NULL : PyErr_Format(PyExc_TypeError,
"swisseph.cotrans: coord: %s", err);
swe_cotrans(xpo, xpn, eps);
return Py_BuildValue("ddd", xpn[0], xpn[1], xpn[2]);
}
/* swisseph.cotrans_sp */
PyDoc_STRVAR(pyswe_cotrans_sp__doc__,
"Coordinate transformation of position and speed, from ecliptic to equator"
" or vice-versa.\n\n"
":Args: seq coord, float eps\n\n"
" - coord: tuple of 6 float for coordinates:\n"
" - 0: longitude\n"
" - 1: latitude\n"
" - 2: distance\n"
" - 3: longitude speed\n"
" - 4: latitude speed\n"
" - 5: distance speed\n"
" - eps: obliquity of ecliptic, in degrees\n\n"
":Return: float retlon, retlat, retdist, retlonsp, retlatsp, retdistsp\n\n"
" - retlon, retlonsp: converted longitude and its speed\n"
" - retlat, retlatsp: converted latitude and its speed\n"
" - retdist, retdistsp: converted distance and its speed\n\n"
"For equatorial to ecliptical, obliquity must be positive. From ecliptical to"
" equatorial, obliquity must be negative. Longitude, latitude, their speeds"
" and obliquity are in positive degrees.");
static PyObject * pyswe_cotrans_sp FUNCARGS_KEYWDS
{
double xpo[6], xpn[6], eps;
int i;
PyObject *o;
char err[128] = {0};
static char *kwlist[] = {"coord", "eps", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Od", kwlist, &o, &eps))
return NULL;
/* extract coord */
i = py_seq2d(o, 6, xpo, err);
if (i > 0)
return i > 3 ? NULL : PyErr_Format(PyExc_TypeError,
"swisseph.cotrans_sp: coord: %s", err);
swe_cotrans_sp(xpo, xpn, eps);
return Py_BuildValue("dddddd", xpn[0],xpn[1],xpn[2],xpn[3],xpn[4],xpn[5]);
}
/* swisseph.cs2degstr */
PyDoc_STRVAR(pyswe_cs2degstr__doc__,
"Get degrees string from centiseconds.\n\n"
":Args: int cs\n"
":Return: str retstr");
static PyObject * pyswe_cs2degstr FUNCARGS_KEYWDS
{
int cs;
char ret[9];
static char *kwlist[] = {"cs", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &cs))
return NULL;
swe_cs2degstr(cs, ret);
return Py_BuildValue("s", ret);
}
/* swisseph.cs2lonlatstr */
PyDoc_STRVAR(pyswe_cs2lonlatstr__doc__,
"Get longitude or latitude string from centiseconds.\n\n"
":Args: int cs, bytes plus, bytes minus\n"
":Return: str retstr\n\n"
"This function raises TypeError if plus or minus parameter length is not"
" exactly 1 byte.");
static PyObject * pyswe_cs2lonlatstr FUNCARGS_KEYWDS
{
int cs;
char ret[10], plus, minus;
static char *kwlist[] = {"cs", "plus", "minus", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "icc", kwlist,
&cs, &plus, &minus))
return NULL;
swe_cs2lonlatstr(cs, plus, minus, ret);
return Py_BuildValue("s", ret);
}
/* swisseph.cs2timestr */
PyDoc_STRVAR(pyswe_cs2timestr__doc__,
"Get time string from centiseconds.\n\n"
":Args: int cs, bytes sep, bool suppresszero=False\n"
":Return: str retstr\n\n"
"This function raises TypeError if sep parameter length is not exactly 1"
" byte.");
static PyObject * pyswe_cs2timestr FUNCARGS_KEYWDS
{
int cs, sep, suppresszero = 0;
char ret[9];
static char *kwlist[] = {"cs", "sep", "suppresszero", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ic|i", kwlist,
&cs, &sep, &suppresszero))
return NULL;
swe_cs2timestr(cs, sep, suppresszero, ret);
return Py_BuildValue("s", ret);
}
/* swisseph.csnorm */
PyDoc_STRVAR(pyswe_csnorm__doc__,
"Normalization of any centisecond number to the range [0;360].\n\n"
":Args: int cs\n"
":Return: int retcs");
static PyObject * pyswe_csnorm FUNCARGS_KEYWDS
{
int cs;
static char *kwlist[] = {"cs", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &cs))
return NULL;
return Py_BuildValue("i", swe_csnorm(cs));
}
/* swisseph.csroundsec */
PyDoc_STRVAR(pyswe_csroundsec__doc__,
"Round centiseconds, but at 29.5959 always down.\n\n"
":Args: int cs\n"
":Return: int retcs");
static PyObject * pyswe_csroundsec FUNCARGS_KEYWDS
{
int cs;
static char *kwlist[] = {"cs", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &cs))
return NULL;
return Py_BuildValue("i", swe_csroundsec(cs));
}
/* swisseph.d2l */
PyDoc_STRVAR(pyswe_d2l__doc__,
"Double to integer with rounding, no overflow check.\n\n"
":Args: float d\n"
":Return: int i");
static PyObject * pyswe_d2l FUNCARGS_KEYWDS
{
double d;
static char *kwlist[] = {"d", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", kwlist, &d))
return NULL;
return Py_BuildValue("l", swe_d2l(d));
}
/* swisseph.date_conversion */
PyDoc_STRVAR(pyswe_date_conversion__doc__,
"Calculate Julian day number with check wether input date is correct.\n\n"
":Args: int year, int month, int day, float hour=12.0, bytes cal=b'g'\n\n"
" - year, month, day: input date\n"
" - hour: input time, decimal with fraction\n"
" - cal: calendar type, gregorian (b'g') or julian (b'j')\n\n"
":Return: bool isvalid, float jd, (dt)\n\n"
" - isvalid: True if the input date and time are legal\n"
" - jd: returned Julian day number\n"
" - dt: a tuple for, if input was not valid, corrected year, month, day, hour;\n"
" if input was valid, contains input date and time\n\n"
"This function raises TypeError if cal length is not exactly 1 byte.\n"
"It raises ValueError if cal is not b'g' or b'j'.");
static PyObject * pyswe_date_conversion FUNCARGS_KEYWDS
{
int year, month, day, ret, y, m, d;
double jd, hour = 12.0, h;
char cal = 'g';
static char *kwlist[] = {"year", "month", "day", "hour", "cal", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "iii|dc", kwlist,
&year, &month, &day, &hour, &cal))
return NULL;
if (cal != 'g' && cal != 'j')
return PyErr_Format(PyExc_ValueError, "swisseph.date_conversion:"
" invalid calendar b'%c', must be b'g' or b'j'",
cal);
ret = swe_date_conversion(year, month, day, hour, cal, &jd);
if (ret == 0) {
y = year;
m = month;
d = day;
h = hour;
}
else
swe_revjul(jd, cal == 'g' ? SE_GREG_CAL : SE_JUL_CAL, &y, &m, &d, &h);
return Py_BuildValue("Od(iiid)", ret == 0 ? Py_True : Py_False, jd,
y, m, d, h);
}
/* swisseph.day_of_week */
PyDoc_STRVAR(pyswe_day_of_week__doc__,
"Calculate day of week number [0;6] from Julian day number (monday is 0).\n\n"
":Args: float jd\n"
":Return: int dow");
static PyObject * pyswe_day_of_week FUNCARGS_KEYWDS
{
double jd;
static char *kwlist[] = {"jd", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", kwlist, &jd))
return NULL;
return Py_BuildValue("i", swe_day_of_week(jd));
}
/* swisseph.deg_midp */
PyDoc_STRVAR(pyswe_deg_midp__doc__,
"Calculate midpoint (in degrees).\n\n"
":Args: float x1, float x2\n"
":Return: float midp");
static PyObject * pyswe_deg_midp FUNCARGS_KEYWDS
{
double x1, x2;
static char *kwlist[] = {"x1", "x2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwlist, &x1, &x2))
return NULL;
return Py_BuildValue("d", swe_deg_midp(x1, x2));
}
/* swisseph.degnorm */
PyDoc_STRVAR(pyswe_degnorm__doc__,
"Normalization of any degree number to the range [0;360[.\n\n"
":Args: float x\n"
":Return: float xnorm");
static PyObject * pyswe_degnorm FUNCARGS_KEYWDS
{
double x;
static char *kwlist[] = {"x", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", kwlist, &x))
return NULL;
return Py_BuildValue("d", swe_degnorm(x));
}
/* swisseph.deltat */
PyDoc_STRVAR(pyswe_deltat__doc__,
"Calculate value of delta T from Julian day number.\n\n"
":Args: float tjdut\n\n"
"- tjdut: input time, Julian day number, Universal Time\n\n"
":Return: float deltat\n\n"
" - deltat: returned delta T value\n\n"
"Reminder::\n\n"
" tjdet == tjdut + deltat(tjdut)\n\n"
"This function is safe only if your application consistently uses the same"
" ephemeris flags, if your application consistently uses the same ephemeris"
" files, if you first call ``set_ephe_path()`` (with flag ``FLG_SWIEPH``) or"
" ``set_jpl_file()`` (with flag ``FLG_JPLEPH``).\n\n"
"Also, it is safe if you first call ``set_tid_acc()`` with the tidal"
" acceleration you want. However, do not use that function unless you know"
" what you are doing.\n\n"
"For best control of the values returned, use function ``deltat_ex()``"
" instead.\n\n"
"The calculation of ephemerides in UT depends on Delta T, which depends on the"
" ephemeris-inherent value of the tidal acceleration of the Moon. In default"
" mode, the function ``deltat()`` automatically tries to find the required"
" values.\n\n"
"Two warnings must be made, though:\n\n"
" - It is not recommended to use a mix of old and new ephemeris files, because"
" the old files were based on JPL Ephemeris DE406, whereas the new ones are"
" based on DE431, and both ephemerides have a different inherent tidal"
" acceleration of the Moon. A mixture of old and new ephemeris files may lead"
" to inconsistent ephemeris output. Using old asteroid files ``se99999.se1``"
" together with new ones, can be tolerated, though.\n"
" - The function ``deltat()`` uses a default value of tidal acceleration"
" (that of DE431). However, after calling some older ephemeris, like Moshier"
" ephemeris, DE200, or DE406, ``deltat()`` might provide slightly different"
" values.\n\n"
"In case of troubles related to these two points, it is recommended to either"
" use function ``deltat_ex()``, or control the value of the tidal acceleration"
" using the functions ``set_tid_acc()`` and ``get_tid_acc()``.");
static PyObject * pyswe_deltat FUNCARGS_KEYWDS
{
double jd;
static char *kwlist[] = {"tjdut", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", kwlist, &jd))
return NULL;
return Py_BuildValue("d", swe_deltat(jd));
}
/* swisseph.deltat_ex */
PyDoc_STRVAR(pyswe_deltat_ex__doc__,
"Calculate value of Delta T from Julian day number (extended).\n\n"
":Args: float tjdut, int flag\n\n"
" - tjdut: input time, Julian day number, Universal Time\n"
" - flag: ephemeris flag, ``FLG_SWIEPH`` ``FLG_JPLEPH`` ``FLG_MOSEPH``\n\n"
":Return: float deltat\n\n"
" - deltat: returned delta T value\n\n"
"Calling this function without a previous call of ``set_ephe_path()`` or "
" ``set_jpl_file()`` will raise swisseph.Error.\n\n"
"The calculation of ephemerides in UT depends on the ephemeris-inherent value"
" of the tidal acceleration of the Moon. The function ``deltat_ex()`` can"
" provide ephemeris-dependent values of Delta T and is therefore better than"
" the old function ``deltat()``, which has to make un uncertain guess of what"
" ephemeris is being used. One warning must be made, though:\n\n"
"It is not recommended to use a mix of old and new ephemeris files, because the"
" old files were based on JPL Ephemeris DE406, whereas the new ones are based"
" on DE431, and both ephemerides have a different inherent tidal acceleration"
" of the Moon. A mixture of old and new ephemeris files may lead to"
" inconsistent ephemeris output. Using old asteroid files ``se99999.se1``"
" together with new ones, can be tolerated, though.");
static PyObject * pyswe_deltat_ex FUNCARGS_KEYWDS
{
double jd, ret;
int flag;
char err[256] = {0};
static char* kwlist[] = {"tjdut", "flag", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "di", kwlist, &jd, &flag))
return NULL;
ret = swe_deltat_ex(jd, flag, err);
if (err[0] != 0)
return PyErr_Format(pyswe_Error, "swisseph.deltat_ex: %s", err);
return Py_BuildValue("d", ret);
}
/* swisseph.difcs2n */
PyDoc_STRVAR(pyswe_difcs2n__doc__,
"Calculate distance in centisecs p1 - p2 normalized to [-180;180].\n\n"
":Args: int p1, int p2\n"
":Return: int dist");
static PyObject * pyswe_difcs2n FUNCARGS_KEYWDS
{
int p1, p2;
static char *kwlist[] = {"p1", "p2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwlist, &p1, &p2))
return NULL;
return Py_BuildValue("i", swe_difcs2n(p1, p2));
}
/* swisseph.difcsn */
PyDoc_STRVAR(pyswe_difcsn__doc__,
"Calculate distance in centisecs p1 - p2.\n\n"
":Args: int p1, int p2\n"
":Return: int dist");
static PyObject * pyswe_difcsn FUNCARGS_KEYWDS
{
int p1, p2;
static char *kwlist[] = {"p1", "p2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwlist, &p1, &p2))
return NULL;
return Py_BuildValue("i", swe_difcsn(p1, p2));
}
/* swisseph.difdeg2n */
PyDoc_STRVAR(pyswe_difdeg2n__doc__,
"Calculate distance in degrees p1 - p2 normalized to [-180;180].\n\n"
":Args: float p1, float p2\n"
":Return: float dist");
static PyObject * pyswe_difdeg2n FUNCARGS_KEYWDS
{
double p1, p2;
static char *kwlist[] = {"p1", "p2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwlist, &p1, &p2))
return NULL;
return Py_BuildValue("d", swe_difdeg2n(p1, p2));
}
/* swisseph.difdegn */
PyDoc_STRVAR(pyswe_difdegn__doc__,
"Calculate distance in degrees p1 - p2.\n\n"
":Args: float p1, float p2\n"
":Return: float dist");
static PyObject * pyswe_difdegn FUNCARGS_KEYWDS
{
double p1, p2;
static char *kwlist[] = {"p1", "p2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwlist, &p1, &p2))
return NULL;
return Py_BuildValue("d", swe_difdegn(p1, p2));
}
/* swisseph.difrad2n */
PyDoc_STRVAR(pyswe_difrad2n__doc__,
"Calculate distance in radians p1 - p2 normalized to [-180;180].\n\n"
":Args: float p1, float p2\n"
":Return: float dist");
static PyObject * pyswe_difrad2n FUNCARGS_KEYWDS
{
double p1, p2;
static char *kwlist[] = {"p1", "p2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwlist, &p1, &p2))
return NULL;
return Py_BuildValue("d", swe_difrad2n(p1, p2));
}
/* swisseph.fixstar */
PyDoc_STRVAR(pyswe_fixstar__doc__,
"Calculate fixed star positions (ET).\n\n"
":Args: str star, float tjdet, int flags=FLG_SWIEPH\n\n"
" - star: name of fixed star to search for\n"
" - tjdet: input time, Julian day number, Ephemeris Time\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), str stnam, int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - stnam: returned star name\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
double jd, xx[6];
int ret, flag = SEFLG_SWIEPH;
static char *kwlist[] = {"star", "tjdet", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd|i", kwlist,
&star, &jd, &flag))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar(st, jd, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar: %s", err);
return Py_BuildValue("(dddddd)si",
xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],st,ret);
}
/* swisseph.fixstar2 */
PyDoc_STRVAR(pyswe_fixstar2__doc__,
"Calculate fixed star positions (faster version) (ET).\n\n"
":Args: str star, float tjdet, int flags=FLG_SWIEPH\n\n"
" - star: name of fixed star to search for\n"
" - tjdet: input time, Julian day number, Ephemeris Time\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), str stnam, int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - stnam: returned star name\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar2 FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
double jd, xx[6];
int ret, flag = SEFLG_SWIEPH;
static char *kwlist[] = {"star", "tjdet", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd|i", kwlist,
&star, &jd, &flag))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar2(st, jd, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar2: %s", err);
return Py_BuildValue("(dddddd)si",
xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],st,ret);
}
/* swisseph.fixstar2_mag */
PyDoc_STRVAR(pyswe_fixstar2_mag__doc__,
"Get fixed star magnitude (faster version).\n\n"
":Args: str star\n\n"
" - star: name of fixed star\n\n"
":Return: float mag, str stnam\n\n"
" - mag: returned magnitude\n"
" - stnam: returned star name\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar2_mag FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
int ret;
double mag;
static char *kwlist[] = {"star", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &star))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar2_mag(st, &mag, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar2_mag: %s", err);
return Py_BuildValue("ds", mag, st);
}
/* swisseph.fixstar2_ut */
PyDoc_STRVAR(pyswe_fixstar2_ut__doc__,
"Calculate fixed star positions (faster version) (UT).\n\n"
":Args: str star, float tjdut, int flags=FLG_SWIEPH\n\n"
" - star: name of fixed star to search for\n"
" - tjdut: inputtime, Julian day nnumber, Universal Time\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), str stnam, int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - stnam: returned star name\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar2_ut FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
double jd, xx[6];
int ret, flag = SEFLG_SWIEPH;
static char *kwlist[] = {"star", "tjdut", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd|i", kwlist,
&star, &jd, &flag))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar2_ut(st, jd, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar2_ut: %s", err);
return Py_BuildValue("(dddddd)si",
xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],st,ret);
}
/* swisseph.fixstar_mag */
PyDoc_STRVAR(pyswe_fixstar_mag__doc__,
"Get fixed star magnitude.\n\n"
":Args: str star\n\n"
" - star: name of fixed star\n\n"
":Return: float mag, str stnam\n\n"
" - mag: returned magnitude\n"
" - stnam: returned star name\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar_mag FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
int ret;
double mag;
static char *kwlist[] = {"star", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &star))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar_mag(st, &mag, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar_mag: %s", err);
return Py_BuildValue("ds", mag, st);
}
/* swisseph.fixstar_ut */
PyDoc_STRVAR(pyswe_fixstar_ut__doc__,
"Calculate fixed star positions (UT).\n\n"
":Args: str star, float tjdut, int flags=FLG_SWIEPH\n\n"
" - star: name of fixed star to search for\n"
" - tjdut: input time, Julian day number, Universal Time\n"
" - flags: bit flags indicating what kind of computation is wanted\n\n"
":Return: (xx), str stnam, int retflags\n\n"
" - xx: tuple of 6 float for results\n"
" - stnam: returned star name\n"
" - retflags: bit flags indicating what kind of computation was done\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_fixstar_ut FUNCARGS_KEYWDS
{
char *star, st[(SE_MAX_STNAME*2)+1], err[256] = {0};
double jd, xx[6];
int ret, flag = SEFLG_SWIEPH;
static char *kwlist[] = {"star", "tjdut", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd|i", kwlist,
&star, &jd, &flag))
return NULL;
memset(st, 0, (SE_MAX_STNAME*2)+1);
strncpy(st, star, SE_MAX_STNAME*2);
ret = swe_fixstar_ut(st, jd, flag, xx, err);
if (ret < 0)
return PyErr_Format(pyswe_Error, "swisseph.fixstar_ut: %s", err);
return Py_BuildValue("(dddddd)si",
xx[0],xx[1],xx[2],xx[3],xx[4],xx[5],st,ret);
}
/* swisseph.gauquelin_sector */
PyDoc_STRVAR(pyswe_gauquelin_sector__doc__,
"Calculate Gauquelin sector position of a body (UT).\n\n"
":Args: float tjdut, int or str body, int method, seq geopos,"
" float atpress=0, float attemp=0, int flags=FLG_SWIEPH|FLG_TOPOCTR\n\n"
" - tjdut: input time, Julian day number, Universal Time\n"
" - body: planet number (int) or fixed star name (str)\n"
" - method: number indicating which computation method is wanted:\n"
" - 0 with latitude\n"
" - 1 without latitude\n"
" - 2 from rising and setting times of the disc center of planet\n"
" - 3 from rising and setting times of disc center, incl. refraction\n"
" - 4 from rising and setting times of the disk edge of planet\n"
" - 5 from rising and setting times of disk edge, incl. refraction\n"
" - geopos: a sequence containing:\n"
" - 0: geographic longitude, in degrees (eastern positive)\n"
" - 1: geographic latitude, in degrees (northern positive)\n"
" - 2: geographic altitude, in meters above sea level\n"
" - atpress: atmospheric pressure (if 0, the default 1013.25 mbar is used)\n"
" - attemp: atmospheric temperature in degrees Celsius\n"
" - flags: bit flags for ephemeris and FLG_TOPOCTR, etc\n\n"
":Return: float sector\n\n"
" - sector: [1;37[. Gauquelin sectors are numbered in clockwise direction.\n\n"
"This function raises swisseph.Error in case of fatal error.");
static PyObject * pyswe_gauquelin_sector FUNCARGS_KEYWDS
{
double jd, geopos[3], ret, press = 0.0, temp = 0.0;
int i, pl, flag = SEFLG_SWIEPH|SEFLG_TOPOCTR, method;
char *star, st[(SE_MAX_STNAME*2)+1] = {0}, err[256] = {0};
PyObject *body, *seq;
static char *kwlist[] = {"tjdut", "body", "method", "geopos", "atpress",
"attemp", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "dOiO|ddi", kwlist, &jd,
&body, &method, &seq, &press, &temp, &flag))
return NULL;
/* extract pl/star */
i = py_obj2plstar(body, &pl, &star);