Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
KostasValeckas authored Jun 26, 2024
2 parents 1b993f2 + 7d4b268 commit 6123ece
Show file tree
Hide file tree
Showing 28 changed files with 1,012 additions and 202 deletions.
4 changes: 2 additions & 2 deletions grizli/aws/aws_drizzler.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def segmentation_figure(label, cat, segfile):
blot_seg = utils.blot_nearest_exact(seg_data, seg_wcs, th_wcs,
stepsize=-1, scale_by_pixel_area=False)

rnd_seg = rnd_ids[np.cast[int](blot_seg)]*1.
rnd_seg = rnd_ids[np.asarray(blot_seg,dtype=int)]*1.
th_ids = np.unique(blot_seg)

sh = th[0].data.shape
Expand Down Expand Up @@ -521,7 +521,7 @@ def segmentation_figure(label, cat, segfile):
plt.close(fig)

# Append to thumbs file
seg_hdu = pyfits.ImageHDU(data=np.cast[int](blot_seg), name='SEG')
seg_hdu = pyfits.ImageHDU(data=np.asarray(blot_seg,dtype=int), name='SEG')
if 'SEG' in th:
th.pop('SEG')

Expand Down
18 changes: 9 additions & 9 deletions grizli/aws/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def add_oned_spectra(root='j214224m4420gr01', bucket='grizli-v2', engine=None):

resp = fresp[sel]

norm_ix = np.cast[int](np.round(np.interp(wnorm*(1+resp['z_map']), wave, np.arange(len(wave)), left=np.nan, right=np.nan)))
norm_ix = np.asarray(np.round(np.interp(wnorm*(1+resp['z_map']), wave, np.arange(len(wave)), left=np.nan, right=np.nan)),dtype=int)

resp.sort_values(sort_column, inplace=True)

Expand All @@ -781,8 +781,8 @@ def add_oned_spectra(root='j214224m4420gr01', bucket='grizli-v2', engine=None):

# Rest-frame
dz = np.diff(wave)[10]/wave[10]
max_zshift = np.cast[int](np.log(1+resp['z_map'].max())/dz)
zshift = np.cast[int]((np.log(1+resp['z_map']) - np.log(1+zref))/dz)
max_zshift = np.asarray(np.log(1+resp['z_map'].max())/dz,dtype=int)
zshift = np.asarray((np.log(1+resp['z_map']) - np.log(1+zref))/dz,dtype=int)

err_max = 5

