Skip to content

Commit 7bdf61d

Browse files
committed
futurize step 1, by hand for some reason
1 parent dbcbd28 commit 7bdf61d

File tree

3 files changed

+493
-41
lines changed

3 files changed

+493
-41
lines changed

.ipynb_checkpoints/RHT_example_workflow-checkpoint.ipynb

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.

RHT_example_workflow.ipynb

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@
1717
},
1818
{
1919
"cell_type": "code",
20-
"execution_count": 145,
21-
"metadata": {},
22-
"outputs": [],
20+
"execution_count": 1,
21+
"metadata": {
22+
"collapsed": false
23+
},
24+
"outputs": [
25+
{
26+
"ename": "SyntaxError",
27+
"evalue": "invalid syntax (rht.py, line 110)",
28+
"output_type": "error",
29+
"traceback": [
30+
"\u001b[0;36m File \u001b[0;32m\"/Users/jegpeek/Repositories/RHT-fork/rht.py\"\u001b[0;36m, line \u001b[0;32m110\u001b[0m\n\u001b[0;31m print announcement(strings)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
31+
]
32+
}
33+
],
2334
"source": [
2435
"from astropy.io import fits\n",
2536
"import matplotlib\n",
@@ -39,7 +50,9 @@
3950
{
4051
"cell_type": "code",
4152
"execution_count": 43,
42-
"metadata": {},
53+
"metadata": {
54+
"collapsed": true
55+
},
4356
"outputs": [],
4457
"source": [
4558
"data_fn = \"testim_tesla_small\"\n",
@@ -56,7 +69,9 @@
5669
{
5770
"cell_type": "code",
5871
"execution_count": 44,
59-
"metadata": {},
72+
"metadata": {
73+
"collapsed": false
74+
},
6075
"outputs": [
6176
{
6277
"data": {
@@ -100,7 +115,9 @@
100115
{
101116
"cell_type": "code",
102117
"execution_count": 23,
103-
"metadata": {},
118+
"metadata": {
119+
"collapsed": false
120+
},
104121
"outputs": [
105122
{
106123
"name": "stdout",
@@ -146,7 +163,9 @@
146163
{
147164
"cell_type": "code",
148165
"execution_count": 51,
149-
"metadata": {},
166+
"metadata": {
167+
"collapsed": true
168+
},
150169
"outputs": [],
151170
"source": [
152171
"rht_data_fn = data_fn+\"_xyt01.fits\"\n",
@@ -163,7 +182,9 @@
163182
{
164183
"cell_type": "code",
165184
"execution_count": 52,
166-
"metadata": {},
185+
"metadata": {
186+
"collapsed": false
187+
},
167188
"outputs": [
168189
{
169190
"data": {
@@ -201,7 +222,9 @@
201222
{
202223
"cell_type": "code",
203224
"execution_count": 54,
204-
"metadata": {},
225+
"metadata": {
226+
"collapsed": false
227+
},
205228
"outputs": [
206229
{
207230
"name": "stdout",
@@ -225,7 +248,9 @@
225248
{
226249
"cell_type": "code",
227250
"execution_count": 152,
228-
"metadata": {},
251+
"metadata": {
252+
"collapsed": true
253+
},
229254
"outputs": [],
230255
"source": [
231256
"indx = 20000\n",
@@ -245,7 +270,9 @@
245270
{
246271
"cell_type": "code",
247272
"execution_count": 148,
248-
"metadata": {},
273+
"metadata": {
274+
"collapsed": false
275+
},
249276
"outputs": [
250277
{
251278
"data": {
@@ -291,7 +318,9 @@
291318
{
292319
"cell_type": "code",
293320
"execution_count": 149,
294-
"metadata": {},
321+
"metadata": {
322+
"collapsed": false
323+
},
295324
"outputs": [
296325
{
297326
"data": {
@@ -339,7 +368,9 @@
339368
{
340369
"cell_type": "code",
341370
"execution_count": 150,
342-
"metadata": {},
371+
"metadata": {
372+
"collapsed": false
373+
},
343374
"outputs": [
344375
{
345376
"data": {
@@ -357,28 +388,30 @@
357388
{
358389
"cell_type": "code",
359390
"execution_count": null,
360-
"metadata": {},
391+
"metadata": {
392+
"collapsed": true
393+
},
361394
"outputs": [],
362395
"source": []
363396
}
364397
],
365398
"metadata": {
366399
"kernelspec": {
367-
"display_name": "Python 2",
400+
"display_name": "Python [anaconda3]",
368401
"language": "python",
369-
"name": "python2"
402+
"name": "Python [anaconda3]"
370403
},
371404
"language_info": {
372405
"codemirror_mode": {
373406
"name": "ipython",
374-
"version": 2
407+
"version": 3
375408
},
376409
"file_extension": ".py",
377410
"mimetype": "text/x-python",
378411
"name": "python",
379412
"nbconvert_exporter": "python",
380-
"pygments_lexer": "ipython2",
381-
"version": "2.7.14"
413+
"pygments_lexer": "ipython3",
414+
"version": "3.5.2"
382415
}
383416
},
384417
"nbformat": 4,

rht.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#Imports
77
#-----------------------------------------------------------------------------------------
88
from __future__ import division #Must be first line of code in the file
9+
from __future__ import print_function
910
from astropy.io import fits
1011
from argparse import ArgumentParser
1112
from argparse import ArgumentDefaultsHelpFormatter
@@ -107,7 +108,7 @@ def announcement(strings):
107108
return result
108109

109110
def announce(strings):
110-
print announcement(strings)
111+
print(announcement(strings))
111112

112113
def update_progress(progress, message='Progress:', final_message='Finished:'):
113114
# Create progress meter that looks like:
@@ -167,7 +168,7 @@ def update_progress(progress, message='Progress:', final_message='Finished:'):
167168
sys.stdout.flush()
168169
start_time = None
169170
stop_time = None
170-
print ''
171+
print('')
171172

172173
#-----------------------------------------------------------------------------------------
173174
# Naming Conventions and Converisons
@@ -215,8 +216,8 @@ def xyt_name_factory(filepath, wlen, smr, frac, original):
215216

216217
# Failure: No match and no available output slots
217218
xyt_filename = string.replace(fnmatch_string, '?', '0')
218-
print 'In xyt_filename(): No existing ouput matches the input parameters and no namespace is available'
219-
print 'Overwrite ' + xyt_filename + '?..'
219+
print('In xyt_filename(): No existing ouput matches the input parameters and no namespace is available')
220+
print('Overwrite ' + xyt_filename + '?..')
220221
choice = raw_input(' [y]/n/'+'0'*(DIGITS-1)+'x')
221222
if len(choice) == 0 or choice == 'y':
222223
return os.path.normpath(os.path.join(dirname, xyt_filename))
@@ -355,7 +356,7 @@ def getXYT(xyt_filename, match_only=False):
355356
xyt = np.memmap(tempfile.TemporaryFile(), dtype=DTYPE, mode='w+', shape=(datay, datax, ntheta))
356357
xyt.fill(0.0)
357358
else:
358-
print 'Warning: Reconstructing very large array in memory! Set BUFFER to True!'
359+
print('Warning: Reconstructing very large array in memory! Set BUFFER to True!')
359360
xyt = np.zeros((datay, datax, ntheta))
360361
coords = zip(Hj, Hi)
361362
for c in range(len(coords)):
@@ -411,7 +412,7 @@ def bad_pixels(data):
411412
'''
412413
except:
413414
# IMPLEMENTATION3: Give up?
414-
print 'Unable to properly mask data in bad_pixels()...'
415+
print('Unable to properly mask data in bad_pixels()...')
415416
return data.astype(np.bool)
416417

417418
def all_within_diameter_are_good(data, diameter):
@@ -480,10 +481,10 @@ def getData(filepath, make_mask=False, smr=SMR, wlen=WLEN):
480481
except:
481482
# Failure Reading Data
482483
if make_mask:
483-
print 'Failure in getData('+filepath+')... Returning None, None, None'
484+
print('Failure in getData('+filepath+')... Returning None, None, None')
484485
return None, None, None
485486
else:
486-
print 'Failure in getData('+filepath+')... Returning None'
487+
print('Failure in getData('+filepath+')... Returning None')
487488
return None
488489

489490
if not make_mask:
@@ -666,15 +667,15 @@ def buffershape(ntheta, filesize=FILECAP):
666667
ntheta = int(ntheta)
667668
filesize = int(filesize)
668669
if not 0 < filesize <= FILECAP:
669-
print 'Chosen buffer size exceeds existing limit. Reset to', str(FILECAP), 'Bytes'
670+
print('Chosen buffer size exceeds existing limit. Reset to', str(FILECAP), 'Bytes')
670671
filesize = FILECAP
671672

672673
bits_per_element_in_bits = np.dtype(DTYPE).itemsize
673674
bits_per_file_in_bits = filesize*8
674675
elements_per_file_in_elements = int(bits_per_file_in_bits // bits_per_element_in_bits)
675676
length_in_elements = int(elements_per_file_in_elements // ntheta)
676677
if length_in_elements <= 0:
677-
print 'In buffershape, ntheta has forced your buffer size to become larger than', filesize, 'Bytes'
678+
print('In buffershape, ntheta has forced your buffer size to become larger than', filesize, 'Bytes')
678679
length_in_elements = 1
679680

680681
return (length_in_elements, ntheta)
@@ -859,7 +860,7 @@ def rmtree_failue(function, path, excinfo):
859860
os.remove(obj)
860861
os.removedirs(temp_dir)
861862
except:
862-
print 'Failed to delete temporary files:', path
863+
print('Failed to delete temporary files:', path)
863864

864865
shutil.rmtree(temp_dir, ignore_errors=False, onerror=rmtree_failue)
865866
return True
@@ -899,7 +900,7 @@ def rht(filepath, force=False, original=ORIGINAL, wlen=WLEN, frac=FRAC, smr=SMR)
899900

900901
if not is_valid_file(filepath):
901902
# Check to see if a file should have the rht applied to it.
902-
print 'Invalid filepath encountered in rht('+filepath+')...'
903+
print('Invalid filepath encountered in rht('+filepath+')...')
903904
return False
904905

905906
try:
@@ -911,17 +912,16 @@ def rht(filepath, force=False, original=ORIGINAL, wlen=WLEN, frac=FRAC, smr=SMR)
911912
# This can overridden by setting the 'force' flag.
912913
return True
913914

914-
print '1/4:: Retrieving Data from:', filepath
915+
print('1/4:: Retrieving Data from:', filepath)
915916
data, smr_mask, wlen_mask = getData(filepath, make_mask=True, smr=smr, wlen=wlen)
916917
datay, datax = data.shape
917918

918-
print '2/4::', 'Size:', str(datax)+'x'+str(datay)+',', 'Wlen:', str(wlen)+',', 'Smr:', str(smr)+',', 'Frac:', str(frac)+',', 'Standard (half-polar) RHT:', str(original)
919-
919+
print('2/4::', 'Size:', str(datax)+'x'+str(datay)+',', 'Wlen:', str(wlen)+',', 'Smr:', str(smr)+',', 'Frac:', str(frac)+',', 'Standard (half-polar) RHT:', str(original))
920920
message = '3/4:: Running RHT...'
921921

922922
success = window_step(data=data, wlen=wlen, frac=frac, smr=smr, original=original, smr_mask=smr_mask, wlen_mask=wlen_mask, xyt_filename=xyt_filename, message=message) #TODO__________________
923923

924-
print '4/4:: Successfully Saved Data As', xyt_filename
924+
print('4/4:: Successfully Saved Data As', xyt_filename)
925925
return success
926926

927927
except:
@@ -950,7 +950,7 @@ def interpret(filepath, force=False, wlen=WLEN, frac=FRAC, smr=SMR, original=ORI
950950
'''
951951

952952

953-
print 'viewer() is currently in disrepair! Exiting to avoid unpleasant results!'
953+
print('viewer() is currently in disrepair! Exiting to avoid unpleasant results!')
954954
return False
955955

956956
# Make sure relevant files are present.
@@ -1004,7 +1004,7 @@ def cleanup():
10041004
plt.close()
10051005

10061006
#---------------------------------------------------------------------- PLOT 1
1007-
print 'Plotting Whole Figure...'
1007+
print('Plotting Whole Figure...')
10081008
fig, axes = plt.subplots(nrows=2, ncols=2)
10091009

10101010
#### Log-scale plot of original image data
@@ -1034,7 +1034,7 @@ def cleanup():
10341034
cleanup()
10351035

10361036
#---------------------------------------------------------------------- PLOT 2
1037-
print 'Backprojecting...'
1037+
print('Backprojecting...')
10381038

10391039
#### Log-scale plot of original image data
10401040
plt.subplot(121)
@@ -1065,7 +1065,7 @@ def cleanup():
10651065
'''
10661066
#---------------------------------------------------------------------- PLOT 4
10671067
#Polar plot of theta power
1068-
print 'Linearity'
1068+
print('Linearity')
10691069

10701070
if original:
10711071
modified_spectrum = np.true_divide(np.append(spectrum, spectrum), 2.0)
@@ -1123,12 +1123,12 @@ def main(source=None, display=False, force=False, drht=False, wlen=WLEN, frac=FR
11231123
pathlist.append(obj_path)
11241124
else:
11251125
# Input is neither a file nor a directory.
1126-
print 'Invalid source encountered in main(); must be file or directory.'
1126+
print('Invalid source encountered in main(); must be file or directory.')
11271127
return False
11281128

11291129
pathlist = filter(is_valid_file, pathlist)
11301130
if len(pathlist) == 0:
1131-
print 'Invalid source encountered in main(); no valid images found.'
1131+
print('Invalid source encountered in main(); no valid images found.')
11321132
return False
11331133

11341134
# Run RHT over all valid inputs.

0 commit comments

Comments
 (0)