Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove OM10 dependence #497

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/desc/twinkles/sprinkler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from __future__ import absolute_import, division, print_function
from future.utils import iteritems
import time
import om10
import numpy as np
import re
import json
Expand All @@ -15,6 +14,7 @@
import copy
import gzip
import shutil
from astropy.io import fits
from lsst.utils import getPackageDir
from lsst.sims.utils import SpecMap, defaultSpecMap
from lsst.sims.catUtils.baseCatalogModels import GalaxyTileCompoundObj
Expand Down Expand Up @@ -104,8 +104,8 @@ def __init__(self, catsim_cat, visit_mjd, specFileMap, sed_path,
self.write_sn_sed = write_sn_sed
self.catalog_column_names = catsim_cat.dtype.names
# ****** THIS ASSUMES THAT THE ENVIRONMENT VARIABLE OM10_DIR IS SET *******
lensdb = om10.DB(catalog=om10_cat, vb=False)
self.lenscat = lensdb.lenses.copy()
lensdb = fits.open(om10_cat)
self.lenscat = lensdb[1].data.copy()
self.density_param = density_param
self.bandpassDict = BandpassDict.loadTotalBandpassesFromFiles(bandpassNames=['i'])
self.lsst_band_indexes = {'u':0, 'g':1, 'r':2, 'i':3, 'z':4, 'y':5}
Expand Down
48 changes: 27 additions & 21 deletions python/desc/twinkles/validation/validate_ic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import sqlite3
import om10
import pandas as pd
import numpy as np
import gzip
import shutil
import copy
import json
from astropy.io import fits
from lsst.utils import getPackageDir
import lsst.sims.utils.htmModule as htm
from lsst.sims.photUtils import Bandpass, BandpassDict, Sed, getImsimFluxNorm
Expand Down Expand Up @@ -449,7 +449,9 @@ def compare_agn_location(self, spr_agn_df, spr_agn_lens_df):
msg += "len(spr_agn_lens_df): %d\n" % len(spr_agn_lens_df)
raise RuntimeError(msg)
return
db = om10.DB(catalog=self.sprinkled_agn_data, vb=False)

db = fits.open(self.sprinkled_agn_data)
lensdb = db[1].data

x_offsets = []
y_offsets = []
Expand All @@ -460,9 +462,9 @@ def compare_agn_location(self, spr_agn_df, spr_agn_lens_df):
u_id = lens_gal_df['uniqueId']

spr_sys_df = spr_agn_df.query('lens_galaxy_uID == %i' % u_id)
use_lens = db.lenses['LENSID'][np.where(db.lenses['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]]
lens = db.get_lens(use_lens)
use_lens = np.where(lensdb['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]
lens = lensdb[use_lens]
num_img = lens['NIMG']

for img_idx in range(num_img[0]):
Expand Down Expand Up @@ -612,7 +614,8 @@ def compare_agn_inputs(self, spr_agn_df, spr_agn_lens_df):
raise RuntimeError(msg)
return

db = om10.DB(catalog=self.sprinkled_agn_data, vb=False)
db = fits.open(self.sprinkled_agn_data)
lensdb = db[1].data

errors_present = False
phi_error = False
Expand All @@ -630,9 +633,9 @@ def compare_agn_inputs(self, spr_agn_df, spr_agn_lens_df):
u_id = lens_gal_df['uniqueId']

spr_sys_df = spr_agn_df.query('lens_galaxy_uID == %i' % u_id)
use_lens = db.lenses['LENSID'][np.where(db.lenses['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]]
lens = db.get_lens(use_lens)
use_lens = np.where(lensdb['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]
lens = lensdb[use_lens]

# These should just be different by a minus sign
if np.abs(lens['PHIE'] + lens_gal_df['positionAngle']) > 0.005:
Expand Down Expand Up @@ -821,7 +824,8 @@ def compare_agn_lens_mags(self, spr_agn_df, spr_agn_lens_df, bandpass_name):
raise RuntimeError(msg)
return

db = om10.DB(catalog=self.sprinkled_agn_data, vb=False)
db = fits.open(self.sprinkled_agn_data)
lensdb = db[1].data

lens_mag_error = []

Expand All @@ -838,9 +842,10 @@ def compare_agn_lens_mags(self, spr_agn_df, spr_agn_lens_df, bandpass_name):
u_id = lens_gal_df['uniqueId']

spr_sys_df = spr_agn_df.query('lens_galaxy_uID == %i' % u_id)
use_lens = db.lenses['LENSID'][np.where(db.lenses['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]]
lens = db.get_lens(use_lens)
use_lens = np.where(lensdb['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]
lens = lensdb[use_lens]

num_img = lens['NIMG']

# Because we allow magNorm to change between
Expand Down Expand Up @@ -1082,7 +1087,8 @@ def compare_agn_image_mags(self, spr_agn_df, spr_agn_lens_df, visit_mjd,
raise RuntimeError(msg)
return

db = om10.DB(catalog=self.sprinkled_agn_data, vb=False)
db = fits.open(self.sprinkled_agn_data)
lensdb = db[1].data

agnSpecDir = 'agnSED'
agnDir = str(getPackageDir('sims_sed_library') + '/' + agnSpecDir)
Expand All @@ -1101,19 +1107,19 @@ def compare_agn_image_mags(self, spr_agn_df, spr_agn_lens_df, visit_mjd,

spr_sys_df = spr_agn_df.query('lens_galaxy_uID == %i' % u_id)
agn_id = spr_sys_df['galaxy_id']
use_lens = db.lenses['LENSID'][np.where(db.lenses['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]]
lens = db.get_lens(use_lens)
num_img = lens['NIMG']
use_lens = np.where(lensdb['twinklesId'] ==
spr_sys_df['twinkles_system'].iloc[0])[0]
lens = lensdb[use_lens]
num_img = lens['NIMG'][0]

mag = lens['MAG'].data[0]
mag = lens['MAG'][0]
lensed_mags = spr_sys_df['phosimMagNorm']
corrected_mags = []

for i in range(num_img.data[0]):
for i in range(num_img):

d_mags = self.get_agn_variability_mags(agn_var_params[str(agn_id.values[0])],
lens['DELAY'].data[0][i], visit_mjd,
lens['DELAY'][0][i], visit_mjd,
spr_sys_df['redshift'].values[0])


Expand Down