-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from LSSTDESC/u/jchiang/instcat_bug_fixes
bug-fixes and added flag to disable proper motion
- Loading branch information
Showing
11 changed files
with
8,231 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pandas as pd | ||
|
||
df = pd.read_pickle('protoDC2_visits.pkl') | ||
|
||
for filt in 'ugrizy': | ||
df_filt = df.query('filter=="%s"' % filt) | ||
df_filt.sort_values('expMJD') | ||
with open('protoDC2_visits_%s-band.txt' % filt, 'w') as output: | ||
for irow in df_filt.index: | ||
output.write('%i %s\n' % (df_filt.loc[irow]['obsHistID'], | ||
df_filt.loc[irow]['expMJD'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
import gzip | ||
|
||
plt.ion() | ||
|
||
def plot_galaxies(catalog, limit=1000000, alpha=0.01, color='grey'): | ||
ra, dec = [], [] | ||
with gzip.open(catalog) as input_: | ||
for i, line in enumerate(input_): | ||
if i > limit: | ||
break | ||
tokens = line.split() | ||
ra_val = float(tokens[2]) | ||
if ra_val > 180: | ||
ra_val -= 360. | ||
ra.append(ra_val) | ||
dec.append(float(tokens[3])) | ||
plt.errorbar(ra, dec, fmt='.', alpha=alpha, color=color) | ||
|
||
def plot_visits(df, xname, yname, side=2.5, ms=2, alpha=1): | ||
for filt in 'ugrizy': | ||
band = df.query('filter=="%s"' % filt) | ||
label = '%s band, %i visits' % (filt, len(band)) | ||
plt.errorbar(band[xname], band[yname], fmt='.', label=label, ms=ms, | ||
alpha=alpha) | ||
plt.xlabel(xname) | ||
plt.ylabel(yname) | ||
plt.legend(fontsize='x-small', loc=0) | ||
plt.plot((-side, -side, side, side, -side), | ||
(-side, side, side, -side, -side)) | ||
|
||
df = pd.read_pickle('protoDC2_visits.pkl') | ||
|
||
plt.figure() | ||
plot_galaxies('gal_cat_138143.txt.gz') | ||
plot_visits(df, 'randomDitherFieldPerVisitRA', 'randomDitherFieldPerVisitDec') | ||
|
||
plt.title('minion_1016_sqlite_new_dithers.db, %i total visits' % len(df)) | ||
plt.savefig('protoDC2_visits.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import pickle | ||
import numpy as np | ||
import pandas as pd | ||
from lsst.sims.catUtils.utils import ObservationMetaDataGenerator | ||
|
||
def fov_overlaps_protoDC2(x, y, half_size=2.5, radius=1.77): | ||
if x > half_size and y > half_size: | ||
return (x - half_size)**2 + (y - half_size)**2 < radius**2 | ||
elif x < -half_size and y > half_size: | ||
return (x + half_size)**2 + (y - half_size)**2 < radius**2 | ||
elif x < -half_size and y < -half_size: | ||
return (x + half_size)**2 + (y + half_size)**2 < radius**2 | ||
elif x > half_size and y < -half_size: | ||
return (x - half_size)**2 + (y + half_size)**2 < radius**2 | ||
outer_box_size = half_size + radius | ||
return (-outer_box_size < x and x < outer_box_size and | ||
-outer_box_size < y and y < outer_box_size) | ||
|
||
opsim_db = 'minion_1016_sqlite_new_dithers.db' | ||
obs_gen = ObservationMetaDataGenerator(opsim_db) | ||
|
||
# Inclusive fov is 2.1 deg radius; protoDC2 is 5x5 box centered on | ||
# (RA, Dec) = (0, 0), with vertical sides aligned N-S and horizontal | ||
# sides aligned E-W. Use 20x20 box to ensure all viable dithered | ||
# visits are considered | ||
dxy = 10 | ||
fov = 2.1 | ||
radius = fov | ||
obs_list = obs_gen.getObservationMetaData(fieldRA=(0, dxy), | ||
fieldDec=(-dxy, dxy), | ||
boundLength=radius) | ||
obs_list.extend(obs_gen.getObservationMetaData(fieldRA=(360-dxy, 360.), | ||
fieldDec=(-dxy, dxy), | ||
boundLength=radius)) | ||
|
||
df = pd.DataFrame(columns=['obsHistID', 'fieldRA', 'fieldDec', | ||
'randomDitherFieldPerVisitRA', | ||
'randomDitherFieldPerVisitDec', | ||
'filter', 'fieldID', 'propID', 'expMJD']) | ||
|
||
for obs in obs_list: | ||
ditheredRA = (obs.summary['OpsimMetaData']['randomDitherFieldPerVisitRA'] | ||
*180./np.pi) | ||
if ditheredRA > 180: | ||
ditheredRA -= 360. | ||
ditheredDec = (obs.summary['OpsimMetaData']['randomDitherFieldPerVisitDec'] | ||
*180./np.pi) | ||
|
||
if not fov_overlaps_protoDC2(ditheredRA, ditheredDec): | ||
continue | ||
|
||
fieldRA = obs.summary['OpsimMetaData']['fieldRA']*180./np.pi | ||
if fieldRA > 180: | ||
fieldRA -= 360. | ||
df.loc[len(df)] = (obs.summary['OpsimMetaData']['obsHistID'], | ||
fieldRA, | ||
obs.summary['OpsimMetaData']['fieldDec']*180./np.pi, | ||
ditheredRA, ditheredDec, | ||
obs.summary['OpsimMetaData']['filter'], | ||
obs.summary['OpsimMetaData']['fieldID'], | ||
obs.summary['OpsimMetaData']['propID'], | ||
obs.summary['OpsimMetaData']['expMJD']) | ||
|
||
pickle.dump(df, open('protoDC2_visits.pkl', 'wb'), protocol=2) | ||
|
||
print(len(df)) |
Binary file not shown.
Oops, something went wrong.