astro-datalab / notebooks-latest

Default set of Data Lab notebooks, by DL team and contributed by users
BSD 3-Clause "New" or "Revised" License
57 stars 48 forks source link

The LSS NB with my extension for 3D plotting #164

Closed kareninysimba closed 1 year ago

kareninysimba commented 1 year ago
rnikutta commented 1 year ago

@kareninysimba @jacquesalice @stephjuneau Could you please briefly review the new 3D plotting section in this NB? We'd like to merge it in time for the DL newsletter. I made some edits to David's version from yesterday (described in the commit log). Thank you!

stephjuneau commented 1 year ago

Planck2018 cosmology reference: https://ui.adsabs.harvard.edu/abs/2020A%26A...641A...6P/abstract

stephjuneau commented 1 year ago

Alright, I got a new query to work (though it takes ~20 sec now instead of ~1 sec):

# ls_dr10.tractor                            # LS DR10 tractor photometry
# ls_dr10.x1p5__tractor__sdss_dr17__specobj  # LS DR10 pre-crossmatched to SDSS DR17 specobj
# sdss_dr17.specobj                          # SDSS DR17 specobj

# Write query statement (sql)
query = ("""
  SELECT L.ra, L.dec, L.type, L.sersic, L.g_r, L.r_z,
         S.z, S.ra as plug_ra, S.dec as plug_dec, S.class, S.veldisp, S.veldisperr 
  FROM ls_dr10.tractor AS L
  JOIN ls_dr10.x1p5__tractor__sdss_dr17__specobj AS X ON L.ls_id=X.id1 
  JOIN sdss_dr17.specobj AS S ON X.id2 = S.specobjid 
  WHERE L.ra BETWEEN %s AND %s AND L.dec BETWEEN %s AND %s AND (L.ra_ivar > 0) 
  LIMIT 100000
  """) % (126,131,7.,12.)  # small region

# L.ra, L.dec        = RA, Dec from Legacy Survey (LS) table    
# L.type             = object type (PSF, SIMP, EXP, DEV, COMP)
# L.g_r, L.r_z       = pre-computed g-r and r-z colors from photometry
# S.z                = redshift (z) from SDSS specObj table
# S.plug_ra, dec     = RA, Dec of SDSS fiber from specObj table
# S.class            = Source class (Star, Galaxy, QSO) from SDSS
# S.veldisp, veldisp = velocity dispersion (and error) from SDSS specObj table
#
# WHERE: requirement that RA & Dec coordinates are within a rectangular region

print(query)

Because of the new "type" in LS DR10, the code needs to be changed for the plotting with the morphological types. This works well:

# Select redshift slice and per type

# DEV or early type Sersic with steep index Sersic>=3
rdev = np.where(((result['type']=='DEV')|((result['type']=='SER')&(result['sersic']>=3))) & (result['z'] >0.105) & (result['z']<0.125))
# EXP or late type Sersic with index Sersic<2
rexp = np.where(((result['type']=='EXP')|((result['type']=='SER')&(result['sersic']<2))) & (result['z'] >0.105) & (result['z']<0.125))
# Intermediate with 2<= Sersic < 3
rint = np.where(((result['type']=='SER')&(result['sersic']>=2)&(result['sersic']<3)) & (result['z'] >0.105) & (result['z']<0.125))

# plot all points in red (all redshifts)
ax2.scatter(result['plug_ra'],result['plug_dec'],s=3,color='gray',marker='o',alpha=0.25)

# overplot in objects in narrow redshift slice color-coded blue (EXP or Late type) or red (DEV or Early type)
ax2.scatter(result['plug_ra'][rexp],result['plug_dec'][rexp],s=15,color='b')         # blue = EXP or late-type Sersic
ax2.scatter(result['plug_ra'][rcomp],result['plug_dec'][rcomp],s=15,color='orange')  # orange = Intermediate
ax2.scatter(result['plug_ra'][rdev],result['plug_dec'][rdev],s=15,color='r')         # red = DEV or early-type Sersic

I tested this and it worked but let me know if you run into problems!

rnikutta commented 1 year ago

@stephjuneau could you please make a commit with your changes, on this branch? Easier than to have me or David add those changes.

stephjuneau commented 1 year ago

@rnikutta & @kareninysimba : I believe I made all the changes to take care of @jacquesalice 's comments and my comments. I also updated the html version. Ready for final approval and merging!

rnikutta commented 1 year ago

Thank you @stephjuneau . Since we are updating this NB, I want to propose a few more (minor) edits:

stephjuneau commented 1 year ago

Hi @rnikutta I just made all the new changes except that I don't see a hidden cell re: "It seems that the cell right under the 3-panel figure that shows Elliptical, Spiral, Quasar images is hidden by default. Expand it?". I just made a new HTML as well. Will push these new commits now.

stephjuneau commented 1 year ago

Done! By the way, I saved the HTML without the 3D plot to make it smaller but saving it with the rendered 3D plot is actually interactive as HTML. Maybe in the future we could create a version of the interactive 3D plot for the website for extra funsies :-)

rnikutta commented 1 year ago

Many thanks @stephjuneau ! Yep I don't see the hidden cell anymore either, must have been my butterfingers or something. Merging!