From b8b0ef7392ae33e83464fb38a19713a87508eb00 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 14:13:11 -0700 Subject: [PATCH 01/11] oldest-supported-numpy gets confused with numpy 2 so remove it --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3e2e8e4..b765fab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "oldest-supported-numpy", + "numpy", "cython", "setuptools", "setuptools-scm>=8.0" From bf72b396015bbafd9b6498e5a1ce87da950717e4 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 14:37:38 -0700 Subject: [PATCH 02/11] Run black on setup.py --- setup.py | 438 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 349 insertions(+), 89 deletions(-) diff --git a/setup.py b/setup.py index 807a507..7af3845 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ - import os import numpy import re @@ -19,79 +18,344 @@ erfa_c = ( - "a2af.c", "a2tf.c", "ab.c", "ae2hd.c", "af2a.c", "anp.c", - "anpm.c", "apcg.c", "apcg13.c", "apci.c", "apci13.c", - "apco.c", "apco13.c", "apcs.c", "apcs13.c", "aper.c", - "aper13.c", "apio.c", "apio13.c", "atcc13.c", "atccq.c", - "atci13.c", "atciq.c", "atciqn.c", "atciqz.c", "atco13.c", - "atic13.c", "aticq.c", "aticqn.c", "atio13.c", "atioq.c", - "atoc13.c", "atoi13.c", "atoiq.c", "bi00.c", "bp00.c", - "bp06.c", "bpn2xy.c", "c2i00a.c", "c2i00b.c", "c2i06a.c", - "c2ibpn.c", "c2ixy.c", "c2ixys.c", "c2s.c", "c2t00a.c", - "c2t00b.c", "c2t06a.c", "c2tcio.c", "c2teqx.c", "c2tpe.c", - "c2txy.c", "cal2jd.c", "cp.c", "cpv.c", "cr.c", "d2dtf.c", - "d2tf.c", "dat.c", "dtdb.c", "dtf2d.c", "eceq06.c", - "ecm06.c", "ee00.c", "ee00a.c", "ee00b.c", "ee06a.c", - "eect00.c", "eform.c", "eo06a.c", "eors.c", "epb.c", - "epb2jd.c", "epj.c", "epj2jd.c", "epv00.c", "eqec06.c", - "eqeq94.c", "era00.c", "erfadatextra.c", - "fad03.c", "fae03.c", "faf03.c", "faju03.c", "fal03.c", - "falp03.c", "fama03.c", "fame03.c", "fane03.c", "faom03.c", - "fapa03.c", "fasa03.c", "faur03.c", "fave03.c", "fk425.c", - "fk45z.c", "fk524.c", "fk52h.c", "fk54z.c", "fk5hip.c", - "fk5hz.c", "fw2m.c", "fw2xy.c", "g2icrs.c", "gc2gd.c", - "gc2gde.c", "gd2gc.c", "gd2gce.c", "gmst00.c", "gmst06.c", - "gmst82.c", "gst00a.c", "gst00b.c", "gst06.c", "gst06a.c", - "gst94.c", "h2fk5.c", "hd2ae.c", "hd2pa.c", "hfk5z.c", - "icrs2g.c", "ir.c", "jd2cal.c", "jdcalf.c", "ld.c", "ldn.c", - "ldsun.c", "lteceq.c", "ltecm.c", "lteqec.c", "ltp.c", - "ltpb.c", "ltpecl.c", "ltpequ.c", "moon98.c", "num00a.c", - "num00b.c", "num06a.c", "numat.c", "nut00a.c", "nut00b.c", - "nut06a.c", "nut80.c", "nutm80.c", "obl06.c", "obl80.c", - "p06e.c", "p2pv.c", "p2s.c", "pap.c", "pas.c", "pb06.c", - "pdp.c", "pfw06.c", "plan94.c", "pm.c", "pmat00.c", - "pmat06.c", "pmat76.c", "pmp.c", "pmpx.c", "pmsafe.c", - "pn.c", "pn00.c", "pn00a.c", "pn00b.c", "pn06.c", "pn06a.c", - "pnm00a.c", "pnm00b.c", "pnm06a.c", "pnm80.c", "pom00.c", - "ppp.c", "ppsp.c", "pr00.c", "prec76.c", "pv2p.c", "pv2s.c", - "pvdpv.c", "pvm.c", "pvmpv.c", "pvppv.c", "pvstar.c", - "pvtob.c", "pvu.c", "pvup.c", "pvxpv.c", "pxp.c", "refco.c", - "rm2v.c", "rv2m.c", "rx.c", "rxp.c", "rxpv.c", "rxr.c", - "ry.c", "rz.c", "s00.c", "s00a.c", "s00b.c", "s06.c", - "s06a.c", "s2c.c", "s2p.c", "s2pv.c", "s2xpv.c", "sepp.c", - "seps.c", "sp00.c", "starpm.c", "starpv.c", "sxp.c", - "sxpv.c", "taitt.c", - "taiut1.c", "taiutc.c", "tcbtdb.c", "tcgtt.c", "tdbtcb.c", - "tdbtt.c", "tf2a.c", "tf2d.c", "tpors.c", "tporv.c", - "tpsts.c", "tpstv.c", "tpxes.c", "tpxev.c", "tr.c", - "trxp.c", "trxpv.c", "tttai.c", "tttcg.c", "tttdb.c", - "ttut1.c", "ut1tai.c", "ut1tt.c", "ut1utc.c", "utctai.c", - "utcut1.c", "xy06.c", "xys00a.c", "xys00b.c", "xys06a.c", - "zp.c", "zpv.c", "zr.c", + "a2af.c", + "a2tf.c", + "ab.c", + "ae2hd.c", + "af2a.c", + "anp.c", + "anpm.c", + "apcg.c", + "apcg13.c", + "apci.c", + "apci13.c", + "apco.c", + "apco13.c", + "apcs.c", + "apcs13.c", + "aper.c", + "aper13.c", + "apio.c", + "apio13.c", + "atcc13.c", + "atccq.c", + "atci13.c", + "atciq.c", + "atciqn.c", + "atciqz.c", + "atco13.c", + "atic13.c", + "aticq.c", + "aticqn.c", + "atio13.c", + "atioq.c", + "atoc13.c", + "atoi13.c", + "atoiq.c", + "bi00.c", + "bp00.c", + "bp06.c", + "bpn2xy.c", + "c2i00a.c", + "c2i00b.c", + "c2i06a.c", + "c2ibpn.c", + "c2ixy.c", + "c2ixys.c", + "c2s.c", + "c2t00a.c", + "c2t00b.c", + "c2t06a.c", + "c2tcio.c", + "c2teqx.c", + "c2tpe.c", + "c2txy.c", + "cal2jd.c", + "cp.c", + "cpv.c", + "cr.c", + "d2dtf.c", + "d2tf.c", + "dat.c", + "dtdb.c", + "dtf2d.c", + "eceq06.c", + "ecm06.c", + "ee00.c", + "ee00a.c", + "ee00b.c", + "ee06a.c", + "eect00.c", + "eform.c", + "eo06a.c", + "eors.c", + "epb.c", + "epb2jd.c", + "epj.c", + "epj2jd.c", + "epv00.c", + "eqec06.c", + "eqeq94.c", + "era00.c", + "erfadatextra.c", + "fad03.c", + "fae03.c", + "faf03.c", + "faju03.c", + "fal03.c", + "falp03.c", + "fama03.c", + "fame03.c", + "fane03.c", + "faom03.c", + "fapa03.c", + "fasa03.c", + "faur03.c", + "fave03.c", + "fk425.c", + "fk45z.c", + "fk524.c", + "fk52h.c", + "fk54z.c", + "fk5hip.c", + "fk5hz.c", + "fw2m.c", + "fw2xy.c", + "g2icrs.c", + "gc2gd.c", + "gc2gde.c", + "gd2gc.c", + "gd2gce.c", + "gmst00.c", + "gmst06.c", + "gmst82.c", + "gst00a.c", + "gst00b.c", + "gst06.c", + "gst06a.c", + "gst94.c", + "h2fk5.c", + "hd2ae.c", + "hd2pa.c", + "hfk5z.c", + "icrs2g.c", + "ir.c", + "jd2cal.c", + "jdcalf.c", + "ld.c", + "ldn.c", + "ldsun.c", + "lteceq.c", + "ltecm.c", + "lteqec.c", + "ltp.c", + "ltpb.c", + "ltpecl.c", + "ltpequ.c", + "moon98.c", + "num00a.c", + "num00b.c", + "num06a.c", + "numat.c", + "nut00a.c", + "nut00b.c", + "nut06a.c", + "nut80.c", + "nutm80.c", + "obl06.c", + "obl80.c", + "p06e.c", + "p2pv.c", + "p2s.c", + "pap.c", + "pas.c", + "pb06.c", + "pdp.c", + "pfw06.c", + "plan94.c", + "pm.c", + "pmat00.c", + "pmat06.c", + "pmat76.c", + "pmp.c", + "pmpx.c", + "pmsafe.c", + "pn.c", + "pn00.c", + "pn00a.c", + "pn00b.c", + "pn06.c", + "pn06a.c", + "pnm00a.c", + "pnm00b.c", + "pnm06a.c", + "pnm80.c", + "pom00.c", + "ppp.c", + "ppsp.c", + "pr00.c", + "prec76.c", + "pv2p.c", + "pv2s.c", + "pvdpv.c", + "pvm.c", + "pvmpv.c", + "pvppv.c", + "pvstar.c", + "pvtob.c", + "pvu.c", + "pvup.c", + "pvxpv.c", + "pxp.c", + "refco.c", + "rm2v.c", + "rv2m.c", + "rx.c", + "rxp.c", + "rxpv.c", + "rxr.c", + "ry.c", + "rz.c", + "s00.c", + "s00a.c", + "s00b.c", + "s06.c", + "s06a.c", + "s2c.c", + "s2p.c", + "s2pv.c", + "s2xpv.c", + "sepp.c", + "seps.c", + "sp00.c", + "starpm.c", + "starpv.c", + "sxp.c", + "sxpv.c", + "taitt.c", + "taiut1.c", + "taiutc.c", + "tcbtdb.c", + "tcgtt.c", + "tdbtcb.c", + "tdbtt.c", + "tf2a.c", + "tf2d.c", + "tpors.c", + "tporv.c", + "tpsts.c", + "tpstv.c", + "tpxes.c", + "tpxev.c", + "tr.c", + "trxp.c", + "trxpv.c", + "tttai.c", + "tttcg.c", + "tttdb.c", + "ttut1.c", + "ut1tai.c", + "ut1tt.c", + "ut1utc.c", + "utctai.c", + "utcut1.c", + "xy06.c", + "xys00a.c", + "xys00b.c", + "xys06a.c", + "zp.c", + "zpv.c", + "zr.c", ) pal_c = ( - "pal1Atms.c", "pal1Atmt.c", "palAddet.c", "palAirmas.c", - "palAltaz.c", "palAmp.c", "palAmpqk.c", "palAop.c", "palAoppa.c", - "palAoppat.c", "palAopqk.c", "palAtmdsp.c", "palCaldj.c", - "palDafin.c", "palDat.c", "palDe2h.c", "palDeuler.c", - "palDfltin.c", "palDh2e.c", "palDjcal.c", "palDmat.c", - "palDmoon.c", "palDrange.c", "palDs2tp.c", "palDt.c", - "palDtp2s.c", "palDtps2c.c", "palDtt.c", "palEcleq.c", "palEcmat.c", - "palEl2ue.c", "palEpco.c", "palEpv.c", "palEqecl.c", - "palEqgal.c", "palEtrms.c", "palEvp.c", "palFk45z.c", - "palFk524.c", "palFk54z.c", "palGaleq.c", "palGalsup.c", - "palGe50.c", "palGeoc.c", "palIntin.c", "palMap.c", - "palMappa.c", "palMapqk.c", "palMapqkz.c", "palNut.c", - "palNutc.c", "palOap.c", "palOapqk.c", "palObs.c", - "palOne2One.c", "palPa.c", "palPcd.c", "palPertel.c", "palPertue.c", - "palPlanel.c", "palPlanet.c", "palPlante.c", "palPlantu.c", - "palPm.c", "palPolmo.c", "palPrebn.c", "palPrec.c", "palPreces.c", - "palPrenut.c", "palPv2el.c", "palPv2ue.c", "palPvobs.c", - "palRdplan.c", "palRefco.c", "palRefro.c", "palRefv.c", - "palRefz.c", "palRverot.c", "palRvgalc.c", "palRvlg.c", - "palRvlsrd.c", "palRvlsrk.c", "palSubet.c", "palSupgal.c", - "palUe2el.c", "palUe2pv.c", "palUnpcd.c" + "pal1Atms.c", + "pal1Atmt.c", + "palAddet.c", + "palAirmas.c", + "palAltaz.c", + "palAmp.c", + "palAmpqk.c", + "palAop.c", + "palAoppa.c", + "palAoppat.c", + "palAopqk.c", + "palAtmdsp.c", + "palCaldj.c", + "palDafin.c", + "palDat.c", + "palDe2h.c", + "palDeuler.c", + "palDfltin.c", + "palDh2e.c", + "palDjcal.c", + "palDmat.c", + "palDmoon.c", + "palDrange.c", + "palDs2tp.c", + "palDt.c", + "palDtp2s.c", + "palDtps2c.c", + "palDtt.c", + "palEcleq.c", + "palEcmat.c", + "palEl2ue.c", + "palEpco.c", + "palEpv.c", + "palEqecl.c", + "palEqgal.c", + "palEtrms.c", + "palEvp.c", + "palFk45z.c", + "palFk524.c", + "palFk54z.c", + "palGaleq.c", + "palGalsup.c", + "palGe50.c", + "palGeoc.c", + "palIntin.c", + "palMap.c", + "palMappa.c", + "palMapqk.c", + "palMapqkz.c", + "palNut.c", + "palNutc.c", + "palOap.c", + "palOapqk.c", + "palObs.c", + "palOne2One.c", + "palPa.c", + "palPcd.c", + "palPertel.c", + "palPertue.c", + "palPlanel.c", + "palPlanet.c", + "palPlante.c", + "palPlantu.c", + "palPm.c", + "palPolmo.c", + "palPrebn.c", + "palPrec.c", + "palPreces.c", + "palPrenut.c", + "palPv2el.c", + "palPv2ue.c", + "palPvobs.c", + "palRdplan.c", + "palRefco.c", + "palRefro.c", + "palRefv.c", + "palRefz.c", + "palRverot.c", + "palRvgalc.c", + "palRvlg.c", + "palRvlsrd.c", + "palRvlsrk.c", + "palSubet.c", + "palSupgal.c", + "palUe2el.c", + "palUe2pv.c", + "palUnpcd.c", ) # Build up source file list @@ -99,12 +363,12 @@ # Sort out path to the C files for cfile in erfa_c: - sources.append(os.path.join('cextern', 'erfa', 'src', cfile)) + sources.append(os.path.join("cextern", "erfa", "src", cfile)) # Also read in prologues palprologs = {} for cfile in pal_c: - palfile = os.path.join('cextern', 'pal', cfile) + palfile = os.path.join("cextern", "pal", cfile) sources.append(palfile) prologs = sst.read_prologs(palfile) palprologs.update(prologs) @@ -116,14 +380,13 @@ infile = "pal.pyx.in" outfile = "pal.pyx" create_outfile = True -if os.path.exists(outfile) and \ - os.path.getmtime(infile) < os.path.getmtime(outfile): +if os.path.exists(outfile) and os.path.getmtime(infile) < os.path.getmtime(outfile): create_outfile = False if create_outfile: paldoc_re = re.compile(r"@(pal.*)@") outfh = codecs.open(outfile, "w", "utf8") - with codecs.open(infile, 'r', 'utf8') as file: + with codecs.open(infile, "r", "utf8") as file: for line in file.readlines(): match_paldoc = paldoc_re.search(line) if match_paldoc is not None: @@ -132,20 +395,18 @@ palpyname = funcname[3:].lower() if funcname in palprologs: info = palprologs[funcname] - lines.append(info['purpose']) - lines += ("Arguments", "---------", info['arguments']) + lines.append(info["purpose"]) + lines += ("Arguments", "---------", info["arguments"]) if "returned value" in info: - lines += ("", "Returned Value", "--------------", - info['returned value']) + lines += ("", "Returned Value", "--------------", info["returned value"]) if "notes" in info: - lines += ("", "Notes", "-----", - info['notes']) + lines += ("", "Notes", "-----", info["notes"]) line = "\n".join(lines) else: continue elif line.count("@"): if line.count("@VERSTRING@"): - line = line.replace("@VERSTRING@", '"'+verstring+'"') + line = line.replace("@VERSTRING@", '"' + verstring + '"') if line.count("@MAJOR_VERSION"): line = line.replace("@MAJOR_VERSION@", str(major)) if line.count("@MINOR_VERSION@"): @@ -153,19 +414,18 @@ if line.count("@PATCH_VERSION@"): line = line.replace("@PATCH_VERSION@", str(patch)) if line.count("@PALPY_VERSION@"): - line = line.replace("@PALPY_VERSION@", '"'+palpy_version+'"') + line = line.replace("@PALPY_VERSION@", '"' + palpy_version + '"') outfh.write(line) outfh.close() # Description -with open('README.rst') as file: +with open("README.rst") as file: long_description = file.read() -extensions = [Extension("palpy", sources, - include_dirs=['cextern/erfa/src', - 'cextern/pal', - numpy.get_include()])] +extensions = [ + Extension("palpy", sources, include_dirs=["cextern/erfa/src", "cextern/pal", numpy.get_include()]) +] setup( ext_modules=cythonize(extensions), From 3d7c14de0ebac80a5b84dd45478a0caeb4e47cdb Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 14:25:17 -0700 Subject: [PATCH 03/11] Use np.nan instead of np.NaN --- pal.pyx.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pal.pyx.in b/pal.pyx.in index 7614bb3..932957e 100644 --- a/pal.pyx.in +++ b/pal.pyx.in @@ -427,7 +427,7 @@ def caldjVector(np.ndarray[long, ndim=1] iy not None, if flag == 0: mjd_out[ii] = mjd else: - mjd_out[ii] = np.NaN + mjd_out[ii] = np.nan return mjd_out @@ -654,7 +654,7 @@ def daf2rVector(np.ndarray[long, ndim=1] ideg_in not None, if flag==0: ang_out[i] = rad else: - ang_out[i] = np.NaN + ang_out[i] = np.nan return ang_out @@ -1442,8 +1442,8 @@ def ds2tpVector( np.ndarray[double, ndim=1] ra not None, xiout[i] = xi etaout[i] = eta else: - xiout[i] = np.NaN - etaout[i] = np.NaN + xiout[i] = np.nan + etaout[i] = np.nan return xiout, etaout @@ -1633,7 +1633,7 @@ def dtf2dVector( np.ndarray[long, ndim=1] ihour not None, if flag==0: days[ii] = value else: - days[ii] = np.NaN + days[ii] = np.nan return days @@ -1700,7 +1700,7 @@ def dtf2rVector(np.ndarray[long, ndim=1] ihour, np.ndarray[long, ndim=1] imin, if flag==0: radians[ii] = value else: - radians[ii] = np.NaN + radians[ii] = np.nan return radians From e8418ec6c0b6821a62c5ed0e741e70802ede5290 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 14:37:27 -0700 Subject: [PATCH 04/11] Use modern np rng APIs --- test_pal.py | 376 ++++++++++++++++++++++++++-------------------------- 1 file changed, 188 insertions(+), 188 deletions(-) diff --git a/test_pal.py b/test_pal.py index cd682ca..a29480a 100644 --- a/test_pal.py +++ b/test_pal.py @@ -69,9 +69,9 @@ def test_airmass_vector(self): """ Test that airmassVector gives results consistent with airmass """ - np.random.seed(145) + rng = np.random.default_rng(145) n_samples = 1000 - zd = np.random.random_sample(n_samples) * 0.5 * np.pi + zd = rng.random(n_samples) * 0.5 * np.pi test_am = pal.airmasVector(zd) for ii in range(n_samples): control_am = pal.airmas(zd[ii]) @@ -91,10 +91,10 @@ def test_altaz(self): self.assertAlmostEqual(padd, -0.2957914128185515, 13) def test_altaz_vector(self): - np.random.seed(32) + rng = np.random.default_rng(32) phi = 0.5 - ha_in = np.random.sample(20) * 2.0 * np.pi - dec_in = (np.random.sample(20) - 0.5) * np.pi + ha_in = rng.random(20) * 2.0 * np.pi + dec_in = (rng.random(20) - 0.5) * np.pi az_c = np.zeros(20, dtype=np.float64) azd_c = np.zeros(20, dtype=np.float64) azdd_c = np.zeros(20, dtype=np.float64) @@ -150,11 +150,11 @@ def test_ampqk_vector(self): """ Test that ampqkVector produces results consistent with ampqk """ - np.random.seed(144) + rng = np.random.default_rng(144) n_samples = 200 amprms = pal.mappa(2010.0, 55927.0) - ra_in = np.random.random_sample(n_samples) * 2.0 * np.pi - dec_in = (np.random.random_sample(n_samples) - 0.5) * np.pi + ra_in = rng.random(n_samples) * 2.0 * np.pi + dec_in = (rng.random(n_samples) - 0.5) * np.pi testRa, testDec = pal.ampqkVector(ra_in, dec_in, amprms) @@ -189,16 +189,16 @@ def test_aopqk_vector(self): tlr = 0.006 wl = 0.45 obsrms = pal.aoppa(date, dut, elongm, phim, hm, xp, yp, tdk, pmb, rh, wl, tlr) - np.random.seed(32) + rng = np.random.default_rng(32) n_tests = 100 - ra_in = np.random.sample(n_tests) * 2.0 * np.pi - dec_in = (np.random.sample(n_tests) - 0.5) * np.pi + ra_in = rng.random(n_tests) * 2.0 * np.pi + dec_in = (rng.random(n_tests) - 0.5) * np.pi az_control = None ze_control = None ha_control = None d_control = None r_control = None - for (rr, dd) in zip(ra_in, dec_in): + for rr, dd in zip(ra_in, dec_in): az, ze, ha, d, r = pal.aopqk(rr, dd, obsrms) if az_control is None: az_control = np.array([az]) @@ -214,7 +214,7 @@ def test_aopqk_vector(self): r_control = np.append(r_control, r) azTest, zeTest, haTest, dTest, rTest = pal.aopqkVector(ra_in, dec_in, obsrms) - for (a1, z1, h1, d1, r1, a2, z2, h2, d2, r2) in zip( + for a1, z1, h1, d1, r1, a2, z2, h2, d2, r2 in zip( az_control, ze_control, ha_control, d_control, r_control, azTest, zeTest, haTest, dTest, rTest ): @@ -354,10 +354,10 @@ def test_oapqk_vector(self): wl = 0.45 aoprms = pal.aoppa(date, dut, elongm, phim, hm, xp, yp, tdk, pmb, rh, wl, tlr) - np.random.seed(133) + rng = np.random.default_rng(133) n_samples = 200 - ob1 = np.random.random_sample(n_samples) * 2.0 * np.pi - ob2 = np.random.random_sample(n_samples) * 0.5 * np.pi + ob1 = rng.random(n_samples) * 2.0 * np.pi + ob2 = rng.random(n_samples) * 0.5 * np.pi # restrict ob2 to 0 < ob2 < pi/2 because we will also be testing az-zenith distance # coordinate pairs @@ -377,8 +377,8 @@ def test_oapqk_vector(self): # the actual maximum zenith distance to be 74.1 degrees). raApCenter, decApCenter = pal.oapqk("h", 0.0, 0.0, aoprms) - rr = np.random.random_sample(n_samples) * np.radians(50.0) - theta = np.random.random_sample(n_samples) * 2.0 * np.pi + rr = rng.random(n_samples) * np.radians(50.0) + theta = rng.random(n_samples) * 2.0 * np.pi ra_ap_list = raApCenter + rr * np.cos(theta) dec_ap_list = decApCenter + rr * np.sin(theta) @@ -416,12 +416,12 @@ def test_dbear_vector(self): Test that dbearVector gives the same results as dbear """ - np.random.seed(122) + rng = np.random.default_rng(122) n_samples = 100 - a1_in = np.random.random_sample(n_samples) * 2.0 * np.pi - b1_in = (np.random.random_sample(n_samples) - 0.5) * np.pi - a2_in = np.random.random_sample(n_samples) * 2.0 * np.pi - b2_in = (np.random.random_sample(n_samples) - 0.5) * np.pi + a1_in = rng.random(n_samples) * 2.0 * np.pi + b1_in = (rng.random(n_samples) - 0.5) * np.pi + a2_in = rng.random(n_samples) * 2.0 * np.pi + b2_in = (rng.random(n_samples) - 0.5) * np.pi # test case where a2, b2 have the same number of elements # as a1, b1 @@ -448,17 +448,17 @@ def test_dpav_vector(self): """ Test that dpavVector is consistent with dpav """ - np.random.seed(127) + rng = np.random.default_rng(127) n_samples = 200 - phi = np.random.random_sample(n_samples) * 2.0 * np.pi - theta = (np.random.random_sample(n_samples) - 0.5) * np.pi + phi = rng.random(n_samples) * 2.0 * np.pi + theta = (rng.random(n_samples) - 0.5) * np.pi v1 = np.array( [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)] ) - phi = np.random.random_sample(n_samples) * 2.0 * np.pi - theta = (np.random.random_sample(n_samples) - 0.5) * np.pi + phi = rng.random(n_samples) * 2.0 * np.pi + theta = (rng.random(n_samples) - 0.5) * np.pi v2 = np.array( [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)] @@ -480,12 +480,12 @@ def test_dpav_vector(self): # test that exceptions are raised when they should be self.assertRaises(ValueError, pal.dpavVector, v1, v2[:19]) - v3 = np.random.random_sample((n_samples, 6)) + v3 = rng.random((n_samples, 6)) self.assertRaises(ValueError, pal.dpavVector, v3, v2) self.assertRaises(ValueError, pal.dpavVector, v1, v3) - self.assertRaises(ValueError, pal.dpavVector, v1, np.random.random_sample(9)) + self.assertRaises(ValueError, pal.dpavVector, v1, rng.random(9)) def test_caldj(self): djm = pal.caldj(1999, 12, 31) @@ -499,11 +499,11 @@ def test_caldj_vector(self): """ Test that caldjVector gives results consistent with cadj """ - np.random.seed(143) + rng = np.random.default_rng(143) n_samples = 200 - iy = np.random.randint(1000, 10001, n_samples) - im = np.random.randint(1, 12, n_samples) - iday = np.random.randint(1, 21, n_samples) + iy = rng.integers(1000, 10001, n_samples) + im = rng.integers(1, 12, n_samples) + iday = rng.integers(1, 21, n_samples) test_mjd = pal.caldjVector(iy, im, iday) @@ -546,11 +546,11 @@ def test_daf2r_vector(self): """ Test that daf2rVector returns the same results as daf2r """ - np.random.seed(123) + rng = np.random.default_rng(123) n_samples = 100 - deg = np.random.randint(0, 360, n_samples) - i_min = np.random.randint(0, 60, n_samples) - asec = np.random.random_sample(n_samples) * 60.0 + deg = rng.integers(0, 360, n_samples) + i_min = rng.integers(0, 60, n_samples) + asec = rng.random(n_samples) * 60.0 radian_test = pal.daf2rVector(deg, i_min, asec) for ii in range(len(deg)): @@ -578,8 +578,8 @@ def test_dcc2s_vector(self): """ Test that dcc2sVector returns the same results as dcc2s """ - np.random.seed(124) - input_data = np.random.random_sample((20, 3)) * 10.0 + rng = np.random.default_rng(124) + input_data = rng.random((20, 3)) * 10.0 aTest, b_test = pal.dcc2sVector(input_data) for ix in range(input_data.shape[0]): aControl, b_control = pal.dcc2s(input_data[ix]) @@ -588,17 +588,17 @@ def test_dcc2s_vector(self): # test that an exception is raised if you don't pass in # 3-D cartesian points - dummy_data = np.random.random_sample((20, 5)) * 10.0 + dummy_data = rng.random((20, 5)) * 10.0 self.assertRaises(ValueError, pal.dcc2sVector, dummy_data) def test_dcs2c_vector(self): """ Test that dcs2cVector returns the same results as dcs2c """ - np.random.seed(125) + rng = np.random.default_rng(125) n_samples = 100 - ra = np.random.random_sample(n_samples) * 2.0 * np.pi - dec = (np.random.random_sample(n_samples) - 0.5) * np.pi + ra = rng.random(n_samples) * 2.0 * np.pi + dec = (rng.random(n_samples) - 0.5) * np.pi v_test = pal.dcs2cVector(ra, dec) for ii in range(n_samples): v_control = pal.dcs2c(ra[ii], dec[ii]) @@ -626,9 +626,9 @@ def test_dd2tf_vector(self): """ Test that dd2tfVector gives the same results as dd2tf """ - np.random.seed(126) + rng = np.random.default_rng(126) n_samples = 100 - days_list = (np.random.sample(n_samples) - 0.5) * 1200.0 + days_list = (rng.random(n_samples) - 0.5) * 1200.0 for ndp in [2, 3, 4, 5]: testSign, testIh, testIm, testIs, testFrac = pal.dd2tfVector(ndp, days_list) @@ -660,9 +660,9 @@ def test_dr2af_vector(self): Test that dr2afVector produces the same results as dr2af """ - np.random.seed(128) + rng = np.random.default_rng(128) n_samples = 200 - angle_list = (np.random.random_sample(n_samples) - 0.5) * 4.0 * np.pi + angle_list = (rng.random(n_samples) - 0.5) * 4.0 * np.pi for npd in [2, 3, 4, 5]: testSign, testDeg, testMin, testSec, testFrac = pal.dr2afVector(npd, angle_list) @@ -688,9 +688,9 @@ def test_dr2tf_vector(self): Test that dr2tfVector produces the same results as dr2tf """ - np.random.seed(128) + rng = np.random.default_rng(128) n_samples = 200 - angle_list = (np.random.random_sample(n_samples) - 0.5) * 4.0 * np.pi + angle_list = (rng.random(n_samples) - 0.5) * 4.0 * np.pi for npd in [2, 3, 4, 5]: testSign, testHr, testMin, testSec, testFrac = pal.dr2tfVector(npd, angle_list) @@ -715,11 +715,11 @@ def test_dtf2d_vector(self): Test that dtf2dVector gives results consistent with dtf2d """ - np.random.seed(131) + rng = np.random.default_rng(131) n_samples = 100 - i_hour = np.random.randint(0, 24, n_samples) - i_min = np.random.randint(0, 60, n_samples) - sec = np.random.random_sample(n_samples) * 60.0 + i_hour = rng.integers(0, 24, n_samples) + i_min = rng.integers(0, 60, n_samples) + sec = rng.random(n_samples) * 60.0 test_days = pal.dtf2dVector(i_hour, i_min, sec) for ii in range(n_samples): @@ -758,11 +758,11 @@ def test_dtf2r_vector(self): Test that dtf2rVector gives results consistent with dtf2r """ - np.random.seed(131) + rng = np.random.default_rng(131) n_samples = 100 - i_hour = np.random.randint(0, 24, n_samples) - i_min = np.random.randint(0, 60, n_samples) - sec = np.random.random_sample(n_samples) * 60.0 + i_hour = rng.integers(0, 24, n_samples) + i_min = rng.integers(0, 60, n_samples) + sec = rng.random(n_samples) * 60.0 test_rad = pal.dtf2rVector(i_hour, i_min, sec) for ii in range(n_samples): @@ -814,9 +814,9 @@ def test_djcal_vector(self): """ Test that djcalVector returns results consistent with djcal """ - np.random.seed(142) + rng = np.random.default_rng(142) n_samples = 200 - mjd = (np.random.random_sample(n_samples) - 0.5) * 100000.0 + mjd = (rng.random(n_samples) - 0.5) * 100000.0 for ndp in [2, 3, 4, 5]: @@ -882,12 +882,12 @@ def test_e2h(self): def test_de2h_vector(self): n_tests = 100 phi = 0.35 - np.random.seed(32) - ha_in = np.random.random_sample(n_tests) * np.pi * 2.0 - dec_in = (np.random.random_sample(n_tests) - 0.5) * np.pi + rng = np.random.default_rng(32) + ha_in = rng.random(n_tests) * np.pi * 2.0 + dec_in = (rng.random(n_tests) - 0.5) * np.pi az_control = None el_control = None - for (ha, dd) in zip(ha_in, dec_in): + for ha, dd in zip(ha_in, dec_in): az, el = pal.de2h(ha, dd, phi) if az_control is None: az_control = np.array([az]) @@ -897,7 +897,7 @@ def test_de2h_vector(self): el_control = np.append(el_control, el) azTest, elTest = pal.de2hVector(ha_in, dec_in, phi) - for (a1, e1, a2, e2) in zip(az_control, el_control, azTest, elTest): + for a1, e1, a2, e2 in zip(az_control, el_control, azTest, elTest): self.assertAlmostEqual(a1, a2, 12) self.assertAlmostEqual(e1, e2, 12) @@ -909,11 +909,11 @@ def test_dh2e_vector(self): """ Test that dh2eVector gives results consistent with dh2e """ - np.random.seed(142) + rng = np.random.default_rng(142) n_samples = 200 phi = 1.432 - az = np.random.random_sample(n_samples) * 2.0 * np.pi - el = (np.random.random_sample(n_samples) - 0.5) * np.pi + az = rng.random(n_samples) * 2.0 * np.pi + el = (rng.random(n_samples) - 0.5) * np.pi testHa, testDec = pal.dh2eVector(az, el, phi) @@ -945,10 +945,10 @@ def test_ecleq_vector(self): ecleq """ mjd = 58734.2 - np.random.seed(138) + rng = np.random.default_rng(138) n_samples = 200 - dl = np.random.random_sample(n_samples) * 2.0 * np.pi - db = (np.random.random_sample(n_samples) - 0.5) * np.pi + dl = rng.random(n_samples) * 2.0 * np.pi + db = (rng.random(n_samples) - 0.5) * np.pi testRa, testDec = pal.ecleqVector(dl, db, mjd) @@ -998,9 +998,9 @@ def test_epj_vector(self): """ Test that epjVector returns results consistent with epj """ - np.random.seed(45738) + rng = np.random.default_rng(45738) n_samples = 300 - date = 43000.0 + np.random.random_sample(n_samples) * 10000.0 + date = 43000.0 + rng.random(n_samples) * 10000.0 test_epj = pal.epjVector(date) for ii in range(n_samples): control_epj = pal.epj(date[ii]) @@ -1014,9 +1014,9 @@ def test_epj2d_vector(self): """ Test that epj2dVector returns results consistent with epj """ - np.random.seed(45367) + rng = np.random.default_rng(45367) n_samples = 300 - epj = 2000.0 + np.random.random_sample(n_samples) * 50.0 + epj = 2000.0 + rng.random(n_samples) * 50.0 test_mjd = pal.epj2dVector(epj) for ii in range(n_samples): control_mjd = pal.epj2d(epj[ii]) @@ -1034,10 +1034,10 @@ def test_eqecl_vector(self): eqecl """ mjd = 53000.0 - np.random.seed(137) + rng = np.random.default_rng(137) n_samples = 200 - ra = np.random.random_sample(n_samples) * 2.0 * np.pi - dec = (np.random.random_sample(n_samples) - 0.5) * np.pi + ra = rng.random(n_samples) * 2.0 * np.pi + dec = (rng.random(n_samples) - 0.5) * np.pi testDb, testDl = pal.eqeclVector(ra, dec, mjd) for ii in range(n_samples): @@ -1053,8 +1053,8 @@ def test_eqeqx(self): self.assertAlmostEqual(pal.eqeqx(53736), -0.8834195072043790156e-5, 15) def test_eqeqx_vector(self): - np.random.seed(32) - date_in = 53000.0 + np.random.sample(20) * 5000.0 + rng = np.random.default_rng(32) + date_in = 53000.0 + rng.random(20) * 5000.0 eq_control = np.zeros(20, dtype=np.float64) for i, d in enumerate(date_in): eq_control[i] = pal.eqeqx(d) @@ -1068,12 +1068,12 @@ def test_eqgal(self): self.assertAlmostEqual(db, -0.6800521449061520, 12) def test_eqgal_vector(self): - np.random.seed(32) - ra_in = np.random.sample(10) * 2.0 * np.pi - dec_in = (np.random.sample(10) - 0.5) * np.pi + rng = np.random.default_rng(32) + ra_in = rng.random(10) * 2.0 * np.pi + dec_in = (rng.random(10) - 0.5) * np.pi dl_control = None db_control = None - for (ra, dec) in zip(ra_in, dec_in): + for ra, dec in zip(ra_in, dec_in): dl, db = pal.eqgal(ra, dec) if dl_control is None: dl_control = np.array([dl]) @@ -1082,7 +1082,7 @@ def test_eqgal_vector(self): np.append(dl_control, dl) np.append(db_control, db) dlTest, db_test = pal.eqgalVector(ra_in, dec_in) - for (dlt, dbt, dlc, dbc) in zip(dlTest, db_test, dl_control, db_control): + for dlt, dbt, dlc, dbc in zip(dlTest, db_test, dl_control, db_control): self.assertAlmostEqual(dlt, dlc, 12) self.assertAlmostEqual(dbt, dbc, 12) @@ -1235,14 +1235,14 @@ def test_fk524_vectors(self): Test that fk524Vector returns results consistent with fk524 """ - np.random.seed(135) + rng = np.random.default_rng(135) n_samples = 200 - ra5 = np.random.random_sample(n_samples) * 2.0 * np.pi - dec5 = (np.random.random_sample(n_samples) - 0.5) * np.pi - mura5 = 0.01 * (np.random.random_sample(n_samples) - 0.5) * 200.0 * np.radians(1.0 / 3600.0) - mudec5 = 0.01 * (np.random.random_sample(n_samples) - 0.5) * 200.0 * np.radians(1.0 / 3600.0) - px5 = np.random.random_sample(n_samples) - vr5 = (np.random.random_sample(n_samples) - 0.5) * 200.0 + ra5 = rng.random(n_samples) * 2.0 * np.pi + dec5 = (rng.random(n_samples) - 0.5) * np.pi + mura5 = 0.01 * (rng.random(n_samples) - 0.5) * 200.0 * np.radians(1.0 / 3600.0) + mudec5 = 0.01 * (rng.random(n_samples) - 0.5) * 200.0 * np.radians(1.0 / 3600.0) + px5 = rng.random(n_samples) + vr5 = (rng.random(n_samples) - 0.5) * 200.0 testRa, testDec, testMura, testMudec, testPx, testVr = pal.fk524Vector( ra5, dec5, mura5, mudec5, px5, vr5 @@ -1291,10 +1291,10 @@ def test_fk45z_vector(self): Test that fk45zVector produces results consistent with fk45z """ epoch = 1960 - np.random.seed(136) + rng = np.random.default_rng(136) n_samples = 200 - r1950 = np.random.random_sample(n_samples) * 2.0 * np.pi - d1950 = (np.random.random_sample(n_samples) - 0.5) * np.pi + r1950 = rng.random(n_samples) * 2.0 * np.pi + d1950 = (rng.random(n_samples) - 0.5) * np.pi testR2000, testD2000 = pal.fk45zVector(r1950, d1950, epoch) @@ -1331,10 +1331,10 @@ def test_fk5hz_vector(self): Test that fk5hzVector returns results consistent with fk5hz """ - np.random.seed(132) + rng = np.random.default_rng(132) n_samples = 200 - ra_list = np.random.random_sample(n_samples) * 2.0 * np.pi - dec_list = (np.random.random_sample(n_samples) - 0.5) * np.pi + ra_list = rng.random(n_samples) * 2.0 * np.pi + dec_list = (rng.random(n_samples) - 0.5) * np.pi testRa, testDec = pal.fk5hzVector(ra_list, dec_list, 2000.0) for ii in range(n_samples): @@ -1351,10 +1351,10 @@ def test_hkf5z_vector(self): Test that hkf5zVector produces results consistent with hkf5z """ - np.random.seed(133) + rng = np.random.default_rng(133) n_samples = 200 - ra_list = np.random.random_sample(n_samples) * 2.0 * np.pi - dec_list = (np.random.random_sample(n_samples) - 0.5) * np.pi + ra_list = rng.random(n_samples) * 2.0 * np.pi + dec_list = (rng.random(n_samples) - 0.5) * np.pi testRa, testDec, testDr, testDd = pal.hfk5zVector(ra_list, dec_list, 2000.0) for ii in range(n_samples): controlRa, controlDec, controlDr, controlDd = pal.hfk5z(ra_list[ii], dec_list[ii], 2000.0) @@ -1384,10 +1384,10 @@ def test_fk54z_vector(self): Test that fk54zVector returns results consistent with fk54z """ epoch = 1960 - np.random.seed(136) + rng = np.random.default_rng(136) n_samples = 200 - r2000 = np.random.random_sample(n_samples) * 2.0 * np.pi - d2000 = (np.random.random_sample(n_samples) - 0.5) * np.pi + r2000 = rng.random(n_samples) * 2.0 * np.pi + d2000 = (rng.random(n_samples) - 0.5) * np.pi testR1950, testD1950, testDr1950, testDd1950 = pal.fk54zVector(r2000, d2000, epoch) for ii in range(n_samples): @@ -1411,17 +1411,17 @@ def test_galeq(self): self.assertAlmostEqual(dd, -0.7834003666745548, 12) def test_galeq_vector(self): - np.random.seed(32) - dl_in = np.random.sample(10) * 2.0 * np.pi - db_in = (np.random.sample(10) - 0.5) * np.pi + rng = np.random.default_rng(32) + dl_in = rng.random(10) * 2.0 * np.pi + db_in = (rng.random(10) - 0.5) * np.pi dr_control = np.zeros(10, dtype=np.float64) dd_control = np.zeros(10, dtype=np.float64) - for (i, cc) in enumerate(zip(dl_in, db_in)): + for i, cc in enumerate(zip(dl_in, db_in)): dr, dd = pal.galeq(cc[0], cc[1]) dr_control[i] = dr dd_control[i] = dd drTest, dd_test = pal.galeqVector(dl_in, db_in) - for (drt, ddt, drc, ddc) in zip(drTest, dd_test, dr_control, dd_control): + for drt, ddt, drc, ddc in zip(drTest, dd_test, dr_control, dd_control): self.assertAlmostEqual(drt, drc, 12) self.assertAlmostEqual(ddt, ddc, 12) @@ -1438,11 +1438,11 @@ def test_galsup_vector(self): """ Test that galsupVector gives results consistent with galsup """ - np.random.seed(134) + rng = np.random.default_rng(134) n_samples = 200 - ll_list = np.random.random_sample(n_samples) * 2.0 * np.pi - bb_list = (np.random.random_sample(n_samples) - 0.5) * np.pi + ll_list = rng.random(n_samples) * 2.0 * np.pi + bb_list = (rng.random(n_samples) - 0.5) * np.pi testSl, testSb = pal.galsupVector(ll_list, bb_list) @@ -1471,10 +1471,10 @@ def test_ge50_vector(self): """ Test that ge50Vector returns results consistent with ge50 """ - np.random.seed(133) + rng = np.random.default_rng(133) n_samples = 200 - ll_list = np.random.random_sample(n_samples) * 2.0 * np.pi - bb_list = (np.random.random_sample(n_samples) - 0.5) * np.pi + ll_list = rng.random(n_samples) * 2.0 * np.pi + bb_list = (rng.random(n_samples) - 0.5) * np.pi testRa, testDec = pal.ge50Vector(ll_list, bb_list) for ii in range(n_samples): controlRa, controlDec = pal.ge50(ll_list[ii], bb_list[ii]) @@ -1490,8 +1490,8 @@ def test_gmst(self): self.assertAlmostEqual(pal.gmsta(53736, 0), 1.754174971870091203, 12) def test_gmst_vector(self): - np.random.seed(32) - date_in = 53000.0 + np.random.sample(20) * 5000.0 + rng = np.random.default_rng(32) + date_in = 53000.0 + rng.random(20) * 5000.0 gm_control = np.zeros(20, dtype=np.float64) for i, d in enumerate(date_in): gm = pal.gmst(d) @@ -1501,9 +1501,9 @@ def test_gmst_vector(self): self.assertAlmostEqual(gt, gc, 12) def test_gmsta_vector(self): - np.random.seed(32) - date_in = 53000 + np.random.randint(0, 1001, 20) - ut_in = np.random.sample(20) + rng = np.random.default_rng(32) + date_in = 53000 + rng.integers(0, 1001, 20) + ut_in = rng.random(20) gm_control = np.zeros(20, dtype=np.float64) for i, d in enumerate(zip(date_in, ut_in)): dd = pal.gmsta(d[0], d[1]) @@ -1632,13 +1632,13 @@ def test_mapqkz(self): def test_mapqkz_vector(self): amprms = pal.mappa(2010, 55927) - np.random.seed(32) + rng = np.random.default_rng(32) n_tests = 100 - ra_in = np.random.sample(n_tests) * 2.0 * np.pi - dec_in = (np.random.sample(n_tests) - 0.5) * np.pi + ra_in = rng.random(n_tests) * 2.0 * np.pi + dec_in = (rng.random(n_tests) - 0.5) * np.pi r_control = None d_control = None - for (rr, dd) in zip(ra_in, dec_in): + for rr, dd in zip(ra_in, dec_in): r, d = pal.mapqkz(rr, dd, amprms) if r_control is None: r_control = np.array([r]) @@ -1648,7 +1648,7 @@ def test_mapqkz_vector(self): d_control = np.append(d_control, d) rTest, dTest = pal.mapqkzVector(ra_in, dec_in, amprms) - for (r1, d1, r2, d2) in zip(r_control, d_control, rTest, dTest): + for r1, d1, r2, d2 in zip(r_control, d_control, rTest, dTest): self.assertAlmostEqual(r1, r2, 12) self.assertAlmostEqual(d1, d2, 12) @@ -1658,17 +1658,17 @@ def test_mapqkz_vector(self): def test_mapqk_vector(self): amprms = pal.mappa(2010, 55927) - np.random.seed(32) + rng = np.random.default_rng(32) n_tests = 100 - ra_in = np.random.sample(n_tests) * 2.0 * np.pi - dec_in = (np.random.sample(n_tests) - 0.5) * np.pi - pmr = (np.random.sample(n_tests) - 0.5) * 0.01 - pmd = (np.random.sample(n_tests) - 0.5) * 0.01 - px = 0.00045 + np.random.sample(n_tests) * 0.001 - rv = 200.0 * np.random.sample(n_tests) + ra_in = rng.random(n_tests) * 2.0 * np.pi + dec_in = (rng.random(n_tests) - 0.5) * np.pi + pmr = (rng.random(n_tests) - 0.5) * 0.01 + pmd = (rng.random(n_tests) - 0.5) * 0.01 + px = 0.00045 + rng.random(n_tests) * 0.001 + rv = 200.0 * rng.random(n_tests) r_control = None d_control = None - for (rr, dd, pr, pd, x, v) in zip(ra_in, dec_in, pmr, pmd, px, rv): + for rr, dd, pr, pd, x, v in zip(ra_in, dec_in, pmr, pmd, px, rv): r, d = pal.mapqk(rr, dd, pr, pd, x, v, amprms) if r_control is None: r_control = np.array([r]) @@ -1678,7 +1678,7 @@ def test_mapqk_vector(self): d_control = np.append(d_control, d) rTest, dTest = pal.mapqkVector(ra_in, dec_in, pmr, pmd, px, rv, amprms) - for (r1, d1, r2, d2) in zip(r_control, d_control, rTest, dTest): + for r1, d1, r2, d2 in zip(r_control, d_control, rTest, dTest): self.assertAlmostEqual(r1, r2, 12) self.assertAlmostEqual(d1, d2, 12) @@ -1712,9 +1712,9 @@ def test_dmoon_vector(self): """ Test that dmoonVector returns results consistent with dmoon """ - np.random.seed(141) + rng = np.random.default_rng(141) n_samples = 1000 - date = np.random.random_sample(n_samples) * 10000.0 + 43000.0 + date = rng.random(n_samples) * 10000.0 + 43000.0 testX, testY, testZ, testXd, testYd, testZd = pal.dmoonVector(date) for ii in range(n_samples): @@ -1762,9 +1762,9 @@ def test_pa(self): self.assertAlmostEqual(pal.dranrm(pal.pa(0, 0.789, 0.789)), 0, 12) def test_pa_vector(self): - np.random.seed(32) - ha_in = np.random.sample(20) * 2.0 * np.pi - dec_in = (np.random.sample(20) - 0.5) * np.pi + rng = np.random.default_rng(32) + ha_in = rng.random(20) * 2.0 * np.pi + dec_in = (rng.random(20) - 0.5) * np.pi phi = 0.3 pa_control = np.zeros(20, dtype=np.float64) for i in range(20): @@ -1800,9 +1800,9 @@ def test_pcd_vector(self): Test that pcdVector returns the same results as running pcd on each element of the vectors """ - np.random.seed(120) - x_in = 2.0 * (np.random.random_sample(100) - 0.5) - y_in = 2.0 * (np.random.random_sample(100) - 0.5) + rng = np.random.default_rng(120) + x_in = 2.0 * (rng.random(100) - 0.5) + y_in = 2.0 * (rng.random(100) - 0.5) disco = 191.0 xTestList, yTestList = pal.pcdVector(disco, x_in, y_in) @@ -1829,10 +1829,10 @@ def test_unpcd_vector(self): Test that unpcdVector produces the same results as running unpcd on each element of the input vectors """ - np.random.seed(121) + rng = np.random.default_rng(121) disco = 132.0 - x_in = 2.0 * (np.random.random_sample(120) - 0.5) - y_in = 2.0 * (np.random.random_sample(120) - 0.5) + x_in = 2.0 * (rng.random(120) - 0.5) + y_in = 2.0 * (rng.random(120) - 0.5) xTestList, yTestList = pal.unpcdVector(disco, x_in, y_in) @@ -2093,17 +2093,17 @@ def test_pm(self): def test_pm_vector(self): ep0 = 52000.0 ep1 = 53510.0 - np.random.seed(32) + rng = np.random.default_rng(32) n_tests = 100 - ra_in = np.random.sample(n_tests) * 2.0 * np.pi - dec_in = (np.random.sample(n_tests) - 0.5) * np.pi - pmr = 0.01 * np.random.sample(n_tests) - pmd = 0.01 * np.random.sample(n_tests) - px = 0.00045 + 0.001 * np.random.sample(n_tests) - rv = 1000.0 * np.random.sample(n_tests) + ra_in = rng.random(n_tests) * 2.0 * np.pi + dec_in = (rng.random(n_tests) - 0.5) * np.pi + pmr = 0.01 * rng.random(n_tests) + pmd = 0.01 * rng.random(n_tests) + px = 0.00045 + 0.001 * rng.random(n_tests) + rv = 1000.0 * rng.random(n_tests) r_control = None d_control = None - for (rr, dd, pr, pd, x, v) in zip(ra_in, dec_in, pmr, pmd, px, rv): + for rr, dd, pr, pd, x, v in zip(ra_in, dec_in, pmr, pmd, px, rv): r, d = pal.pm(rr, dd, pr, pd, x, v, ep0, ep1) if r_control is None: r_control = np.array([r]) @@ -2113,7 +2113,7 @@ def test_pm_vector(self): d_control = np.append(d_control, d) rTest, dTest = pal.pmVector(ra_in, dec_in, pmr, pmd, px, rv, ep0, ep1) - for (r1, d1, r2, d2) in zip(r_control, d_control, rTest, dTest): + for r1, d1, r2, d2 in zip(r_control, d_control, rTest, dTest): self.assertAlmostEqual(r1, r2, 12) self.assertAlmostEqual(d1, d2, 12) @@ -2188,10 +2188,10 @@ def test_drange_vector(self): """ Test that drangeVector returns results consistent with drange """ - np.random.seed(140) + rng = np.random.default_rng(140) n_samples = 1000 - angle_in = np.random.random_sample(n_samples) * 10.0 * np.pi + 2.0 * np.pi - angle_in = np.append(angle_in, np.random.random_sample(n_samples) * (-10.0) * np.pi) + angle_in = rng.random(n_samples) * 10.0 * np.pi + 2.0 * np.pi + angle_in = np.append(angle_in, rng.random(n_samples) * (-10.0) * np.pi) test_angle = pal.drangeVector(angle_in) @@ -2208,9 +2208,9 @@ def test_dranrm_vector(self): """ Test that dranrmVector returns the same results as dranrm """ - np.random.seed(74310) + rng = np.random.default_rng(74310) n_samples = 100 - angle_in = (np.random.random_sample(100) - 0.5) * 4.0 * np.pi + angle_in = (rng.random(100) - 0.5) * 4.0 * np.pi angle_in = np.array([aa + 2.0 * np.pi if aa > 0.0 else aa for aa in angle_in]) # make sure we created input angles that are outside the @@ -2278,8 +2278,8 @@ def test_ref(self): zr = pal.refz(1.55, refa, refb) self.assertAlmostEqual(zr, 1.545697350690958, 12) - np.random.seed(32) - zu_int = np.random.sample(20) * 1.4 + rng = np.random.default_rng(32) + zu_int = rng.random(20) * 1.4 zr_control = np.zeros(20, dtype=np.float64) for i, zu in enumerate(zu_int): zr = pal.refz(zu, refa, refb) @@ -2293,8 +2293,8 @@ def test_refv_vector(self): Test that refvVector gives the same results as iterating over vectors with refv """ - np.random.seed(118) - input_data = np.random.random_sample((4, 3)) * 5.0 + rng = np.random.default_rng(118) + input_data = rng.random((4, 3)) * 5.0 ref_a = 0.02 ref_b = 0.05 output_data = pal.refvVector(input_data, ref_a, ref_b) @@ -2307,7 +2307,7 @@ def test_refro_vector(self): Test that refroVector returns the same results as just calling refro on each element of the input vector individually. """ - np.random.seed(119) + rng = np.random.default_rng(119) hm = 150.0 tdk = 289.0 pmb = 670.0 @@ -2316,7 +2316,7 @@ def test_refro_vector(self): phi = 0.3 tlr = 0.008 eps = 1.0e-10 - zobs = np.random.random_sample(20) * np.pi * 0.5 + zobs = rng.random(20) * np.pi * 0.5 test_output = pal.refroVector(zobs, hm, tdk, pmb, rh, wl, phi, tlr, eps) for zz, test in zip(zobs, test_output): control = pal.refro(zz, hm, tdk, pmb, rh, wl, phi, tlr, eps) @@ -2356,17 +2356,17 @@ def test_sep(self): self.assertAlmostEqual(pal.dsepv(d1, d2), 2.8603919190246608, 7) def test_dsep_vector(self): - np.random.seed(32) - ra1 = np.random.sample(20) * 2.0 * np.pi - dec1 = np.random.sample(20) * 2.0 * np.pi - ra2 = np.random.sample(20) * 2.0 * np.pi - dec2 = np.random.sample(20) * 2.0 * np.pi + rng = np.random.default_rng(32) + ra1 = rng.random(20) * 2.0 * np.pi + dec1 = rng.random(20) * 2.0 * np.pi + ra2 = rng.random(20) * 2.0 * np.pi + dec2 = rng.random(20) * 2.0 * np.pi dd_control = np.zeros(20, dtype=np.float64) - for (i, rr) in enumerate(zip(ra1, dec1, ra2, dec2)): + for i, rr in enumerate(zip(ra1, dec1, ra2, dec2)): dd = pal.dsep(rr[0], rr[1], rr[2], rr[3]) dd_control[i] = dd dd_test = pal.dsepVector(ra1, dec1, ra2, dec2) - for (ddc, ddt) in zip(dd_test, dd_control): + for ddc, ddt in zip(dd_test, dd_control): self.assertAlmostEqual(ddc, ddt, 12) # test that an exception is raised if input arrays @@ -2382,10 +2382,10 @@ def test_dsepv_vector(self): Test that dsepvVector produces results that agree with dsepv """ - np.random.seed(130) + rng = np.random.default_rng(130) n_samples = 100 - v1 = (np.random.random_sample((n_samples, 3)) - 0.5) * 100.0 - v2 = (np.random.random_sample((n_samples, 3)) - 0.5) * 100.0 + v1 = (rng.random((n_samples, 3)) - 0.5) * 100.0 + v2 = (rng.random((n_samples, 3)) - 0.5) * 100.0 test_sep = pal.dsepvVector(v1, v2) for ii in range(n_samples): @@ -2402,12 +2402,12 @@ def test_dsepv_vector(self): # test that exceptions are raised when they ought to be self.assertRaises(ValueError, pal.dsepvVector, v1, v2[0:19]) - v3 = np.random.random_sample((n_samples, 2)) + v3 = rng.random((n_samples, 2)) self.assertRaises(ValueError, pal.dsepvVector, v3, v2) self.assertRaises(ValueError, pal.dsepvVector, v1, v3) - self.assertRaises(ValueError, pal.dsepvVector, v1, np.random.random_sample(4)) + self.assertRaises(ValueError, pal.dsepvVector, v1, rng.random(4)) def test_supgal(self): (dl, db) = pal.supgal(6.1, -1.4) @@ -2419,10 +2419,10 @@ def test_supgal_vector(self): Test that supgalVector returns results consistent with supgal """ - np.random.seed(134) + rng = np.random.default_rng(134) n_samples = 200 - dsl_list = np.random.random_sample(n_samples) * 2.0 * np.pi - dsb_list = (np.random.random_sample(n_samples) - 0.5) * np.pi + dsl_list = rng.random(n_samples) * 2.0 * np.pi + dsb_list = (rng.random(n_samples) - 0.5) * np.pi testDl, testDb = pal.supgalVector(dsl_list, dsb_list) @@ -2463,12 +2463,12 @@ def test_ds2tp_vector(self): raz = 0.3 decz = 0.1 n_tests = 100 - np.random.seed(32) - ra_in = raz + (np.random.sample(n_tests) - 0.5) * 0.2 - dec_in = decz + (np.random.sample(n_tests) - 0.5) * 0.2 + rng = np.random.default_rng(32) + ra_in = raz + (rng.random(n_tests) - 0.5) * 0.2 + dec_in = decz + (rng.random(n_tests) - 0.5) * 0.2 xi_control = None eta_control = None - for (rr, dd) in zip(ra_in, dec_in): + for rr, dd in zip(ra_in, dec_in): xi, eta = pal.ds2tp(rr, dd, raz, decz) if xi_control is None: xi_control = np.array([xi]) @@ -2478,7 +2478,7 @@ def test_ds2tp_vector(self): eta_control = np.append(eta_control, eta) xiTest, etaTest = pal.ds2tpVector(ra_in, dec_in, raz, decz) - for (x1, e1, x2, e2) in zip(xi_control, eta_control, xiTest, etaTest): + for x1, e1, x2, e2 in zip(xi_control, eta_control, xiTest, etaTest): self.assertAlmostEqual(x1, x2, 12) self.assertAlmostEqual(e1, e2, 12) @@ -2505,13 +2505,13 @@ def test_dtp2s_vector(self): dtp2s """ - np.random.seed(139) + rng = np.random.default_rng(139) n_samples = 200 raz = 0.9 decz = -0.3 - xi = (np.random.random_sample(n_samples) - 0.5) * 10.0 - eta = (np.random.random_sample(n_samples) - 0.5) * 10.0 + xi = (rng.random(n_samples) - 0.5) * 10.0 + eta = (rng.random(n_samples) - 0.5) * 10.0 testRa, testDec = pal.dtp2sVector(xi, eta, raz, decz) for ii in range(n_samples): From 83b1d3b4f793b852e089929bfd2c4a8ee468a873 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 14:45:11 -0700 Subject: [PATCH 05/11] Ruff and black fixes --- setup.py | 12 +-- test_pal.py | 229 ++++++++++++++++++++++------------------------------ 2 files changed, 104 insertions(+), 137 deletions(-) diff --git a/setup.py b/setup.py index 7af3845..4ca3e41 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ +import codecs import os -import numpy import re -import codecs -from setuptools import Extension, setup + +import numpy from Cython.Build import cythonize +from setuptools import Extension, setup from setuptools_scm import get_version -# Local code -from support import sst2pydoc as sst from support import palvers +from support import sst2pydoc as sst # The version is needed so we can copy the version into the # palpy binary (there are no python support packages with __init__.py). @@ -424,7 +424,7 @@ long_description = file.read() extensions = [ - Extension("palpy", sources, include_dirs=["cextern/erfa/src", "cextern/pal", numpy.get_include()]) + Extension("palpy", sources, include_dirs=["cextern/erfa/src", "cextern/pal", numpy.get_include()]), ] setup( diff --git a/test_pal.py b/test_pal.py index a29480a..9b88b6d 100644 --- a/test_pal.py +++ b/test_pal.py @@ -17,8 +17,9 @@ # along with this program. If not, see . import unittest -import palpy as pal + import numpy as np +import palpy as pal class TestPal(unittest.TestCase): @@ -66,9 +67,7 @@ def test_airmass(self): self.assertAlmostEqual(pal.airmas(1.2354), 3.015698990074724, 11) def test_airmass_vector(self): - """ - Test that airmassVector gives results consistent with airmass - """ + """Test that airmassVector gives results consistent with airmass""" rng = np.random.default_rng(145) n_samples = 1000 zd = rng.random(n_samples) * 0.5 * np.pi @@ -147,9 +146,7 @@ def test_ampqk(self): self.assertAlmostEqual(dm, -0.56702909748530827549, 11) def test_ampqk_vector(self): - """ - Test that ampqkVector produces results consistent with ampqk - """ + """Test that ampqkVector produces results consistent with ampqk""" rng = np.random.default_rng(144) n_samples = 200 amprms = pal.mappa(2010.0, 55927.0) @@ -215,7 +212,16 @@ def test_aopqk_vector(self): azTest, zeTest, haTest, dTest, rTest = pal.aopqkVector(ra_in, dec_in, obsrms) for a1, z1, h1, d1, r1, a2, z2, h2, d2, r2 in zip( - az_control, ze_control, ha_control, d_control, r_control, azTest, zeTest, haTest, dTest, rTest + az_control, + ze_control, + ha_control, + d_control, + r_control, + azTest, + zeTest, + haTest, + dTest, + rTest, ): self.assertAlmostEqual(a1, a2, 12) @@ -336,10 +342,7 @@ def test_aop(self): self.assertAlmostEqual(aoprms[13], 7.602374979243502, 8) def test_oapqk_vector(self): - """ - Test that oapqkVector gives results consistent with oapqk - """ - + """Test that oapqkVector gives results consistent with oapqk""" date = 51000.1 dut = 25.0 elongm = 2.1 @@ -412,8 +415,7 @@ def test_bear(self): self.assertAlmostEqual(pal.dpav(d1, d2), 0.7045970341781791, 12) def test_dbear_vector(self): - """ - Test that dbearVector gives the same + """Test that dbearVector gives the same results as dbear """ rng = np.random.default_rng(122) @@ -445,23 +447,21 @@ def test_dbear_vector(self): self.assertRaises(ValueError, pal.dbearVector, a1_in, b1_in, a2_in[:9], b2_in[:9]) def test_dpav_vector(self): - """ - Test that dpavVector is consistent with dpav - """ + """Test that dpavVector is consistent with dpav""" rng = np.random.default_rng(127) n_samples = 200 phi = rng.random(n_samples) * 2.0 * np.pi theta = (rng.random(n_samples) - 0.5) * np.pi v1 = np.array( - [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)] + [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)], ) phi = rng.random(n_samples) * 2.0 * np.pi theta = (rng.random(n_samples) - 0.5) * np.pi v2 = np.array( - [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)] + [[np.cos(th), np.sin(th) * np.cos(ph), np.sin(th) * np.sin(ph)] for th, ph in zip(theta, phi)], ) test_pa = pal.dpavVector(v1, v2) @@ -496,9 +496,7 @@ def test_caldj(self): self.assertRaises(ValueError, pal.caldj, 1970, 1, 32) def test_caldj_vector(self): - """ - Test that caldjVector gives results consistent with cadj - """ + """Test that caldjVector gives results consistent with cadj""" rng = np.random.default_rng(143) n_samples = 200 iy = rng.integers(1000, 10001, n_samples) @@ -543,9 +541,7 @@ def test_daf2r(self): self.assertAlmostEqual(dr, 1.342313819975276, 12) def test_daf2r_vector(self): - """ - Test that daf2rVector returns the same results as daf2r - """ + """Test that daf2rVector returns the same results as daf2r""" rng = np.random.default_rng(123) n_samples = 100 deg = rng.integers(0, 360, n_samples) @@ -575,9 +571,7 @@ def test_cc2s(self): self.assertAlmostEqual(db, 0.2199879773954594, 12) def test_dcc2s_vector(self): - """ - Test that dcc2sVector returns the same results as dcc2s - """ + """Test that dcc2sVector returns the same results as dcc2s""" rng = np.random.default_rng(124) input_data = rng.random((20, 3)) * 10.0 aTest, b_test = pal.dcc2sVector(input_data) @@ -592,9 +586,7 @@ def test_dcc2s_vector(self): self.assertRaises(ValueError, pal.dcc2sVector, dummy_data) def test_dcs2c_vector(self): - """ - Test that dcs2cVector returns the same results as dcs2c - """ + """Test that dcs2cVector returns the same results as dcs2c""" rng = np.random.default_rng(125) n_samples = 100 ra = rng.random(n_samples) * 2.0 * np.pi @@ -623,9 +615,7 @@ def test_cd2tf(self): self.assertEqual(fraction, 3333) def test_dd2tf_vector(self): - """ - Test that dd2tfVector gives the same results as dd2tf - """ + """Test that dd2tfVector gives the same results as dd2tf""" rng = np.random.default_rng(126) n_samples = 100 days_list = (rng.random(n_samples) - 0.5) * 1200.0 @@ -656,8 +646,7 @@ def test_dr2af(self): self.assertEqual(f, 9706) def test_dr2af_vector(self): - """ - Test that dr2afVector produces the same results as + """Test that dr2afVector produces the same results as dr2af """ rng = np.random.default_rng(128) @@ -684,8 +673,7 @@ def test_dr2tf(self): self.assertEqual(f, 6484) def test_dr2tf_vector(self): - """ - Test that dr2tfVector produces the same results as + """Test that dr2tfVector produces the same results as dr2tf """ rng = np.random.default_rng(128) @@ -711,8 +699,7 @@ def test_dtf2d(self): self.assertRaises(ValueError, pal.dtf2d, 23, 1, 60) def test_dtf2d_vector(self): - """ - Test that dtf2dVector gives results consistent with + """Test that dtf2dVector gives results consistent with dtf2d """ rng = np.random.default_rng(131) @@ -754,8 +741,7 @@ def test_dtf2r(self): self.assertRaises(ValueError, pal.dtf2r, 23, 1, 60) def test_dtf2r_vector(self): - """ - Test that dtf2rVector gives results consistent with + """Test that dtf2rVector gives results consistent with dtf2r """ rng = np.random.default_rng(131) @@ -811,9 +797,7 @@ def test_djcal(self): self.assertAlmostEqual(f, 0.9999, 7) def test_djcal_vector(self): - """ - Test that djcalVector returns results consistent with djcal - """ + """Test that djcalVector returns results consistent with djcal""" rng = np.random.default_rng(142) n_samples = 200 mjd = (rng.random(n_samples) - 0.5) * 100000.0 @@ -854,7 +838,7 @@ def test_djcal_vector(self): def test_dmat(self): da = np.array( - [[2.22, 1.6578, 1.380522], [1.6578, 1.380522, 1.22548578], [1.380522, 1.22548578, 1.1356276122]] + [[2.22, 1.6578, 1.380522], [1.6578, 1.380522, 1.22548578], [1.380522, 1.22548578, 1.1356276122]], ) dv = np.array([2.28625, 1.7128825, 1.429432225]) (da, dv, dd) = pal.dmat(da, dv) @@ -906,9 +890,7 @@ def test_de2h_vector(self): self.assertRaises(ValueError, pal.de2hVector, ha_in[:10], dec_in, phi) def test_dh2e_vector(self): - """ - Test that dh2eVector gives results consistent with dh2e - """ + """Test that dh2eVector gives results consistent with dh2e""" rng = np.random.default_rng(142) n_samples = 200 phi = 1.432 @@ -940,8 +922,7 @@ def test_ecleq(self): self.assertAlmostEqual(dd, 0.2638461400411088, 5) def test_ecleq_vector(self): - """ - Test that ecleqVector produces results consistent with + """Test that ecleqVector produces results consistent with ecleq """ mjd = 58734.2 @@ -974,7 +955,7 @@ def test_ecmat(self): [1.0, 0.0, 0.0], [0.0, 0.91749307789883549624, 0.3977517467060596168], [0.0, -0.3977517467060596168, 0.91749307789883549624], - ] + ], ) rmat = pal.ecmat(55966.46) @@ -995,9 +976,7 @@ def test_epj(self): self.assertAlmostEqual(pal.epj(42999), 1976.603696098563, 7) def test_epj_vector(self): - """ - Test that epjVector returns results consistent with epj - """ + """Test that epjVector returns results consistent with epj""" rng = np.random.default_rng(45738) n_samples = 300 date = 43000.0 + rng.random(n_samples) * 10000.0 @@ -1011,9 +990,7 @@ def test_epj2d(self): self.assertAlmostEqual(pal.epj2d(2010.077), 55225.124250, 6) def test_epj2d_vector(self): - """ - Test that epj2dVector returns results consistent with epj - """ + """Test that epj2dVector returns results consistent with epj""" rng = np.random.default_rng(45367) n_samples = 300 epj = 2000.0 + rng.random(n_samples) * 50.0 @@ -1029,8 +1006,7 @@ def test_eqecl(self): self.assertAlmostEqual(db, -0.4036047164116848, 6) def test_eqecl_vector(self): - """ - Test that eqeclVector produces results consistent with + """Test that eqeclVector produces results consistent with eqecl """ mjd = 53000.0 @@ -1120,8 +1096,7 @@ def test_evp(self): np.testing.assert_allclose(dph, phex2, atol=1e-12) def test_fk524(self): - """ - Test that fk524 gives results consistent with data published + """Test that fk524 gives results consistent with data published in: 'Explanatory Supplement to The Astronomical Almanac' @@ -1130,7 +1105,6 @@ def test_fk524(self): Table 3.58.1 """ - # fk4 ra hr_in = np.array([0, 3, 6, 14, 21, 1, 20, 11, 14]) min_in = np.array([17, 17, 11, 36, 4, 48, 15, 50, 54]) @@ -1231,8 +1205,7 @@ def test_fk524(self): self.assertLess(dvr, 0.01) def test_fk524_vectors(self): - """ - Test that fk524Vector returns results consistent with + """Test that fk524Vector returns results consistent with fk524 """ rng = np.random.default_rng(135) @@ -1245,12 +1218,22 @@ def test_fk524_vectors(self): vr5 = (rng.random(n_samples) - 0.5) * 200.0 testRa, testDec, testMura, testMudec, testPx, testVr = pal.fk524Vector( - ra5, dec5, mura5, mudec5, px5, vr5 + ra5, + dec5, + mura5, + mudec5, + px5, + vr5, ) for ii in range(n_samples): controlRa, controlDec, controlMura, controlMudec, controlPx, controlVr = pal.fk524( - ra5[ii], dec5[ii], mura5[ii], mudec5[ii], px5[ii], vr5[ii] + ra5[ii], + dec5[ii], + mura5[ii], + mudec5[ii], + px5[ii], + vr5[ii], ) self.assertEqual(controlRa, testRa[ii]) @@ -1287,9 +1270,7 @@ def test_fk45z(self): self.assertAlmostEqual(d2000, -0.29826111711331398935, 12) def test_fk45z_vector(self): - """ - Test that fk45zVector produces results consistent with fk45z - """ + """Test that fk45zVector produces results consistent with fk45z""" epoch = 1960 rng = np.random.default_rng(136) n_samples = 200 @@ -1327,8 +1308,7 @@ def test_fk52h(self): self.assertAlmostEqual(dd5, -0.000000002334012, 13) def test_fk5hz_vector(self): - """ - Test that fk5hzVector returns results consistent with + """Test that fk5hzVector returns results consistent with fk5hz """ rng = np.random.default_rng(132) @@ -1347,8 +1327,7 @@ def test_fk5hz_vector(self): self.assertRaises(ValueError, pal.fk5hzVector, ra_list, dec_list[:24], 2000.0) def test_hkf5z_vector(self): - """ - Test that hkf5zVector produces results consistent with + """Test that hkf5zVector produces results consistent with hkf5z """ rng = np.random.default_rng(133) @@ -1380,9 +1359,7 @@ def test_fk54z(self): self.assertAlmostEqual(dd1950, 7.196059425334821089e-09, 12) def test_fk54z_vector(self): - """ - Test that fk54zVector returns results consistent with fk54z - """ + """Test that fk54zVector returns results consistent with fk54z""" epoch = 1960 rng = np.random.default_rng(136) n_samples = 200 @@ -1435,9 +1412,7 @@ def test_galsup(self): self.assertAlmostEqual(dsb, -0.01862369899731829, 12) def test_galsup_vector(self): - """ - Test that galsupVector gives results consistent with galsup - """ + """Test that galsupVector gives results consistent with galsup""" rng = np.random.default_rng(134) n_samples = 200 @@ -1468,9 +1443,7 @@ def test_ge50(self): self.assertAlmostEqual(dd, -0.4924752701678960, 12) def test_ge50_vector(self): - """ - Test that ge50Vector returns results consistent with ge50 - """ + """Test that ge50Vector returns results consistent with ge50""" rng = np.random.default_rng(133) n_samples = 200 ll_list = rng.random(n_samples) * 2.0 * np.pi @@ -1572,14 +1545,13 @@ def test_mappa(self): 0.00022682360163333854623, -1.5069005133483779417e-05, 0.99999997416198904698, - ] + ], ) amprms = pal.mappa(2010.0, 55927) np.testing.assert_array_almost_equal(amprms, expected, decimal=12) def test_mapqk(self): - """ - Test mapqk by taking the geocentric apparent positions of Arcturus + """Test mapqk by taking the geocentric apparent positions of Arcturus as downloaded from aa.usno.mil/data/docs/geocentric.php and trying to calculate it from Arcturus' mean position, proper motion, parallax, and radial velocity. @@ -1591,7 +1563,6 @@ def test_mapqk(self): JD (UT) 2457000.375 as reported by http://aa.usno.navy.mil/data/docs/geocentric.php """ - ra_0, i = pal.dafin("14 15 39.67207 ", 1) ra_0 *= 15.0 dec_0, i = pal.dafin("19 10 56.673", 1) @@ -1618,8 +1589,7 @@ def test_mapqk(self): self.assertAlmostEqual(dd, 0.0, 0) def test_mapqkz(self): - """ - Run inputs through mapqk with zero proper motion, parallax + """Run inputs through mapqk with zero proper motion, parallax and radial velocity. Then run the same inputs through mapqkz. Verify that the results are the same. """ @@ -1703,15 +1673,13 @@ def test_moon(self): -3.44709700068209e-09, 5.44477533462392e-09, 2.11785724844417e-09, - ] + ], ) pv = pal.dmoon(48634.4687174074) np.testing.assert_array_almost_equal(pv, expected, decimal=12) def test_dmoon_vector(self): - """ - Test that dmoonVector returns results consistent with dmoon - """ + """Test that dmoonVector returns results consistent with dmoon""" rng = np.random.default_rng(141) n_samples = 1000 date = rng.random(n_samples) * 10000.0 + 43000.0 @@ -1732,7 +1700,7 @@ def test_nut(self): [9.999999969492166e-1, 7.166577986249302e-5, 3.107382973077677e-5], [-7.166503970900504e-5, 9.999999971483732e-1, -2.381965032461830e-5], [-3.107553669598237e-5, 2.381742334472628e-5, 9.999999992335206818e-1], - ] + ], ) rmatn = pal.nut(46012.32) @@ -1796,8 +1764,7 @@ def test_pcd(self): self.assertAlmostEqual(y, refy, 14) def test_pcd_vector(self): - """ - Test that pcdVector returns the same results as running + """Test that pcdVector returns the same results as running pcd on each element of the vectors """ rng = np.random.default_rng(120) @@ -1825,8 +1792,7 @@ def test_pcd_vector(self): self.assertRaises(ValueError, pal.pcdVector, disco, x_in, y_in[:10]) def test_unpcd_vector(self): - """ - Test that unpcdVector produces the same results as running unpcd + """Test that unpcdVector produces the same results as running unpcd on each element of the input vectors """ rng = np.random.default_rng(121) @@ -1877,13 +1843,22 @@ def test_planet(self): -0.01552349065435120900, 50000.0, 0.0, - ] + ], ) np.testing.assert_allclose(u, expectedue1, atol=1e-12) # palPertel (epoch, orbinc, anode, perih, aorq, e, aorl) = pal.pertel( - 2, 43000.0, 43200.0, 43000.0, 0.2, 3, 4, 5, 0.02, 6 + 2, + 43000.0, + 43200.0, + 43000.0, + 0.2, + 3, + 4, + 5, + 0.02, + 6, ) self.assertAlmostEqual(epoch, 43200, 10) self.assertAlmostEqual(orbinc, 0.1995661466545422381, 7) @@ -1910,7 +1885,7 @@ def test_planet(self): 0.01452010174371893229, 50100.0, 0.0, - ] + ], ) np.testing.assert_allclose(unew, expectedue3, atol=1e-12) @@ -1924,7 +1899,7 @@ def test_planet(self): 2.742247411571786194e-8, 1.170467244079075911e-7, 3.709878268217564005e-8, - ] + ], ) np.testing.assert_allclose(pv, expectedpv2, atol=1e-12) @@ -1990,7 +1965,7 @@ def test_planet(self): -0.2511321445456515, 50000.0, 0.0, - ] + ], ) u = pal.pv2ue(pv, 50000.0, 0.00006) np.testing.assert_allclose(u, expectedue2, atol=1e-12) @@ -2068,7 +2043,7 @@ def test_planet(self): -0.6890132370721108608e-6, 0.4326690733487621457e-6, -0.1763249096254134306e-6, - ] + ], ) np.testing.assert_allclose(pv, expectedpv, atol=1e-12) @@ -2142,7 +2117,7 @@ def test_prebn(self): [9.999257613786738e-1, -1.117444640880939e-2, -4.858341150654265e-3], [1.117444639746558e-2, 9.999375635561940e-1, -2.714797892626396e-5], [4.858341176745641e-3, -2.714330927085065e-5, 9.999881978224798e-1], - ] + ], ) rmatp = pal.prebn(1925, 1975) np.testing.assert_array_almost_equal(rmatp, expected, 12) @@ -2153,7 +2128,7 @@ def test_prec(self): [0.9999856154510, -0.0049192906204, -0.0021376320580], [0.0049192906805, 0.9999879002027, -5.2297405698747e-06], [0.0021376319197, -5.2859681191735e-06, 0.9999977152483], - ] + ], ) rmat = pal.prec(1990, 2012) np.testing.assert_array_almost_equal(rmat, expected, 12) @@ -2176,7 +2151,7 @@ def test_pvobs(self): -7.5976959740661272483e-10, -3.4771429582640930371e-10, 0.0, - ] + ], ) pv = pal.pvobs(1.3, 10000, 2) np.testing.assert_array_almost_equal(pv, expected, decimal=12) @@ -2185,9 +2160,7 @@ def test_range(self): self.assertAlmostEqual(pal.drange(-4), 2.283185307179586, 12) def test_drange_vector(self): - """ - Test that drangeVector returns results consistent with drange - """ + """Test that drangeVector returns results consistent with drange""" rng = np.random.default_rng(140) n_samples = 1000 angle_in = rng.random(n_samples) * 10.0 * np.pi + 2.0 * np.pi @@ -2205,9 +2178,7 @@ def test_ranorm(self): self.assertAlmostEqual(pal.dranrm(-0.1), 6.183185307179587, 12) def test_dranrm_vector(self): - """ - Test that dranrmVector returns the same results as dranrm - """ + """Test that dranrmVector returns the same results as dranrm""" rng = np.random.default_rng(74310) n_samples = 100 angle_in = (rng.random(100) - 0.5) * 4.0 * np.pi @@ -2234,10 +2205,14 @@ def test_dranrm_vector(self): def test_ref(self): self.assertAlmostEqual( - pal.refro(1.4, 3456.7, 280, 678.9, 0.9, 0.55, -0.3, 0.006, 1e-9), 0.00106715763018568, 12 + pal.refro(1.4, 3456.7, 280, 678.9, 0.9, 0.55, -0.3, 0.006, 1e-9), + 0.00106715763018568, + 12, ) self.assertAlmostEqual( - pal.refro(1.4, 3456.7, 280, 678.9, 0.9, 1000, -0.3, 0.006, 1e-9), 0.001296416185295403, 12 + pal.refro(1.4, 3456.7, 280, 678.9, 0.9, 1000, -0.3, 0.006, 1e-9), + 0.001296416185295403, + 12, ) (refa, refb) = pal.refcoq(275.9, 709.3, 0.9, 101) @@ -2289,8 +2264,7 @@ def test_ref(self): self.assertAlmostEqual(zt, zc, 12) def test_refv_vector(self): - """ - Test that refvVector gives the same results as iterating over + """Test that refvVector gives the same results as iterating over vectors with refv """ rng = np.random.default_rng(118) @@ -2303,8 +2277,7 @@ def test_refv_vector(self): np.testing.assert_array_equal(outVector, control_vector) def test_refro_vector(self): - """ - Test that refroVector returns the same results as just calling + """Test that refroVector returns the same results as just calling refro on each element of the input vector individually. """ rng = np.random.default_rng(119) @@ -2378,8 +2351,7 @@ def test_dsep_vector(self): self.assertRaises(ValueError, pal.dsepVector, ra1, dec1, ra2, dec2[:5]) def test_dsepv_vector(self): - """ - Test that dsepvVector produces results that agree + """Test that dsepvVector produces results that agree with dsepv """ rng = np.random.default_rng(130) @@ -2415,10 +2387,7 @@ def test_supgal(self): self.assertAlmostEqual(db, -0.1397070490669407, 12) def test_supgal_vector(self): - """ - Test that supgalVector returns results consistent with supgal - """ - + """Test that supgalVector returns results consistent with supgal""" rng = np.random.default_rng(134) n_samples = 200 dsl_list = rng.random(n_samples) * 2.0 * np.pi @@ -2500,11 +2469,9 @@ def test_ds2tp_vector(self): self.assertRaises(ValueError, pal.ds2tpVector, ra_in[:3], dec_in, raz, decz) def test_dtp2s_vector(self): - """ - Test that dtp2sVector produces results consistent with + """Test that dtp2sVector produces results consistent with dtp2s """ - rng = np.random.default_rng(139) n_samples = 200 raz = 0.9 @@ -2538,7 +2505,7 @@ def test_vecmat(self): [0.9930075842721269, 0.05902743090199868, -0.1022335560329612], [-0.07113807138648245, 0.9903204657727545, -0.1191836812279541], [0.09420887631983825, 0.1256229973879967, 0.9875948309655174], - ] + ], ) deuler_expected = np.array( @@ -2546,7 +2513,7 @@ def test_vecmat(self): [-0.1681574770810878, 0.1981362273264315, 0.9656423242187410], [-0.2285369373983370, 0.9450659587140423, -0.2337117924378156], [-0.9589024617479674, -0.2599853247796050, -0.1136384607117296], - ] + ], ) dmxm_expected = np.array( @@ -2554,7 +2521,7 @@ def test_vecmat(self): [-0.09010460088585805, 0.3075993402463796, 0.9472400998581048], [-0.3161868071070688, 0.8930686362478707, -0.3200848543149236], [-0.9444083141897035, -0.3283459407855694, 0.01678926022795169], - ] + ], ) drm1 = pal.dav2m(dav) From 130d84990d0d17c419243f39f49a2bb2680a196a Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 15:48:49 -0700 Subject: [PATCH 06/11] Modernize GHA --- .github/workflows/build.yaml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 274f4d5..c2aabe9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,16 +14,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: "pip" @@ -52,14 +52,14 @@ jobs: needs: [build_and_test] if: startsWith(github.ref, 'refs/tags/') steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive # Full git history. fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.8 @@ -71,20 +71,21 @@ jobs: run: | python -m build --sdist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: palpy-sdist path: dist/* pypi_wheel_build: strategy: matrix: - os: ["ubuntu-latest", "macos-11"] + os: ["ubuntu-latest", "macos-12"] runs-on: ${{ matrix.os }} needs: [build_and_test] if: startsWith(github.ref, 'refs/tags/') env: - CIBW_BUILD: "cp3{8,9,10,11}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}" + CIBW_BUILD: "cp3{8,9,10,11,12}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}" CIBW_ARCHS_MACOS: "x86_64 arm64" # use line below to enable aarch64 builds # CIBW_ARCHS_LINUX: "auto aarch64" @@ -98,13 +99,13 @@ jobs: # with: # platforms: arm64 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.8 @@ -115,8 +116,9 @@ jobs: - name: Build and create distribution run: | python -m cibuildwheel --output-dir dist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: palpy-${{ matrix.os }} path: dist/* pypi-publish: @@ -127,9 +129,10 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: artifact path: dist + pattern: palpy-* + merge-multiple: true - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From f11c32e13fcca163b15ab538876b8c17ed6ab5c7 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 16:07:04 -0700 Subject: [PATCH 07/11] Add python 3.13 to GHA --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c2aabe9..a2a5085 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 @@ -85,7 +85,7 @@ jobs: needs: [build_and_test] if: startsWith(github.ref, 'refs/tags/') env: - CIBW_BUILD: "cp3{8,9,10,11,12}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}" + CIBW_BUILD: "cp3{8,9,10,11,12,13}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}" CIBW_ARCHS_MACOS: "x86_64 arm64" # use line below to enable aarch64 builds # CIBW_ARCHS_LINUX: "auto aarch64" From 5262ffb1842ad8b55193a55ced99eaf832bf75a8 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 16:08:23 -0700 Subject: [PATCH 08/11] Switch to uv over pip --- .github/workflows/build.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a2a5085..7dbd97b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -32,16 +32,16 @@ jobs: - name: Update pip/wheel infrastructure run: | python -m pip install --upgrade pip - pip install wheel + pip install wheel uv - name: Install pytest packages - run: pip install pytest + run: uv pip install --system pytest - name: List installed packages run: pip list -v - name: Build and install - run: pip install -v -e . + run: uv pip install --system -v -e . - name: Run tests run: | @@ -69,7 +69,7 @@ jobs: - name: Build and create distribution run: | - python -m build --sdist + python -m build --sdist - uses: actions/upload-artifact@v4 with: From 29ae48a99f6b183fff0e1bc902d4d210d3b07a7c Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 16:12:21 -0700 Subject: [PATCH 09/11] Turn on python pre releases --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7dbd97b..e6b9441 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -28,6 +28,7 @@ jobs: python-version: ${{ matrix.python-version }} cache: "pip" cache-dependency-path: "setup.cfg" + allow-prereleases: true - name: Update pip/wheel infrastructure run: | From 024eb3df113f49f06ac5e83b8676d201e3ccb86e Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 16:17:34 -0700 Subject: [PATCH 10/11] Use -Wd when running tests --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e6b9441..ac19f52 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -46,7 +46,7 @@ jobs: - name: Run tests run: | - pytest test_pal.py + pytest -Wd test_pal.py pypi_sdist_build: runs-on: ubuntu-latest From 4a42125a6110484cb8289b6258ac7034bca50f78 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 17 Aug 2024 16:19:15 -0700 Subject: [PATCH 11/11] Update release notes --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index a3d8313..47208f9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +1.8.4 +----- + +- Fix build problems with numpy 2. +- Test with python 3.12 and 3.13. + 1.8.3 -----