Expand Down Expand Up @@ -1410,7 +1410,7 @@ def multibeam_to_database(beams_file, engine=None, Rspline=15, force=False, **kw

dtype[c[:-1]+'_p'] = types.ARRAY(types.FLOAT)

data[c[:-1]+'_p'] = [list(np.cast[float](line.strip()[1:-1].split(','))) for line in df[c]]
data[c[:-1]+'_p'] = [list(np.asarray(line.strip()[1:-1].split(','),dtype=float)) for line in df[c]]

data.to_sql('multibeam_tmp', engine, index=False, if_exists='append', method='multi')

Expand Down Expand Up @@ -2491,7 +2491,7 @@ def query_from_ds9(ds9, radius=5, engine=None, extra_cols=['mag_auto', 'z_map',
if engine is None:
engine = get_db_engine(echo=False)

ra, dec = np.cast[float](ds9.get('pan fk5').split())
ra, dec = np.asarray(ds9.get('pan fk5').split(),dtype=float)
dd = radius/3600.
dr = dd/np.cos(dec/180*np.pi)

Expand Down Expand Up @@ -2731,9 +2731,9 @@ def get_exposure_info():
print(file)
_q = Table.read(file, character_as_bytes=False)

_q['proposal_id'] = np.cast[np.int16](_q['proposal_id'])
_q['obsid'] = np.cast[np.int64](_q['obsid'])
_q['objID'] = np.cast[np.int64](_q['objID'])
_q['proposal_id'] = np.asarray(_q['proposal_id'],dtype=np.int16)
_q['obsid'] = np.asarray(_q['obsid'],dtype=np.int64)
_q['objID'] = np.asarray(_q['objID'],dtype=np.int64)
_q.rename_column('ra','target_ra')
_q.rename_column('dec','target_dec')
_q.rename_column('footprint', 'sregion')
Expand All @@ -2750,7 +2750,7 @@ def get_exposure_info():
print(i, file)
_p = Table.read(file, character_as_bytes=False)

_p['obsid'] = np.cast[np.int64](_p['obsid'])
_p['obsid'] = np.asarray(_p['obsid'],dtype=np.int64)
_p['dataset'] = [d[:-1] for d in _p['observation_id']]

df = _p[cols].to_pandas()
Expand Down
181 changes: 174 additions & 7 deletions grizli/aws/define_mosaics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
elgordo
mrg0138
miri-gto
ulasj1342
sunburst
#PEARLS
gama100033
clg-1212p2733
plck-g165p67
plck-g191p62
tn-j1338m1942
abell1689
""".split()

__all__ = ['AVAILABLE_FIELDS', 'make_wcs', 'show_field_footprint']
Expand Down Expand Up @@ -274,7 +283,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
# Centered
rc, dc = 3.4573691, -30.3660376

xc, yc = np.cast[int](np.round(np.squeeze(xivo_wcs.all_world2pix([rc], [dc], 0))))
xc, yc = np.asarray(np.round(np.squeeze(xivo_wcs.all_world2pix([rc], [dc], 0))),dtype=int)
#print('xxx', xc, yc, NP)

NX = 5*2048
Expand All @@ -288,7 +297,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
# New pointing fully including GLASS + UNCOVER/NIS
rc, dc = 3.4793842, -30.3562169

xc, yc = np.cast[int](np.round(np.squeeze(xivo_wcs.all_world2pix([rc], [dc], 0))))
xc, yc = np.asarray(np.round(np.squeeze(xivo_wcs.all_world2pix([rc], [dc], 0))),dtype=int)
#print('xxx', xc, yc, NP)

NX = 6*2048
Expand Down Expand Up @@ -689,7 +698,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
# Slices
llr, lld = w.all_pix2world([0],[0], 0)
ll = np.squeeze(full_wcs.all_world2pix(llr, lld, 0))
llx, lly = np.cast[int](np.floor(ll))
llx, lly = np.asarray(np.floor(ll),dtype=int)

wh = utils.get_wcs_slice_header(full_wcs,
slice(llx, llx+NX*2048),
Expand Down Expand Up @@ -998,7 +1007,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
root = f'abell370-{fi}-grizli-v6.0'
root = f'abell370-{fi}-grizli-{version}'

xi, yi = np.cast[int](np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)))
xi, yi = np.asarray(np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)),dtype=int)

wh = utils.get_wcs_slice_header(full_wcs,
slice(xi-int(nnx*2048), xi+int(nnx*2048)),
Expand Down Expand Up @@ -1039,7 +1048,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
root = f'macs0416-{fi}-grizli-v6.0'
root = f'macs0416-{fi}-grizli-{version}'

xi, yi = np.cast[int](np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)))
xi, yi = np.asarray(np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)),dtype=int)

wh = utils.get_wcs_slice_header(full_wcs,
slice(xi-int(nnx*2048), xi+int(nnx*2048)),
Expand Down Expand Up @@ -1084,7 +1093,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
root = f'macs1423-{fi}-grizli-v6.0' # stripe fixes, etc.
root = f'macs1423-{fi}-grizli-{version}'

xi, yi = np.cast[int](np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)))
xi, yi = np.asarray(np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)),dtype=int)

wh = utils.get_wcs_slice_header(full_wcs,
slice(xi-int(nnx*2048), xi+int(nnx*2048)),
Expand Down Expand Up @@ -1137,7 +1146,7 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):
root = f'macs1149-{fi}-grizli-v6.1' # Chris level 1
root = f'macs1149-{fi}-grizli-{version}'

xi, yi = np.cast[int](np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)))
xi, yi = np.asarray(np.squeeze(full_wcs.all_world2pix([r0], [d0], 0)),dtype=int)

wh = utils.get_wcs_slice_header(full_wcs,
slice(xi-int(nnx*2048), xi+int(nnx*2048)),
Expand Down Expand Up @@ -1299,6 +1308,164 @@ def make_wcs(mosaic_field='primer_uds', version='v7.0', canucs_subfield='clu'):

ref_file = w

elif mosaic_field == 'ulasj1342':

# ULAS-J1342
NX, NY, ra, dec = 4.5, 7.5, 205.555, 9.462

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'ulasj1342-grizli-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'sunburst':

# ULAS-J1342
NX, NY, ra, dec = 4, 4, 237.5297488, -78.1917476

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'sunburst-grizli-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'cosmos-transients':
NX, NY, ra, dec = 5, 5, 150.1250419, 2.3661324

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'cosmos-transients-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

## PEARLS fields
elif mosaic_field == 'gama100033':
NX, NY, ra, dec = 3, 5, 130.58659471, 1.61764667

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'gama100033-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'clg-1212p2733':
NX, NY, ra, dec = 3, 5, 183.08573496, 27.57669020

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'clg-1212p2733-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'plck-g165p67':
NX, NY, ra, dec = 5, 4, 171.78782682, 42.47523529

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'plck-g165p67-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'plck-g191p62':
NX, NY, ra, dec = 5, 5, 161.16195126, 33.83078874

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'plck-g191p62-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'tn-j1338m1942':
NX, NY, ra, dec = 4, 5, 204.61036521, -19.67247443

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'tn-j1338m1942-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

elif mosaic_field == 'abell1689':
NX, NY, ra, dec = 4, 4, 197.8765, -1.33

hdu = utils.make_wcsheader(ra=ra, dec=dec,
size=(NX*2048*0.04, NY*2048*0.04),
pixscale=0.04, theta=0., get_hdu=True)

hdu.header['CRPIX1'] = NX*2048//2
hdu.header['CRPIX2'] = NY*2048//2
w = pywcs.WCS(hdu.header)

root = f'abell1689-grizli-{version}'

print(root, hdu.data.shape, w.pixel_shape)

ref_file = w

else:
raise ValueError(f'Field {mosaic_field} not defined')

Expand Down
Loading

0 comments on commit 6123ece

Please sign in to comment.