Skip to content

Commit

Permalink
Merge pull request #266 from rbiswas4/Issue/265/randomize_simlibs
Browse files Browse the repository at this point in the history
Make changes to randomize simlibs.
  • Loading branch information
rbiswas4 authored Aug 29, 2018
2 parents 85c7069 + 3df7bd3 commit a6abd15
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
13 changes: 9 additions & 4 deletions opsimsummary/simlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,19 @@ def get_surveyPix(self, surveydf, numFields=15, rng=np.random.RandomState(0)):
"""
surveydf['simlibId'] = -1

if numFields < len(surveydf):
hids = rng.choice(surveydf.reset_index()['hid'].values, size=numFields,
replace=False)
if numFields <= len(surveydf):
surveydf = surveydf.sample(n=numFields, replace=False,
random_state=rng)
# hids = rng.choice(surveydf.reset_index()['hid'].values, size=numFields,
# replace=False)
else:
hids = surveydf.reset_index()['hid'].values
surveydf = surveydf.sample(size=numFields, replace=True,
random_state=rng)
print("Warning: You have asked for more samples than the original number of fields")
print('Printing original number of fields instead')

hids = surveydf.reset_index()['hid'].values

surveydf.reset_index().set_index('hid')
surveydf.loc[hids, 'simlibId'] = np.arange(len(hids))
return surveydf
Expand Down
2 changes: 1 addition & 1 deletion opsimsummary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = "1.19.7"
__VERSION__ = "1.19.8"
43 changes: 32 additions & 11 deletions scripts/make_simlibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def write_genericSimlib(simlibFilename, summary, minVisits, maxVisits, numFields
surveyPix = surveyPix.reset_index().query('simlibId > -1').set_index('simlibId')
surveyPix = surveyPix.reset_index().sort_values(by='simlibId').set_index('simlibId')
surveyPix.to_csv(mapFile)
return surveyPix
return surveyPix, surveydf

if __name__ == '__main__':
parser = ArgumentParser(description='write out simlibs from an OpSim Database')
Expand Down Expand Up @@ -152,8 +152,14 @@ def write_genericSimlib(simlibFilename, summary, minVisits, maxVisits, numFields

if wfd_simlibfilename is None:
wfd_simlibfilename = basename +'_wfd.simlib'
availwfdFileName = basename + "_wfd_avail.csv"
selectedwfdFileName = basename + "_wfd_sel.csv"
print('output file names for wfd are {0}, {1}, {2}'.format(wfd_simlibfilename, availwfdFileName, selectedwfdFileName))
if ddf_simlibfilename is None:
ddf_simlibfilename = basename +'_ddf.simlib'
availddfFileName = basename + "_ddf_avail.csv"
selectedddfFileName = basename + "_ddf_sel.csv"
print('output file names for DDF are {0}, {1}, {2}'.format(ddf_simlibfilename, availddfFileName, selectedddfFileName))

numFields_DDF = args.numFields_DDF
numFields_WFD = args.numFields_WFD
Expand All @@ -178,22 +184,37 @@ def write_genericSimlib(simlibFilename, summary, minVisits, maxVisits, numFields
tend = time.time()
print("finished reading database {0} at time {1}".format(dbname, tend))
print("reading the db took {} minutes".format((tend-tstart)/60.0))
sys.stdout.flush()
summary = opsout.summary
script_name = os.path.abspath(__file__)
if write_ddf_simlib:
print('writing out simlib for DDF')
# 133 random locations is similar density of locations in WFD.
x = write_genericSimlib(simlibFilename=ddf_simlibfilename,
summary=opsout_ddf.summary, minVisits=500, maxVisits=None,
numFields=numFields_DDF, mapFile='ddf_minion_1016_sqlite.csv',
fieldType='DDF', opsimoutput=dbname,
script_name=script_name)
x, y = write_genericSimlib(simlibFilename=ddf_simlibfilename,
summary=opsout_ddf.summary, minVisits=500, maxVisits=None,
numFields=numFields_DDF, mapFile='ddf_minion_1016_sqlite.csv',
fieldType='DDF', opsimoutput=dbname,
script_name=script_name)
print('Finished writing out simlib for DDF')
print('write mapping to csv')
x.to_csv(selectedddfFileName)
y.to_csv(availddfFileName)
print('Finished writing mapping to csv')
sys.stdout.flush()
sys.stdout.flush()
if write_wfd_simlib :
print('writing out simlib for WFD')
x = write_genericSimlib(simlibFilename=wfd_simlibfilename,
summary=summary, minVisits=500, maxVisits=10000,
numFields=numFields_WFD, mapFile='wfd_minion_1016_sqlite.csv',
fieldType='WFD', opsimoutput=dbname,
vetoed_hids=ddf_hid, script_name=script_name)
sys.stdout.flush()
x, y = write_genericSimlib(simlibFilename=wfd_simlibfilename,
summary=summary, minVisits=500, maxVisits=10000,
numFields=numFields_WFD, mapFile='wfd_minion_1016_sqlite.csv',
fieldType='WFD', opsimoutput=dbname,
vetoed_hids=ddf_hid, script_name=script_name)
print('Finished writing out simlib for WFD')
print('write mapping to csv')
x.to_csv(selectedwfdFileName)
y.to_csv(availwfdFileName)
print('Finished writing mapping to csv')
sys.stdout.flush()
print('finished job')
sys.stdout.flush()

0 comments on commit a6abd15

Please sign in to comment.