Skip to content

Commit 78111c2

Browse files
Merge pull request #366 from HERA-Team/fix-numpy-warnings
Fix numpy warnings
2 parents 3da86e5 + 25a317c commit 78111c2

File tree

16 files changed

+121
-117
lines changed

16 files changed

+121
-117
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,4 @@ jobs:
6666
env_vars: OS,PYTHON
6767
name: codecov-umbrella
6868
fail_ci_if_error: true
69-
path_to_write_report: ./coverage/codecov_report.txt
7069
verbose: true

examples/Overview_Core_Pspec_functions.ipynb

Lines changed: 32 additions & 27 deletions
Large diffs are not rendered by default.

hera_pspec/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def combine_psc_spectra(psc, groups=None, dset_split_str='_x_', ext_split_str='_
544544
If True, overwrite output spectra if they exist.
545545
"""
546546
# Load container
547-
if isinstance(psc, (str, np.str)):
547+
if isinstance(psc, str):
548548
psc = PSpecContainer(psc, mode='rw')
549549
else:
550550
assert isinstance(psc, PSpecContainer)

hera_pspec/grouping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def average_spectra(uvp_in, blpair_groups=None, time_avg=False,
259259
# stat_l is a list of supplied error_fields, to sum over.
260260
if isinstance(error_field, (list, tuple, np.ndarray)):
261261
stat_l = list(error_field)
262-
elif isinstance(error_field, (str, np.str)):
262+
elif isinstance(error_field, str):
263263
stat_l = [error_field]
264264
else:
265265
stat_l = []
@@ -526,7 +526,7 @@ def average_spectra(uvp_in, blpair_groups=None, time_avg=False,
526526
lst_2.extend([np.mean(np.unwrap(uvp.lst_2_array[blpairts]))%(2*np.pi)])
527527
lst_avg_arr.extend([np.mean(np.unwrap(uvp.lst_avg_array[blpairts]))%(2*np.pi)])
528528
else:
529-
blpair_arr.extend(np.ones_like(blpairts, np.int) * blpg[0])
529+
blpair_arr.extend(np.ones_like(blpairts, int) * blpg[0])
530530
time_1.extend(uvp.time_1_array[blpairts])
531531
time_2.extend(uvp.time_2_array[blpairts])
532532
time_avg_arr.extend(uvp.time_avg_array[blpairts])
@@ -746,7 +746,7 @@ def spherical_average(uvp_in, kbins, bin_widths, blpair_groups=None, time_avg=Fa
746746
dlys_array.extend(taus)
747747

748748
# store kbins as delay bins
749-
spw_dlys_array.extend(np.ones_like(taus, dtype=np.int) * spw)
749+
spw_dlys_array.extend(np.ones_like(taus, dtype=int) * spw)
750750

751751
# iterate over blpairs
752752
for b, blp in enumerate(uvp.get_blpairs()):
@@ -1488,8 +1488,8 @@ def bootstrap_resampled_error(uvp, blpair_groups=None, time_avg=False, Nsamples=
14881488
"""
14891489
from hera_pspec import UVPSpec
14901490
# type check
1491-
assert isinstance(uvp, (UVPSpec, str, np.str)), "uvp must be fed as a UVPSpec object or filepath"
1492-
if isinstance(uvp, (str, np.str)):
1491+
assert isinstance(uvp, (UVPSpec, str)), "uvp must be fed as a UVPSpec object or filepath"
1492+
if isinstance(uvp, str):
14931493
_uvp = UVPSpec()
14941494
_uvp.read_hdf5(uvp)
14951495
uvp = _uvp
@@ -1623,7 +1623,7 @@ def bootstrap_run(filename, spectra=None, blpair_groups=None, time_avg=False, Ns
16231623
from hera_pspec import uvpspec
16241624
from hera_pspec import PSpecContainer
16251625
# type check
1626-
if isinstance(filename, (str, np.str)):
1626+
if isinstance(filename, str):
16271627
# open in transactional mode
16281628
psc = PSpecContainer(filename, mode='rw', keep_open=False, swmr=False, tsleep=0.5, maxiter=maxiter)
16291629
elif isinstance(filename, PSpecContainer):

hera_pspec/noise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def set_cosmology(self, cosmo):
9494
----------
9595
cosmo : conversions.Cosmo_Conversions instance, or self.cosmo_params string, or dictionary
9696
"""
97-
if isinstance(cosmo, (str, np.str)):
97+
if isinstance(cosmo, str):
9898
cosmo = ast.literal_eval(cosmo)
9999
if isinstance(cosmo, (dict, odict)):
100100
cosmo = conversions.Cosmo_Conversions(**cosmo)

hera_pspec/pspecbeam.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _compute_pspec_scalar(cosmo, beam_freqs, omega_ratio, pspec_freqs,
6969
df = np.median(np.diff(pspec_freqs))
7070
integration_freqs = np.linspace(pspec_freqs.min(),
7171
pspec_freqs.min() + df*len(pspec_freqs),
72-
num_steps, endpoint=True, dtype=np.float)
72+
num_steps, endpoint=True, dtype=float)
7373

7474
# The interpolations are generally more stable in MHz
7575
integration_freqs_MHz = integration_freqs / 1e6
@@ -92,7 +92,7 @@ def _compute_pspec_scalar(cosmo, beam_freqs, omega_ratio, pspec_freqs,
9292

9393
# Get B_pp = \int dnu taper^2 and Bp = \int dnu
9494
if taper == 'none':
95-
dBpp_over_BpSq = np.ones_like(integration_freqs, np.float)
95+
dBpp_over_BpSq = np.ones_like(integration_freqs, float)
9696
else:
9797
dBpp_over_BpSq = dspec.gen_window(taper, len(pspec_freqs))**2.
9898
dBpp_over_BpSq = interp1d(pspec_freqs, dBpp_over_BpSq, kind='nearest',
@@ -231,12 +231,12 @@ def Jy_to_mK(self, freqs, pol='pI'):
231231
Contains Jy -> mK factor at each frequency.
232232
"""
233233
# Check input types
234-
if isinstance(freqs, (np.float, float)):
234+
if isinstance(freqs, float):
235235
freqs = np.array([freqs])
236236
elif not isinstance(freqs, np.ndarray):
237237
raise TypeError("freqs must be fed as a float ndarray")
238238
elif isinstance(freqs, np.ndarray) \
239-
and freqs.dtype not in (float, np.float, np.float64):
239+
and freqs.dtype not in (float, np.float64):
240240
raise TypeError("freqs must be fed as a float ndarray")
241241

242242
# Check frequency bounds
@@ -477,7 +477,7 @@ def beam_normalized_response(self, pol='pI', freq=None, x_orientation=None):
477477
beam_res = self.primary_beam._interp_freq(freq) # interpolate beam in frequency, based on the data frequencies
478478
beam_res = beam_res[0]
479479

480-
if isinstance(pol, (str, np.str)):
480+
if isinstance(pol, str):
481481
pol = uvutils.polstr2num(pol, x_orientation=x_orientation)
482482

483483
pol_array = self.primary_beam.polarization_array
@@ -684,8 +684,8 @@ def add_pol(self, pol, OmegaP, OmegaPP):
684684

685685
# Make sure OmegaP and OmegaPP are arrays
686686
try:
687-
OmegaP = np.array(OmegaP).astype(np.float)
688-
OmegaPP = np.array(OmegaPP).astype(np.float)
687+
OmegaP = np.array(OmegaP).astype(float)
688+
OmegaPP = np.array(OmegaPP).astype(float)
689689
except:
690690
raise TypeError("OmegaP and OmegaPP must both be array_like.")
691691

hera_pspec/pspecdata.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def C_model(self, key, model='empirical', time_index=None, known_cov=None, inclu
629629
"""
630630
# type check
631631
assert isinstance(key, tuple), "key must be fed as a tuple"
632-
assert isinstance(model, (str, np.str)), "model must be a string"
632+
assert isinstance(model, str), "model must be a string"
633633

634634
# parse key
635635
dset, bl = self.parse_blkey(key)
@@ -720,7 +720,7 @@ def cross_covar_model(self, key1, key2, model='empirical',
720720
# type check
721721
assert isinstance(key1, tuple), "key1 must be fed as a tuple"
722722
assert isinstance(key2, tuple), "key2 must be fed as a tuple"
723-
assert isinstance(model, (str, np.str)), "model must be a string"
723+
assert isinstance(model, str), "model must be a string"
724724

725725
# parse key
726726
dset1, bl1 = self.parse_blkey(key1)
@@ -1390,7 +1390,7 @@ def get_G(self, key1, key2, exact_norm=False, pol=False):
13901390
raise ValueError("Number of delay bins should have been set"
13911391
"by now! Cannot be equal to None")
13921392

1393-
G = np.zeros((self.spw_Ndlys, self.spw_Ndlys), dtype=np.complex)
1393+
G = np.zeros((self.spw_Ndlys, self.spw_Ndlys), dtype=complex)
13941394
R1 = self.R(key1)
13951395
R2 = self.R(key2)
13961396

@@ -1489,16 +1489,16 @@ def get_H(self, key1, key2, sampling=False, exact_norm=False, pol=False):
14891489
raise ValueError("Number of delay bins should have been set"
14901490
"by now! Cannot be equal to None.")
14911491

1492-
H = np.zeros((self.spw_Ndlys, self.spw_Ndlys), dtype=np.complex)
1492+
H = np.zeros((self.spw_Ndlys, self.spw_Ndlys), dtype=complex)
14931493
R1 = self.R(key1)
14941494
R2 = self.R(key2)
14951495
if not sampling:
14961496
nfreq=np.sum(self.filter_extension) + self.spw_Nfreqs
14971497
sinc_matrix = np.zeros((nfreq, nfreq))
14981498
for i in range(nfreq):
14991499
for j in range(nfreq):
1500-
sinc_matrix[i,j] = np.float(i - j)
1501-
sinc_matrix = np.sinc(sinc_matrix / np.float(nfreq))
1500+
sinc_matrix[i,j] = float(i - j)
1501+
sinc_matrix = np.sinc(sinc_matrix / float(nfreq))
15021502

15031503
iR1Q1, iR2Q2 = {}, {}
15041504
if (exact_norm):
@@ -1582,7 +1582,7 @@ def get_unnormed_E(self, key1, key2, exact_norm=False, pol=False):
15821582
"by now! Cannot be equal to None")
15831583
nfreq = self.spw_Nfreqs + np.sum(self.filter_extension)
15841584
E_matrices = np.zeros((self.spw_Ndlys, nfreq, nfreq),
1585-
dtype=np.complex)
1585+
dtype=complex)
15861586
R1 = self.R(key1)
15871587
R2 = self.R(key2)
15881588
if (exact_norm):
@@ -2227,7 +2227,7 @@ def get_Q_alt(self, mode, allow_fft=True, include_extension=False):
22272227
else:
22282228
phase_correction = 0.
22292229
if (self.spw_Ndlys == nfreq) and (allow_fft == True):
2230-
_m = np.zeros((nfreq,), dtype=np.complex)
2230+
_m = np.zeros((nfreq,), dtype=complex)
22312231
_m[mode] = 1. # delta function at specific delay mode
22322232
# FFT to transform to frequency space
22332233
m = np.fft.fft(np.fft.ifftshift(_m))
@@ -2426,9 +2426,9 @@ def broadcast_dset_flags(self, spw_ranges=None, time_thresh=0.2,
24262426
Nfreqs = float(flags.shape[1])
24272427
# get time- and freq-continguous flags
24282428
freq_contig_flgs = np.sum(flags, axis=1) / Nfreqs > 0.999999
2429-
Ntimes_noncontig = np.sum(~freq_contig_flgs, dtype=np.float)
2429+
Ntimes_noncontig = np.sum(~freq_contig_flgs, dtype=float)
24302430
# get freq channels where non-contiguous flags exceed threshold
2431-
exceeds_thresh = np.sum(flags[~freq_contig_flgs], axis=0, dtype=np.float) / Ntimes_noncontig > time_thresh
2431+
exceeds_thresh = np.sum(flags[~freq_contig_flgs], axis=0, dtype=float) / Ntimes_noncontig > time_thresh
24322432
# flag channels for all times that exceed time_thresh
24332433
dset.flag_array[bl_inds, :, np.where(exceeds_thresh)[0][:, None], i] = True
24342434
# for pixels that have flags but didn't meet broadcasting limit
@@ -2695,9 +2695,9 @@ def validate_pol(self, dsets, pol_pair):
26952695
x_orientation = self.dsets[0].x_orientation
26962696

26972697
# convert elements to integers if fed as strings
2698-
if isinstance(pol_pair[0], (str, np.str)):
2698+
if isinstance(pol_pair[0], str):
26992699
pol_pair = (uvutils.polstr2num(pol_pair[0], x_orientation=x_orientation), pol_pair[1])
2700-
if isinstance(pol_pair[1], (str, np.str)):
2700+
if isinstance(pol_pair[1], str):
27012701
pol_pair = (pol_pair[0], uvutils.polstr2num(pol_pair[1], x_orientation=x_orientation))
27022702

27032703
assert isinstance(pol_pair[0], (int, np.integer)), err_msg
@@ -3081,9 +3081,9 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
30813081
# Convert string to pol-integer pair
30823082
p = (uvutils.polstr2num(p, x_orientation=self.dsets[0].x_orientation),
30833083
uvutils.polstr2num(p, x_orientation=self.dsets[0].x_orientation))
3084-
if isinstance(p[0], (str, np.str)):
3084+
if isinstance(p[0], str):
30853085
p = (uvutils.polstr2num(p[0], x_orientation=self.dsets[0].x_orientation), p[1])
3086-
if isinstance(p[1], (str, np.str)):
3086+
if isinstance(p[1], str):
30873087
p = (p[0], uvutils.polstr2num(p[1], x_orientation=self.dsets[0].x_orientation))
30883088
_pols.append(p)
30893089
pols = _pols
@@ -3285,7 +3285,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
32853285
# the diagonal norm matrix mode (i.e., norm = 'I')
32863286
if norm == 'I' and not(exact_norm):
32873287
sa = self.scalar_delay_adjustment(Gv=Gv, Hv=Hv)
3288-
if isinstance(sa, (np.float, float)):
3288+
if isinstance(sa, float):
32893289
pv *= sa
32903290
else:
32913291
pv = np.atleast_2d(sa).T * pv
@@ -3305,7 +3305,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
33053305
cov_imag = cov_imag * (scalar)**2.
33063306

33073307
if norm == 'I' and not(exact_norm):
3308-
if isinstance(sa, (np.float, float)):
3308+
if isinstance(sa, float):
33093309
cov_real = cov_real * (sa)**2.
33103310
cov_imag = cov_imag * (sa)**2.
33113311
else:
@@ -3386,7 +3386,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
33863386
lst2.extend(dset2.lst_array[inds2])
33873387

33883388
# insert blpair info
3389-
blp_arr.extend(np.ones_like(inds1, np.int) \
3389+
blp_arr.extend(np.ones_like(inds1, int) \
33903390
* uvputils._antnums_to_blpair(blp))
33913391

33923392
# insert into data and wgts integrations dictionaries
@@ -3458,7 +3458,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
34583458
uvp.Nspwdlys = len(uvp.spw_dly_array)
34593459
uvp.Nspwfreqs = len(uvp.spw_freq_array)
34603460
uvp.Nfreqs = len(np.unique(freqs))
3461-
uvp.polpair_array = np.array(spw_polpair, np.int)
3461+
uvp.polpair_array = np.array(spw_polpair, int)
34623462
uvp.Npols = len(spw_polpair)
34633463
uvp.scalar_array = np.array(sclr_arr)
34643464
uvp.channel_width = dset1.channel_width # all dsets validated to agree
@@ -3473,11 +3473,11 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
34733473
label1 = self.labels[self.dset_idx(dsets[0])]
34743474
label2 = self.labels[self.dset_idx(dsets[1])]
34753475
uvp.labels = sorted(set([label1, label2]))
3476-
uvp.label_1_array = np.ones((uvp.Nspws, uvp.Nblpairts, uvp.Npols), np.int) \
3476+
uvp.label_1_array = np.ones((uvp.Nspws, uvp.Nblpairts, uvp.Npols), int) \
34773477
* uvp.labels.index(label1)
3478-
uvp.label_2_array = np.ones((uvp.Nspws, uvp.Nblpairts, uvp.Npols), np.int) \
3478+
uvp.label_2_array = np.ones((uvp.Nspws, uvp.Nblpairts, uvp.Npols), int) \
34793479
* uvp.labels.index(label2)
3480-
uvp.labels = np.array(uvp.labels, np.str)
3480+
uvp.labels = np.array(uvp.labels, str)
34813481
uvp.r_params = uvputils.compress_r_params(r_params)
34823482
uvp.taper = taper
34833483
if not return_q:
@@ -3507,7 +3507,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
35073507
uvp.integration_array = integration_array
35083508
uvp.wgt_array = wgt_array
35093509
uvp.nsample_array = dict(
3510-
[ (k, np.ones_like(uvp.integration_array[k], np.float))
3510+
[ (k, np.ones_like(uvp.integration_array[k], float))
35113511
for k in uvp.integration_array.keys() ] )
35123512

35133513
# covariance
@@ -4030,7 +4030,7 @@ def pspec_run(dsets, filename, dsets_std=None, cals=None, cal_flag=True,
40304030

40314031
# parse psname
40324032
if psname_ext is not None:
4033-
assert isinstance(psname_ext, (str, np.str))
4033+
assert isinstance(psname_ext, str)
40344034
else:
40354035
psname_ext = ''
40364036

@@ -4132,7 +4132,7 @@ def pspec_run(dsets, filename, dsets_std=None, cals=None, cal_flag=True,
41324132
assert len(pol_pairs) > 0, "no pol_pairs specified"
41334133

41344134
# load beam
4135-
if isinstance(beam, (str, np.str)):
4135+
if isinstance(beam, str):
41364136
beam = pspecbeam.PSpecBeamUV(beam, cosmo=cosmo)
41374137

41384138
# beam and cosmology check
@@ -4472,7 +4472,7 @@ def _load_dsets(fnames, bls=None, pols=None, logf=None, verbose=True,
44724472

44734473
# read data
44744474
uvd = UVData()
4475-
if isinstance(dset, (str, np.str)):
4475+
if isinstance(dset, str):
44764476
dfiles = glob.glob(dset)
44774477
else:
44784478
dfiles = dset
@@ -4510,7 +4510,7 @@ def _load_cals(cnames, logf=None, verbose=True):
45104510

45114511
# read data
45124512
uvc = UVCal()
4513-
if isinstance(cfile, (str, np.str)):
4513+
if isinstance(cfile, str):
45144514
uvc.read_calfits(glob.glob(cfile))
45154515
else:
45164516
uvc.read_calfits(cfile)

hera_pspec/pstokes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def _combine_pol(uvd1, uvd2, pol1, pol2, pstokes='pI', x_orientation=None):
104104
"uvd2 must be a pyuvdata.UVData instance"
105105

106106
# convert pol1 and/or pol2 to integer if fed as a string
107-
if isinstance(pol1, (str, np.str)):
107+
if isinstance(pol1, str):
108108
pol1 = pyuvdata.utils.polstr2num(pol1, x_orientation=x_orientation)
109-
if isinstance(pol2, (str, np.str)):
109+
if isinstance(pol2, str):
110110
pol2 = pyuvdata.utils.polstr2num(pol2, x_orientation=x_orientation)
111111

112112
# extracting data array from the UVData objects
@@ -121,7 +121,7 @@ def _combine_pol(uvd1, uvd2, pol1, pol2, pstokes='pI', x_orientation=None):
121121
flag = np.logical_or(flag1, flag2)
122122

123123
# convert pStokes to polarization integer if a string
124-
if isinstance(pstokes, (str, np.str)):
124+
if isinstance(pstokes, str):
125125
pstokes = pyuvdata.utils.polstr2num(pstokes, x_orientation=x_orientation)
126126

127127
# get string form of polarizations
@@ -144,7 +144,7 @@ def _combine_pol(uvd1, uvd2, pol1, pol2, pstokes='pI', x_orientation=None):
144144
uvdS = copy.deepcopy(uvd1)
145145
uvdS.data_array = stdata # pseudo-stokes data
146146
uvdS.flag_array = flag # flag array
147-
uvdS.polarization_array = np.array([pstokes], dtype=np.int) # polarization number
147+
uvdS.polarization_array = np.array([pstokes], dtype=int) # polarization number
148148
uvdS.nsample_array = uvd1.nsample_array + uvd2.nsample_array # nsamples
149149

150150
uvdS.history = "Merged into pseudo-stokes vis with hera_pspec version {}\n{}" \
@@ -220,15 +220,15 @@ def construct_pstokes(dset1, dset2, pstokes='pI', run_check=True, antenna_nums=N
220220
"""
221221
# convert dset1 and dset2 to UVData objects if they are miriad files
222222
if isinstance(dset1, pyuvdata.UVData) == False:
223-
assert isinstance(dset1, (str, np.str)), \
223+
assert isinstance(dset1, str), \
224224
"dset1 must be fed as a string or UVData object"
225225
uvd1 = miriad2pyuvdata(dset1, antenna_nums=antenna_nums, bls=bls,
226226
polarizations=polarizations, ant_str=ant_str,
227227
time_range=time_range)
228228
else:
229229
uvd1 = dset1
230230
if isinstance(dset2, pyuvdata.UVData) == False:
231-
assert isinstance(dset2, (str, np.str)), \
231+
assert isinstance(dset2, str), \
232232
"dset2 must be fed as a string or UVData object"
233233
uvd2 = miriad2pyuvdata(dset2, antenna_nums=antenna_nums, bls=bls,
234234
polarizations=polarizations, ant_str=ant_str,
@@ -237,7 +237,7 @@ def construct_pstokes(dset1, dset2, pstokes='pI', run_check=True, antenna_nums=N
237237
uvd2 = dset2
238238

239239
# convert pstokes to integer if fed as a string
240-
if isinstance(pstokes, (str, np.str)):
240+
if isinstance(pstokes, str):
241241
pstokes = pyuvdata.utils.polstr2num(pstokes, x_orientation=dset1.x_orientation)
242242

243243
# check if dset1 and dset2 habe the same spectral window
@@ -326,7 +326,7 @@ def filter_dset_on_stokes_pol(dsets, pstokes):
326326
pols = [d.polarization_array[0] for d in dsets]
327327

328328
# convert pstokes to integer if a string
329-
if isinstance(pstokes, (str, np.str)):
329+
if isinstance(pstokes, str):
330330
pstokes = pyuvdata.utils.polstr2num(pstokes, x_orientation=dsets[0].x_orientation)
331331
assert pstokes in [1, 2, 3, 4], \
332332
"pstokes must be fed as a pseudo-Stokes parameter"

0 commit comments

Comments
 (0)