From 9ab03d5f9c8b4671d0612e2d6bf5742e974e3a01 Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Wed, 26 Jun 2024 09:23:01 +0200 Subject: [PATCH 1/2] Cast to AsArray --- eazy/filters.py | 22 +++++++++++----------- eazy/photoz.py | 8 ++++---- eazy/sps.py | 2 +- eazy/templates.py | 4 ++-- eazy/utils.py | 4 ++-- eazy/visualization.py | 2 +- scripts/nmf.py | 2 +- scripts/run.py | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/eazy/filters.py b/eazy/filters.py index a4ad3026..038406df 100644 --- a/eazy/filters.py +++ b/eazy/filters.py @@ -56,8 +56,8 @@ def __init__(self, name=None, wave=None, throughput=None, bp=None, photon_counte # pysynphot Bandpass if bp is not None: - self.wave = np.cast[np.double](bp.wave) - self._throughput = np.cast[np.double](bp.throughput) + self.wave = np.asarray(bp.wave, dtype=np.double) + self._throughput = np.asarray(bp.throughput, dtype=np.double) self.name = bp.name # Set throughput accounting for photon_counter @@ -291,11 +291,11 @@ def __init__(self, file='FILTER.RES.latest', path='./'): if len(wave) > 0: # Make filter from lines already read in new_filter = FilterDefinition(name=header, - wave=np.cast[float](wave), - throughput=np.cast[float](trans)) + wave=np.asarray(wave,dtype=float), + throughput=np.asarray(trans,dtype=float)) # new_filter.name = header - # new_filter.wave = np.cast[float](wave) - # new_filter.throughput = np.cast[float](trans) + # new_filter.wave = np.asarray(wave,dtype=float) + # new_filter.throughput = np.asarray(trans,dtype=float) filters.append(new_filter) # Initialize filter @@ -303,18 +303,18 @@ def __init__(self, file='FILTER.RES.latest', path='./'): wave = [] trans = [] else: - lspl = np.cast[float](line.split()) + lspl = np.asarray(line.split(),dtype=float) wave.append(lspl[1]) trans.append(lspl[2]) # last one # new_filter = FilterDefinition() # new_filter.name = header - # new_filter.wave = np.cast[float](wave) - # new_filter.throughput = np.cast[float](trans) + # new_filter.wave = np.asarray(wave,dtype=float) + # new_filter.throughput = np.asarray(trans,dtype=float) new_filter = FilterDefinition(name=header, - wave=np.cast[float](wave), - throughput=np.cast[float](trans)) + wave=np.asarray(wave,dtype=float), + throughput=np.asarray(trans,dtype=float)) filters.append(new_filter) diff --git a/eazy/photoz.py b/eazy/photoz.py index 535449fb..05627431 100644 --- a/eazy/photoz.py +++ b/eazy/photoz.py @@ -1229,7 +1229,7 @@ def read_prior(zgrid=None, prior_file='templates/prior_F160W_TAO.dat', prior_flo prior_raw = np.loadtxt(prior_file) prior_header = open(prior_file).readline() - prior_mags = np.cast[float](prior_header.split()[2:]) + prior_mags = np.asarray(prior_header.split()[2:],dtype=float) NZ = len(zgrid) prior_data = np.zeros((NZ, len(prior_mags))) @@ -1290,7 +1290,7 @@ def set_prior(self, verbose=True): # prior_raw = np.loadtxt(self.param['PRIOR_FILE']) # prior_header = open(self.param['PRIOR_FILE']).readline() # - # self.prior_mags = np.cast[float](prior_header.split()[2:]) + # self.prior_mags = np.asarray(prior_header.split()[2:],dtype=float) # self.prior_data = np.zeros((self.NZ, len(self.prior_mags))) # # for i in range(self.prior_data.shape[1]): @@ -5206,8 +5206,8 @@ def apply_spatial_offset(self, f_ix, bin2d, xycols=None): ex = np.arange(nx) ey = np.arange(ny) - ix = np.cast[int](np.interp(xc, bin2d.x_edge, ex)) - iy = np.cast[int](np.interp(yc, bin2d.y_edge, ey)) + ix = np.asarray(np.interp(xc, bin2d.x_edge, ex),dtype=int) + iy = np.asarray(np.interp(yc, bin2d.y_edge, ey),dtype=int) corr = bin2d.statistic[ix, iy] corr[~np.isfinite(corr)] = 1 diff --git a/eazy/sps.py b/eazy/sps.py index 12f03ad9..31adb2ef 100644 --- a/eazy/sps.py +++ b/eazy/sps.py @@ -567,7 +567,7 @@ def izmet(self): NZ = len(self.zlegend) logzsol = self.params['logzsol'] zi = np.interp(logzsol, np.log10(self.zlegend/0.019), np.arange(NZ)) - return np.clip(np.cast[int](np.round(zi)), 0, NZ-1) + return np.clip(np.asarray(np.round(zi),dtype=int), 0, NZ-1) @property def fsps_ages(self): diff --git a/eazy/templates.py b/eazy/templates.py index 3d035c56..5a50c209 100644 --- a/eazy/templates.py +++ b/eazy/templates.py @@ -470,8 +470,8 @@ def __init__(self, file=None, name=None, arrays=None, sp=None, meta={}, to_angst if sp is not None: # Prospector - self.wave = np.cast[float](sp.wave) - self.flux = np.cast[float](sp.flux) + self.wave = np.asarray(sp.wave,dtype=float) + self.flux = np.asarray(sp.flux,dtype=float) # already fnu self.flux *= utils.CLIGHT*1.e10 / self.wave**2 diff --git a/eazy/utils.py b/eazy/utils.py index 32c5a280..f1a7273b 100644 --- a/eazy/utils.py +++ b/eazy/utils.py @@ -1138,8 +1138,8 @@ def draw_random(self, N=10): Draw random sets of parameters from the chain """ #ok_walk = self.sampler.acceptance_fraction > min_acceptance - iwalk = np.cast[int](np.random.rand(N)*self.nwalkers) - istep = self.nburn + np.cast[int](np.random.rand(N)*(self.nstep-self.nburn)) + iwalk = np.asarray(np.random.rand(N)*self.nwalkers,dtype=int) + istep = self.nburn + np.asarray(np.random.rand(N)*(self.nstep-self.nburn),dtype=int) draw = self.chain[iwalk, istep, :] return draw diff --git a/eazy/visualization.py b/eazy/visualization.py index 77be12cb..82ee8a0f 100644 --- a/eazy/visualization.py +++ b/eazy/visualization.py @@ -1224,7 +1224,7 @@ def parse_id_input(id_input): if len(inp_split) == 1: return int(inp_split[0]), None - ra, dec = np.cast[float](inp_split) + ra, dec = np.asarray(inp_split, dtype=float)float cosd = np.cos(self.df['dec']/180*np.pi) dx = (self.df['ra'] - ra)*cosd diff --git a/scripts/nmf.py b/scripts/nmf.py index f187cdba..bc18eec6 100644 --- a/scripts/nmf.py +++ b/scripts/nmf.py @@ -114,7 +114,7 @@ def build_matrices(): ############## ## Build NMF matrix - izbest = np.cast[int](np.round(np.interp(self.zbest, self.tempfilt.zgrid, np.arange(self.NZ)))) + izbest = np.asarray(np.round(np.interp(self.zbest, self.tempfilt.zgrid, np.arange(self.NZ))),dtype=int) NOBJ = len(idx) data = np.zeros((NOBJ, self.NFILT, self.NZ)) diff --git a/scripts/run.py b/scripts/run.py index 124c5c8e..8e5bc4cc 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -90,8 +90,8 @@ def go(): Lj = Ltot[:,2] lines = open('templates/uvista_nmf/spectra_kc13_12_tweak.param').readlines() - MLv_template = np.cast[float]([line.split()[3] for line in lines if ('MLv' in line) & (line.startswith('# '))]) - SFRv_template = np.cast[float]([line.split()[5] for line in lines if ('MLv' in line) & (line.startswith('# '))]) + MLv_template = np.asarray([line.split()[3] for line in lines if ('MLv' in line) & (line.startswith('# '))],dtype=float) + SFRv_template = np.asarray([line.split()[5] for line in lines if ('MLv' in line) & (line.startswith('# '))],dtype=float) irest = 1 # V #irest = 2 # J @@ -103,8 +103,8 @@ def go(): # These are masses lines = open(self.param['TEMPLATES_FILE']).readlines() - MLv_template = np.cast[float]([line.split()[4] for line in lines if line.startswith('# ')]) - SFRv_template = np.cast[float]([line.split()[5] for line in lines if line.startswith('# ')]) + MLv_template = np.asarray([line.split()[4] for line in lines if line.startswith('# ')],dtype=float) + SFRv_template = np.asarray([line.split()[5] for line in lines if line.startswith('# ')],dtype=float) MLv_template /= Lvt SFRv_template /= Lvt From 2e8f0c1c4b2d462a48df4c9d2157e456dcece479 Mon Sep 17 00:00:00 2001 From: Gabe Brammer Date: Wed, 26 Jun 2024 11:29:02 +0200 Subject: [PATCH 2/2] Fix bug --- eazy/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eazy/visualization.py b/eazy/visualization.py index 82ee8a0f..0dac59f9 100644 --- a/eazy/visualization.py +++ b/eazy/visualization.py @@ -1224,7 +1224,7 @@ def parse_id_input(id_input): if len(inp_split) == 1: return int(inp_split[0]), None - ra, dec = np.asarray(inp_split, dtype=float)float + ra, dec = np.asarray(inp_split, dtype=float) cosd = np.cos(self.df['dec']/180*np.pi) dx = (self.df['ra'] - ra)*cosd