Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreicuceu committed Nov 18, 2023
1 parent 9dbcff2 commit c953971
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 221 deletions.
4 changes: 0 additions & 4 deletions bin/run_vega_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def print_func(message):
raise ValueError('You asked to run over a Monte Carlo simulation,'
' but no "[monte carlo]" section provided.')

# run compute_model once to initialize all the caches
# vega.set_fast_metals()
# _ = vega.compute_model(run_init=False)

# Run sampler
if vega.has_sampler:
print_func('Running the sampler')
Expand Down
104 changes: 0 additions & 104 deletions vega/correlation_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import numpy as np


class CorrelationItem:
"""Class for handling the info and config of
each correlation function component.
Expand All @@ -9,18 +6,6 @@ class CorrelationItem:
model_coordinates = None
dist_model_coordinates = None
data_coordinates = None
# _rp_rt_grid = None
# _r_mu_grid = None
# _z_grid = None
# _bin_size_rp_model = None
# _bin_size_rt_model = None
# _bin_size_rp_data = None
# _bin_size_rt_data = None
# rp_min_model = None
# rp_max_model = None
# rt_max_model = None
# num_bins_rp_model = None
# num_bins_rt_model = None

def __init__(self, config, model_pk=False):
"""
Expand Down Expand Up @@ -106,92 +91,3 @@ def init_coordinates(
self.data_coordinates = model_coordinates if data_coordinates is None else data_coordinates
self.dist_model_coordinates = (model_coordinates if dist_model_coordinates is None
else dist_model_coordinates)

# @property
# def r_mu_grid(self):
# return self._r_mu_grid

# @r_mu_grid.setter
# def r_mu_grid(self, r_mu_grid):
# self._r_mu_grid = np.array(r_mu_grid)
# assert (self._r_mu_grid[1] <= 1).all()
# assert (self._r_mu_grid[1] >= -1).all()

# # Compute rp/rt from r/mu
# rp_grid = self._r_mu_grid[0] * self._r_mu_grid[1]
# rt_grid = np.sqrt(self._r_mu_grid[0]**2 - rp_grid**2)

# # Save the rp/rt grid
# self._rp_rt_grid = np.array([rp_grid, rt_grid])

# @property
# def rp_rt_grid(self):
# return self._rp_rt_grid

# @rp_rt_grid.setter
# def rp_rt_grid(self, rp_rt_grid):
# self._rp_rt_grid = np.array(rp_rt_grid)

# # Compute r/mu from rp/rt
# r_grid = np.sqrt(self._rp_rt_grid[0]**2 + self._rp_rt_grid[1]**2)
# mu_grid = np.zeros(r_grid.size)
# w = r_grid > 0.
# mu_grid[w] = self._rp_rt_grid[0, w] / r_grid[w]

# # Save the r/mu grid
# self._r_mu_grid = np.array([r_grid, mu_grid])

# @property
# def z_grid(self):
# return self._z_grid

# @z_grid.setter
# def z_grid(self, z_grid):
# if not isinstance(z_grid, float):
# assert (z_grid >= 0).all() and (z_grid <= 10).all()
# self._z_grid = np.array(z_grid)
# else:
# assert z_grid >= 0 and z_grid <= 10
# self._z_grid = z_grid

# @property
# def bin_size_rp_model(self):
# if self._bin_size_rp_model is None:
# raise ValueError('You must set the value of "bin_size_rp_model" in vega.corr_items to '
# 'compute model without data.')
# return self._bin_size_rp_model

# @bin_size_rp_model.setter
# def bin_size_rp_model(self, bin_size_rp_model):
# self._bin_size_rp_model = bin_size_rp_model

# @property
# def bin_size_rt_model(self):
# if self._bin_size_rt_model is None:
# raise ValueError('You must set the value of "bin_size_rt_model" in vega.corr_items to '
# 'compute model without data.')
# return self._bin_size_rt_model

# @bin_size_rt_model.setter
# def bin_size_rt_model(self, bin_size_rt_model):
# self._bin_size_rt_model = bin_size_rt_model

# @property
# def bin_size_rp_data(self):
# if self._bin_size_rp_data is None:
# return self.bin_size_rp_model
# return self._bin_size_rp_data

# @bin_size_rp_data.setter
# def bin_size_rp_data(self, bin_size_rp_data):
# self._bin_size_rp_data = bin_size_rp_data

# @property
# def bin_size_rt_data(self):
# if self._bin_size_rt_data is None:
# return self.bin_size_rt_model
# return self._bin_size_rt_data

# @bin_size_rt_data.setter
# def bin_size_rt_data(self, bin_size_rt_data):
# self._bin_size_rt_data = bin_size_rt_data
90 changes: 0 additions & 90 deletions vega/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,89 +363,6 @@ def _read_dmat(self, dmat_path, cuts_config):

hdul.close()

Check warning on line 364 in vega/data.py

View check run for this annotation

Codecov / codecov/patch

vega/data.py#L364

Added line #L364 was not covered by tests

# self.rp_min_model = header['RPMIN']
# self.rp_max_model = header['RPMAX']
# self.rt_max_model = header['RTMAX']
# self.coeff_binning_model = header['COEFMOD']
# self.num_bins_rp_model = header['NP'] * self.coeff_binning_model
# self.num_bins_rt_model = header['NT'] * self.coeff_binning_model

# Get the model bin size
# TODO If RTMIN is ever added to the cf data files this needs modifying
# self.bin_size_rp_model = (self.rp_max_model - self.rp_min_model) / self.num_bins_rp_model
# self.bin_size_rt_model = self.rt_max_model / self.num_bins_rt_model

# if ((self.bin_size_rp_model != self.bin_size_rp_data)
# or (self.bin_size_rt_model != self.bin_size_rt_data)):
# rp_custom_grid = np.arange(self.rp_min_model + self.bin_size_rp_data / 2,
# self.rp_max_model, self.bin_size_rp_data)
# rt_custom_grid = np.arange(self.bin_size_rt_data / 2,
# self.rt_max_model, self.bin_size_rt_data)

# rt_custom_grid, rp_custom_grid = np.meshgrid(rt_custom_grid, rp_custom_grid)

# self.model_mask = self._build_mask(
# rp_custom_grid.flatten(), rt_custom_grid.flatten(), cuts_config, self.rp_min_model,
# self.bin_size_rp_data, self.bin_size_rt_data
# )
# self.rp_rt_custom_grid = np.r_[rp_custom_grid, rt_custom_grid]
# else:
# self.model_mask = self._build_mask(
# rp_grid, rt_grid, cuts_config, self.rp_min_model,
# self.bin_size_rp_data, self.bin_size_rt_data
# )

# return rp_grid, rt_grid, z_grid

# def _build_mask(self, rp_grid, rt_grid, cuts_config, rp_min, bin_size_rp, bin_size_rt):
# """Build the mask for the data by comparing
# the cuts from config with the data limits.

# Parameters
# ----------
# rp_grid : 1D Array
# Vector of data rp coordinates
# rt_grid : 1D Array
# Vector of data rt coordinates
# cuts_config : ConfigParser
# cuts section from config
# header : fits header
# Data file header

# Returns
# -------
# (ND Array, float, float)
# Mask, Bin size in rp, Bin size in rt
# """
# # Read the cuts
# rp_min_cut = cuts_config.getfloat('rp-min', 0.)
# rp_max_cut = cuts_config.getfloat('rp-max', 200.)

# rt_min_cut = cuts_config.getfloat('rt-min', 0.)
# rt_max_cut = cuts_config.getfloat('rt-max', 200.)

# self.r_min_cut = cuts_config.getfloat('r-min', 10.)
# self.r_max_cut = cuts_config.getfloat('r-max', 180.)

# self.mu_min_cut = cuts_config.getfloat('mu-min', -1.)
# self.mu_max_cut = cuts_config.getfloat('mu-max', +1.)

# # Compute bin centers
# bin_index_rp = np.floor((rp_grid - rp_min) / bin_size_rp)
# bin_center_rp = rp_min + (bin_index_rp + 0.5) * bin_size_rp
# bin_center_rt = (np.floor(rt_grid / bin_size_rt) + 0.5) * bin_size_rt

# bin_center_r = np.sqrt(bin_center_rp**2 + bin_center_rt**2)
# bin_center_mu = bin_center_rp / bin_center_r

# # Build the mask by comparing the data bins to the cuts
# mask = (bin_center_rp > rp_min_cut) & (bin_center_rp < rp_max_cut)
# mask &= (bin_center_rt > rt_min_cut) & (bin_center_rt < rt_max_cut)
# mask &= (bin_center_r > self.r_min_cut) & (bin_center_r < self.r_max_cut)
# mask &= (bin_center_mu > self.mu_min_cut) & (bin_center_mu < self.mu_max_cut)

# return mask

def _init_metal_tracers(self, metal_config):
assert ('in tracer1' in metal_config) or ('in tracer2' in metal_config)

Expand Down Expand Up @@ -516,9 +433,6 @@ def _init_metals(self, metal_config):

self.metal_mats = {}
self.metal_coordinates = {}
# self.metal_rp_grids = {}
# self.metal_rt_grids = {}
# self.metal_z_grids = {}

# Read the metal file
metal_hdul = fits.open(find_file(metal_config.get('filename')))
Expand Down Expand Up @@ -619,10 +533,6 @@ def _read_metal_correlation(self, metal_hdul, tracers, name, dm_prefix):
z_grid=metal_hdul[2].data['Z_' + name]
)

