@@ -172,7 +172,7 @@ def cgi_session(command_list):
172
172
return html
173
173
174
174
175
- def calc_delta (hdulist , record ):
175
+ def calc_delta (header , record ):
176
176
"""Calculate JPL coordinate and HST reference pixel deltas.
177
177
178
178
The calculation is performed in degrees and then converted to
@@ -182,8 +182,8 @@ def calc_delta(hdulist, record):
182
182
`astrolib.coords` library.
183
183
184
184
Parameters:
185
- hdulist : HDUList instance
186
- pyfits .io.fits.hdulist object
185
+ header : header instance
186
+ astropy .io.fits.header object
187
187
record : dict
188
188
The record dictionary
189
189
@@ -205,19 +205,36 @@ def calc_delta(hdulist, record):
205
205
assert isinstance (record , dict ), \
206
206
'Expected dict got ' + str (type (record ))
207
207
208
- crval1 = hdulist [ 0 ]. header ['CRVAL1' ]
209
- crval2 = hdulist [ 0 ]. header ['CRVAL2' ]
208
+ crval1 = header ['CRVAL1' ]
209
+ crval2 = header ['CRVAL2' ]
210
210
211
211
# Convert the coordinates to coords instances in degrees.
212
212
record = convert_coords (record )
213
213
refpic_coords = coords .Degrees ((crval1 , crval2 ))
214
214
crval1 , crval2 = refpic_coords .a1 , refpic_coords .a2
215
215
216
+
217
+ # Set the pixel scale of the detector, in arcsec/pixel:
218
+ # WFPC2 has no detector keyword
219
+ instrument = header ['instrume' ]
220
+ try :
221
+ detector = header ['detector' ]
222
+ except KeyError :
223
+ detector = instrument
224
+
225
+ px_scales = {'WFPC2' : 0.046 , #this is only the planetary chip
226
+ 'WFC' : 0.049 ,
227
+ 'HRC' : 0.027 ,
228
+ 'SBC' : 0.032 ,
229
+ 'UVIS' : 0.04 ,
230
+ 'IR' : 0.13 }
231
+
232
+ px_scale = px_scales [detector ]
233
+
216
234
# Take the difference and convert to pixels.
217
235
# RA increases to the East (left) so we switch the sign on the delta.
218
- # Note these values are for WFPC2 only.
219
- delta_x = - 1 * (record ['jpl_ra' ] - crval1 ) * (3600. / 0.05 )
220
- delta_y = (record ['jpl_dec' ] - crval2 ) * (3600. / 0.05 )
236
+ delta_x = - 1 * (record ['jpl_ra' ] - crval1 ) * (3600. / px_scale )
237
+ delta_y = (record ['jpl_dec' ] - crval2 ) * (3600. / px_scale )
221
238
222
239
assert isinstance (delta_x , float ), \
223
240
'Expected float got ' + str (type (delta_x ))
@@ -226,7 +243,7 @@ def calc_delta(hdulist, record):
226
243
return delta_x , delta_y
227
244
228
245
229
- def calc_pixel_position (hdulist , delta_x , delta_y ):
246
+ def calc_pixel_position (header , delta_x , delta_y ):
230
247
"""Return the x and y position of the ephemeris in pixel space.
231
248
232
249
This function takes the ephemerides deltas (in pixels) and applies
@@ -235,8 +252,8 @@ def calc_pixel_position(hdulist, delta_x, delta_y):
235
252
space.
236
253
237
254
Parameters:
238
- hdulist : HDUList instance
239
- pyfits .io.fits.hdulist object
255
+ header : header instance
256
+ astropy .io.fits.hdulist.header object
240
257
delta_x : float
241
258
Float of the delta_x shift in pixels.
242
259
delta_y : float
@@ -252,8 +269,8 @@ def calc_pixel_position(hdulist, delta_x, delta_y):
252
269
'Expected float type got ' + str (type (delta_x ))
253
270
assert isinstance (delta_y , float ), \
254
271
'Expected float type got ' + str (type (delta_y ))
255
- ephem_x = hdulist [ 0 ]. header ['CRPIX1' ] + delta_x
256
- ephem_y = hdulist [ 0 ]. header ['CRPIX2' ] + delta_y
272
+ ephem_x = header ['CRPIX1' ] + delta_x
273
+ ephem_y = header ['CRPIX2' ] + delta_y
257
274
assert isinstance (ephem_x , float ), \
258
275
'Expected float type got ' + str (type (ephem_x ))
259
276
assert isinstance (ephem_y , float ), \
@@ -401,7 +418,7 @@ def make_all_moon_dict(targname):
401
418
return all_moon_dict
402
419
403
420
404
- def insert_record (hdulist , moon_dict , master_images_id ):
421
+ def insert_record (header , moon_dict , master_images_id ):
405
422
"""Insert a new record into the `master_finders` table.
406
423
407
424
If there is no magnitude or diameter information, this raises an
@@ -412,8 +429,8 @@ def insert_record(hdulist, moon_dict, master_images_id):
412
429
-999 in `parse_jpl_cgi` so these exceptions should never happen.
413
430
414
431
Parameters:
415
- hdulist : HDUList instance
416
- pyfits .io.fits.hdulist object
432
+ header : FITS header instance
433
+ astropy .io.fits.hdulist.header object
417
434
all_moon_dict : dict
418
435
A dict containing the JPL id and object information
419
436
for each
@@ -436,8 +453,8 @@ def insert_record(hdulist, moon_dict, master_images_id):
436
453
record .object_name = moon_dict ['object' ]
437
454
record .jpl_ra = moon_dict ['jpl_ra' ]
438
455
record .jpl_dec = moon_dict ['jpl_dec' ]
439
- delta_x , delta_y = calc_delta (hdulist , moon_dict )
440
- ephem_x , ephem_y = calc_pixel_position (hdulist , delta_x , delta_y )
456
+ delta_x , delta_y = calc_delta (header , moon_dict )
457
+ ephem_x , ephem_y = calc_pixel_position (header , delta_x , delta_y )
441
458
record .ephem_x = int (ephem_x )
442
459
record .ephem_y = int (ephem_y )
443
460
try :
@@ -502,16 +519,16 @@ def parse_jpl_cgi(data):
502
519
soe_switch = True
503
520
504
521
505
- def update_record (hdulist , moon_dict , master_images_id ): # changed this function. added hdulist as a parameter and added the ephemerides calculations.
522
+ def update_record (header , moon_dict , master_images_id ): # changed this function. added header as a parameter and added the ephemerides calculations.
506
523
'''
507
524
Update a record in the master_finders table.
508
525
'''
509
526
update_dict = {}
510
527
update_dict ['object_name' ] = moon_dict ['object' ]
511
528
update_dict ['jpl_ra' ] = moon_dict ['jpl_ra' ]
512
529
update_dict ['jpl_dec' ] = moon_dict ['jpl_dec' ]
513
- delta_x , delta_y = calc_delta (hdulist , moon_dict )
514
- ephem_x , ephem_y = calc_pixel_position (hdulist , delta_x , delta_y )
530
+ delta_x , delta_y = calc_delta (header , moon_dict )
531
+ ephem_x , ephem_y = calc_pixel_position (header , delta_x , delta_y )
515
532
update_dict ['ephem_x' ] = int (ephem_x )
516
533
update_dict ['ephem_y' ] = int (ephem_y )
517
534
try :
@@ -594,6 +611,7 @@ def ephem_main(filename, reproc=False):
594
611
# Extract needed header information
595
612
file_dict = {}
596
613
with fits .open (filename ,mode = 'readonly' ) as hdulist :
614
+ header = hdulist .header
597
615
file_dict ['date_obs' ] = hdulist [0 ].header ['date-obs' ]
598
616
file_dict ['time_obs' ] = hdulist [0 ].header ['time-obs' ]
599
617
file_dict ['targname' ] = hdulist [0 ].header ['targname' ]
@@ -614,7 +632,7 @@ def ephem_main(filename, reproc=False):
614
632
if master_finders_count == 0 :
615
633
jpl_dict = get_jpl_data (moon_dict )
616
634
moon_dict .update (jpl_dict )
617
- insert_record (hdulist , moon_dict , master_images_query .id )
635
+ insert_record (header , moon_dict , master_images_query .id )
618
636
619
637
# When a record exists, check if it has jpl_ra info. If it
620
638
# doesn't then update.
@@ -626,7 +644,7 @@ def ephem_main(filename, reproc=False):
626
644
if master_finders_count == 1 or reproc == True :
627
645
jpl_dict = get_jpl_data (moon_dict )
628
646
moon_dict .update (jpl_dict )
629
- update_record (hdulist , moon_dict , master_images_query .id )
647
+ update_record (header , moon_dict , master_images_query .id )
630
648
631
649
session .close ()
632
650
0 commit comments