In [1]:
import os
import numpy as np
import matplotlib.pyplot as plt
In [45]:
import fitsio
from astropy.table import Table
from astrometry.util.fits import fits_table
In [35]:
from legacypipe.runs import get_survey
from legacypipe.survey import bricks_touching_wcs, ccds_touching_wcs
from legacypipe.survey import LegacySurveyData
In [3]:
%matplotlib inline
In [16]:
output_dir = '/global/cscratch1/sd/ioannis/dr8/largest-gals'
SURVEY_DIR = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8'
LSLGA_DIR = '/global/project/projectdirs/cosmo/staging/largegalaxies/v2.0'
In [46]:
LSLGA = fits_table(os.path.join(LSLGA_DIR, 'LSLGA-v2.0.fits'))
In [11]:
def read_all_ccds(dr='dr8'):
"""Read the CCDs files, treating DECaLS and BASS+MzLS separately.
"""
from astrometry.libkd.spherematch import tree_open
#survey = LegacySurveyData()
kdccds_north = []
for camera in ('90prime', 'mosaic'):
ccdsfile = os.path.join(SURVEY_DIR, 'survey-ccds-{}-{}.kd.fits'.format(camera, dr))
ccds = tree_open(ccdsfile, 'ccds')
print('Read {} CCDs from {}'.format(ccds.n, ccdsfile))
kdccds_north.append((ccdsfile, ccds))
ccdsfile = os.path.join(SURVEY_DIR, 'survey-ccds-decam-{}.kd.fits'.format(dr))
ccds = tree_open(ccdsfile, 'ccds')
print('Read {} CCDs from {}'.format(ccds.n, ccdsfile))
kdccds_south = (ccdsfile, ccds)
return kdccds_north, kdccds_south
In [49]:
def simple_wcs(ra, dec, radius_arcmin, factor=1.0, pixscale=0.262):
'''Build a simple WCS object for a single galaxy.
'''
from astrometry.util.util import Tan
diam = np.ceil(factor * radius_arcmin * 60 / pixscale).astype('int') # [pixels]
#print(ra, dec, diam)
simplewcs = Tan(ra, dec, diam/2+0.5, diam/2+0.5,
-pixscale/3600.0, 0.0, 0.0, pixscale/3600.0,
float(diam), float(diam))
return simplewcs
In [50]:
#kdccds_north, kdccds_south = read_all_ccds()
In [51]:
big = LSLGA[LSLGA.galaxy == 'NGC5194'][0]
wcs = simple_wcs(big.ra, big.dec, big.d25, factor=1.2)
big
Out[51]:
In [52]:
survey = get_survey('90prime-mosaic', survey_dir=SURVEY_DIR, output_dir=output_dir)
In [57]:
ccds, bricks = survey.ccds_touching_wcs(wcs), bricks_touching_wcs(wcs, survey=survey)
In [60]:
len(ccds), len(np.unique(ccds.image_filename))
Out[60]:
In [56]:
plt.scatter(big.ra, big.dec, marker='x')
plt.scatter(ccds.ra, ccds.dec)
Out[56]:
In [ ]: