Skip to content

Commit

Permalink
Merge pull request #20 from mkelley/target-filenames
Browse files Browse the repository at this point in the history
better treatment of comet target filenames
  • Loading branch information
mommermi committed Mar 14, 2017
2 parents 810a7de + b0f6d60 commit 21255d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
9 changes: 9 additions & 0 deletions _pp_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import logging
import warnings

try:
from astropy import wcs
from astropy.io import fits
Expand Down Expand Up @@ -104,6 +105,14 @@ def setup_diagnostics():
# start pp_process_idx counter (if using 'pp_run all')
pp_process_idx = 0

# Translation table to transform target names to file names
# space and / --> _
if sys.version_info > (3, 0):
target2filename = str.maketrans(' /', '__')
else:
import string
target2filename = string.maketrans(' /', '__')

# available catalogs

# list of available catalogs
Expand Down
17 changes: 10 additions & 7 deletions diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,12 @@ def add_results(data):
linestyle='', color='black')
plt.ylim([plt.ylim()[1], plt.ylim()[0]])
plt.grid()
plt.savefig('.diagnostics/' + ('%s.png' % target.replace(' ', '_')),
plt.savefig('.diagnostics/'
+ ('%s.png' % target.translate(_pp_conf.target2filename)),
format='png')
plt.close()
data['lightcurveplots'][target] = ('.diagnostics/' + '%s.png' %
target.replace(' ', '_'))
target.translate(_pp_conf.target2filename))

##### create thumbnail images

Expand Down Expand Up @@ -861,7 +862,8 @@ def add_results(data):
exp_y-obj_y+old_div(boxsize,2.),
marker='+', s=100, color='green')

thumbfilename = '.diagnostics/' + target.replace(' ', '_')+'_'+ \
thumbfilename = '.diagnostics/' + \
target.translate(_pp_conf.target2filename) + '_' + \
fitsfilename[:fitsfilename.find('.fit')] + \
'_thumb.png'
plt.savefig(thumbfilename, format='png', bbox_inches='tight',
Expand All @@ -872,15 +874,14 @@ def add_results(data):
thumbfilename))

## create gif animation
gif_filename = ('%s.gif' %
(target.replace(' ', '_')))
gif_filename = ('%s.gif' % target.translate(_pp_conf.target2filename))
logging.info('converting images to gif: %s' % gif_filename)
root = os.getcwd()
os.chdir(_pp_conf.diagroot)
try:
convert = subprocess.Popen(['convert', '-delay', '50',
('%s*thumb.png' %
(target.replace(' ', '_'))),
(target.translate(_pp_conf.target2filename))),
'-loop', '0',
('%s' % gif_filename)])

Expand Down Expand Up @@ -923,7 +924,9 @@ def add_results(data):
html += "<P>%s<IMG ID=\"%s\" SRC=\"%s\">\n" % (plts[0],
data[target][idx][10],
plts[1].split('.diagnostics/')[1])
filename = '.diagnostics/'+target.replace(' ', '_')+'_'+'results.html'
filename = '.diagnostics/' + \
target.translate(_pp_conf.target2filename) + \
'_' + 'results.html'
create_website(filename, html)
data['resultswebsites'][target] = filename

Expand Down
3 changes: 2 additions & 1 deletion pp_distill.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ def distill(catalogs, man_targetname, offset, fixed_targets_file, posfile,

if display:
print('write photometry results for %s' % target)
outf = open('photometry_%s.dat' % target.replace(' ', '_'), 'w')
outf = open('photometry_%s.dat' %
target.translate(_pp_conf.target2filename), 'w')
outf.write('# filename julian_date '
'ast_mag ast_sig ast_ra ast_dec '
'[1] [2] [3] [4] [5] ZP ZP_sig '
Expand Down
4 changes: 2 additions & 2 deletions pp_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def curve_of_growth_analysis(filenames, parameters,
# pull target coordinates from Horizons
targetname = hdu[0].header[obsparam['object']]
if parameters['manobjectname'] is not None:
targetname = parameters['manobjectname'].replace('_', ' ')
targetname = parameters['manobjectname'].transform(_pp_conf.target2name)

image = hdu[0].data

Expand Down Expand Up @@ -449,7 +449,7 @@ def photometry(filenames, sex_snr, source_minarea, aprad,
obsparam = _pp_conf.telescope_parameters[telescope]

if type(manobjectname) == str:
manobjectname = manobjectname.replace(' ', '_')
manobjectname = manobjectname.transform(_pp_conf.target2name)

# set minarea from obsparam
if source_minarea == 0:
Expand Down

0 comments on commit 21255d2

Please sign in to comment.