# self.metal_rp_grids[tracers] = metal_hdul[2].data['RP_' + name]
# self.metal_rt_grids[tracers] = metal_hdul[2].data['RT_' + name]
# self.metal_z_grids[tracers] = metal_hdul[2].data['Z_' + name]

metal_mat_size = self.metal_coordinates[tracers].rp_grid.size

dm_name = dm_prefix + name
Expand Down
15 changes: 0 additions & 15 deletions vega/metals.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ def __init__(self, corr_item, fiducial, scale_params, PktoXi_obj, data=None):
else:
# Read rp and rt for the metal correlation
metal_coordinates = data.metal_coordinates[(name1, name2)]
# rp_grid = data.metal_rp_grids[(name1, name2)]
# rt_grid = data.metal_rt_grids[(name1, name2)]
# z_grid = data.metal_z_grids[(name1, name2)]

# Compute the corresponding r/mu coords
# r_grid = np.sqrt(rp_grid**2 + rt_grid**2)
# mask = r_grid != 0
# mu_grid = np.zeros(len(r_grid))
# mu_grid[mask] = rp_grid[mask] / r_grid[mask]

# Initialize the coords grid dictionary
# coords_grid = {}
# coords_grid['r'] = r_grid
# coords_grid['mu'] = mu_grid
# coords_grid['z'] = z_grid

# Get bin sizes
if self._data is not None:
Expand Down
4 changes: 0 additions & 4 deletions vega/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def __init__(self, corr_item, fiducial, scale_params, data=None):
self._model_pk = corr_item.model_pk

assert corr_item.model_coordinates is not None
# self._coords_grid = {}
# self._coords_grid['r'] = corr_item.r_mu_grid[0]
# self._coords_grid['mu'] = corr_item.r_mu_grid[1]
# self._coords_grid['z'] = corr_item.z_grid

self._data = data
data_has_distortion = False
Expand Down
4 changes: 0 additions & 4 deletions vega/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ def _bestfit_hdu(self, minimizer):
bestfit_hdu.name = 'Bestfit'

# Add all the attributes of the minimum to the header
# for item, value in minimizer.fmin.items():
# name = item
# if len(item) > 8:
# name = 'hierarch ' + item
bestfit_hdu.header['FVAL'] = minimizer.fmin.fval
bestfit_hdu.header['VALID'] = minimizer.minuit.valid
bestfit_hdu.header['ACCURATE'] = minimizer.minuit.accurate
Expand Down

0 comments on commit c953971

Please sign in to comment.