Skip to content

Commit

Permalink
ENH add DES gal cat
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed May 9, 2024
1 parent 2636313 commit 2065d88
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- astropy
- pandas
- des-eastlake
- des-y6utils
- galsim_extra
- importlib_metadata
- cfitsio # for fpack
Expand Down
1 change: 1 addition & 0 deletions montara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from . import badpixfromfits # noqa
from . import eastlake_step # noqa
from . import eval_gsobject # noqa
from . import input_desgal # noqa
55 changes: 55 additions & 0 deletions montara/input_desgal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import galsim
import numpy as np
from galsim.config.input import InputLoader, RegisterInputType, GetInputObj
from galsim.config.value import RegisterValueType
import fitsio
from .utils import add_field


class DESGalCatalog(object):
_req_params = {'file_name': str}
_single_params = []
_takes_rng = False

def __init__(self, file_name, mag_i_col='mag_i', mag_i_max=None, mag_i_min=None,
_nobjects_only=False):
self.gal_data = fitsio.read(file_name)
self.gal_data = add_field(
self.gal_data, [("catalog_row", int)],
[np.arange(len(self.gal_data))],
)
self.nobjects = len(self.gal_data)

def get(self, index, col):
return self.gal_data[index][col]

def getNObjects(self):
return self.nobjects


def _GenerateFromDESGalCatalog(config, base, value_type):
"""@brief Return a value read from an input catalog
"""
gal_input = GetInputObj('desgal', config, base, 'DESGalValue')

# Setup the indexing sequence if it hasn't been specified.
# The normal thing with a Catalog is to just use each object in order,
# so we don't require the user to specify that by hand. We can do it for them.
galsim.config.SetDefaultIndex(config, gal_input.getNObjects())

req = {'col': str, 'index': int}
opt = {'num': int}
kwargs, safe = galsim.config.GetAllParams(config, base, req=req, opt=opt)
col = kwargs['col']
index = kwargs['index']
val = gal_input.get(index, col)
return val, safe


RegisterInputType('desgal', InputLoader(DESGalCatalog, has_nobj=True))
RegisterValueType(
'DESGalValue',
_GenerateFromDESGalCatalog,
[float],
input_type='desgal',
)

0 comments on commit 2065d88

Please sign in to comment.