Skip to content

Commit

Permalink
Added extended fit range features
Browse files Browse the repository at this point in the history
  • Loading branch information
kfanning committed Jun 12, 2023
1 parent d2a243d commit 4374947
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions bin/make_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
parser.add_argument('--version', '-v', default=0, help='catalog version, for mocks this is mock number')
parser.add_argument('--impversion', '-i', default=None, help='override version for imputation, default None == same as version')
parser.add_argument('--physical', '-p', action='store_true', help='Set flag to use physical units (S_perp, R) instead of Z and angular distance.')
parser.add_argument('--extend', '-e', action='store_true', help='Set flag to extend plotting range from +/- 22.5 to +/- 45')
#parser.add_argument('--fit_type', '-ft', default='gauss', type=str, help='Type of fit to use (gauss, quad or lorentz)')

uargs = parser.parse_args()
Expand Down Expand Up @@ -46,7 +47,7 @@
fig.savefig(f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_N_clusfrac.pdf')
plt.close(fig)
mode = 'physical' if uargs.physical else None
figs = plotter.imputation_fits(mode=mode)
figs = plotter.imputation_fits(mode=mode, extended=uargs.extend)
filename = f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_N_model_bins.pdf'
with PdfPages(filename) as pdf:
for fig in figs:
Expand All @@ -64,7 +65,7 @@
fig.savefig(f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_S_clusfrac.pdf')
plt.close(fig)
mode = 'physical' if uargs.physical else None
figs = plotter.imputation_fits(mode=mode)
figs = plotter.imputation_fits(mode=mode, extended=uargs.extend)
filename = f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_S_model_bins.pdf'
with PdfPages(filename) as pdf:
for fig in figs:
Expand Down
5 changes: 3 additions & 2 deletions bin/run_imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
parser.add_argument('--radial_bins', '-rb', default=15, type=int, help='Number of radial bins to use')
parser.add_argument('--perp_bins', '-pb', default=18, type=int, help='Number of perpendicular bins to use')
parser.add_argument('--fit_type', '-ft', default='gauss', type=str, help='Type of fit to use (gauss, quad or lorentz)')
parser.add_argument('--extend', '-e', action='store_true', help='Set flag to extend fitting range from +/- 22.5 to +/- 45')
# add dir management
# catdir (for base catalogs for reading, no writing)
# temp dir (intermediate files like logging, nn cats, etc)
Expand Down Expand Up @@ -73,15 +74,15 @@

#run imputation
impn = impute.ImputeModel(obs_nncat_n, mis_nncat_n, tracer=uargs.tracer)
impn_cat = impn.run(skip_background=uargs.nobackground, physical=uargs.physical, fit=uargs.fit, rbins=uargs.radial_bins, angbins=uargs.perp_bins, fit_type=uargs.fit_type)
impn_cat = impn.run(skip_background=uargs.nobackground, physical=uargs.physical, fit=uargs.fit, rbins=uargs.radial_bins, angbins=uargs.perp_bins, fit_type=uargs.fit_type, extended=uargs.extend)
figs = impn.figs
filename = f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_N_model_bins_live.pdf'
with PdfPages(filename) as pdf:
for fig in figs:
pdf.savefig(fig)
plt.close(fig)
imps = impute.ImputeModel(obs_nncat_s, mis_nncat_s, tracer=uargs.tracer)
imps_cat = imps.run(skip_background=uargs.nobackground, physical=uargs.physical, fit=uargs.fit, rbins=uargs.radial_bins, angbins=uargs.perp_bins, fit_type=uargs.fit_type)
imps_cat = imps.run(skip_background=uargs.nobackground, physical=uargs.physical, fit=uargs.fit, rbins=uargs.radial_bins, angbins=uargs.perp_bins, fit_type=uargs.fit_type, extended=uargs.extend)
figs = imps.figs
filename = f'{stagedir}/{uargs.tracer}_{uargs.survey}_{uargs.version}_S_model_bins_live.pdf'
with PdfPages(filename) as pdf:
Expand Down
4 changes: 2 additions & 2 deletions py/lssimpute/impute.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def bin_sperp(self, nbins=18):
self.sperp_misbins = np.extract(maskb, self.sperp_misbins)
self.sperp_edges = np.extract(maske, self.sperp_edges)
self.sperp_clusbins = np.extract(maskb, self.sperp_clusbins)
else:
elif nbins>1:
bins = np.linspace(0, 2. + 2./(nbins-1), nbins+1)
bins[-1] = maxbin
self.sperp_misbins, self.sperp_edges = np.histogram(self.misscat['sperp_n0'], bins=bins)
Expand Down Expand Up @@ -178,7 +178,7 @@ def bin_r(self, nbins=15):
self.r_misbins = np.extract(mask, self.r_misbins)
self.r_clusbins = np.extract(mask, self.r_clusbins)
self.r_edges = np.extract(mask2, self.r_edges)
else:
elif nbins>1:
r_bounds = self.cosmo.comoving_radial_distance(self.tracer_bounds)
bdiff = r_bounds[1] - r_bounds[0]
bins = np.linspace(r_bounds[0], r_bounds[1], nbins+1)
Expand Down
10 changes: 7 additions & 3 deletions py/lssimpute/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def fraction_bin(self):
def imputation_bins(self):
return

def imputation_fits(self, catver='observed', mode='physical'):
def imputation_fits(self, catver='observed', mode='physical', extended=False):
'''
'''
if mode == 'physical':
Expand All @@ -112,6 +112,10 @@ def imputation_fits(self, catver='observed', mode='physical'):
pcatcol = 'angdist_n0'
rcatcol = 'z_n0'
backg = 0.01
nbins=50
if extended:
nbins = nbins*2
backg = backg*2
cat = self.cats[catver]
rdiffs = cat[rname] - cat[f'{rname.lower()}_n0']
rmins = list(self.imputedetails[f'MIN_{rname}'])
Expand Down Expand Up @@ -140,8 +144,8 @@ def imputation_fits(self, catver='observed', mode='physical'):
clusmask = (rdiffs < backg) & (rdiffs > -1*backg)
clus = rdiffs[clusmask]
back = rdiffs[~clusmask]
cbbins, cbedges = np.histogram(back, bins=50, density=False)
ccbins, ccedges = np.histogram(clus, bins=50, density=False)
cbbins, cbedges = np.histogram(back, bins=nbins, density=False)
ccbins, ccedges = np.histogram(clus, bins=nbins, density=False)
y1 = cbbins
y2 = ccbins
if fitt[i] == 'gauss':
Expand Down

0 comments on commit 4374947

Please sign in to comment.