Skip to content

Commit

Permalink
Developing new ST code.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-gutierrez committed Sep 11, 2018
1 parent 0ae61ea commit 0a265ab
Show file tree
Hide file tree
Showing 6 changed files with 1,310 additions and 341 deletions.
52 changes: 48 additions & 4 deletions RPI/ST_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.- Imports
# Imports.
import time
import os
import re
Expand All @@ -11,12 +11,35 @@
from astropy.table import Table


# Check the initial data entered to the code.
# Define directories and names.
def names_and_dir():
dir_this = os.path.dirname(os.path.abspath(__file__)) + '/'
dir_img_fits = dir_this
dir_stars = dir_img_fits + 'sext'
dir_first_match = dir_img_fits + 'new_cat'
dir_sext = './sextractor'
dir_proj_cat = './Catalog/Projected/'
dir_normal_cat = './Catalog/Normal/'
fits_name = 'img_fits.fits'
return dir_this, dir_img_fits, dir_stars, dir_first_match, dir_sext, dir_proj_cat, dir_normal_cat, fits_name


# Define significant constant values.
def st_constants():
x_pix = 1024
y_pix = 1024
x_pix1 = int(x_pix/2)
y_pix1 = int(y_pix/2)
cmos_to_pix = 0.00270
return x_pix1, y_pix1, cmos_to_pix


# Check the initial data entered to execute code in the terminal.
def rev_initial_data(sys_arg, len_arg):
if len_arg == 1:
print '- Too few arguments...'
print '- Add the full directory of the image.'
raise ValueError('Invalid data...')
raise ValueError('Not enough data...')
elif len_arg == 2:
pic_name = sys_arg[1]
catalog_division = 10
Expand Down Expand Up @@ -49,4 +72,25 @@ def generate_fits(pic_name, fits_name):
fits4 = np.flipud(fits3)
fits5 = fits.PrimaryHDU(data=fits4)
fits5.writeto(fits_name, overwrite=True)
return
return 0


# Apply Source Extractor over an image.
def apply_sext(dir_sext, dir_img_fits, fits_name, x_pix, y_pix, cmos2pix):
os.chdir(dir_sext)
imdir = dir_img_fits + fits_name
sext_task = 'sextractor ' + imdir
subprocess.check_output(sext_task, shell=True)
sext1 = ascii.read('./test.cat', format='sextractor')
sext1.sort(['MAG_ISO'])
sext2 = sext1[0:40]
os.chdir(dir_img_fits)
sext_x = sext2['X_IMAGE']
sext_y = sext2['Y_IMAGE']
sext_mag = sext2['MAG_ISO']
sext_x1 = (sext_x - x_pix)*cmos2pix
sext_y1 = (sext_y - y_pix)*cmos2pix
sext_fname = 'sext'
ascii.write([sext_x1, sext_y1, sext_mag], sext_fname, delimiter=' ', format='no_header', overwrite=True,
formats={'X': '% 15.10f', 'Y': '% 15.10f', 'Z': '% 15.10f'}, names=['X', 'Y', 'Z'])
return 0
Binary file modified RPI/ST_functions.pyc
Binary file not shown.
28 changes: 11 additions & 17 deletions RPI/StarTracker_dev.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
# 1.- Imports.
import ST_functions
import os
import sys

# 2.- Define directories and names.
DIR_this = os.path.dirname(os.path.abspath(__file__)) + '/'
DIR_img_fits = DIR_this
DIR_stars = DIR_img_fits + 'sext'
DIR_first_match = DIR_img_fits + 'new_cat'
DIR_sext = './sextractor'
DIR_proj_cat = './Catalog/Projected/'
DIR_normal_cat = './Catalog/Normal/'
fits_name = 'img_fits.fits'
# 2.- Define directories, names and important values.
DIRs = ST_functions.names_and_dir()
values = ST_functions.st_constants()

# 3.- Receives initial data.
# 3.- Receives and reviews the initial data.
st_args = sys.argv
len_arg = len(st_args)
pic_name, cat_division = ST_functions.rev_initial_data(st_args, len_arg)

print '-.'*20
print 'REVIEW:'
print '-.'*30
print 'REVIEW - 1:'
print 'Initial arguments:', st_args
print 'Image name:', pic_name
print 'DIR_this: ', DIR_this
print '-.'*20
print 'DIR_this: ', DIRs[0]
print '-.'*30

# 4.- Generate FITS image.
ST_functions.generate_fits(pic_name, fits_name)
# 4.- Generate FITS image and execute SExtractor.
ST_functions.generate_fits(pic_name, DIRs[7])
ST_functions.apply_sext(DIRs[4], DIRs[1], DIRs[7], values[0], values[1], values[2])
Binary file modified RPI/img_fits.fits
Binary file not shown.
80 changes: 40 additions & 40 deletions RPI/sext
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
1.9439514 0.8178840000000008 -23.6361
-12.3420024 -0.6315191999999993 -23.0252
12.3218307 -7.785701099999999 -19.4581
-5.1669846 6.9385302000000015 -18.0235
-8.1205875 -3.3854084999999996 -16.9448
-6.2104859999999995 -6.764793300000001 -16.9106
7.257589200000002 -11.562228900000001 -16.4438
6.1032582 -12.7137465 -16.36
-3.2569182 13.638293999999998 -16.0623
-11.8787229 1.1573037000000008 -15.7499
9.0109314 0.6750755999999994 -15.6757
12.386074500000001 -13.386170700000001 -15.6412
0.6983145000000012 -9.7408737 -15.5885
-2.408967 -1.7330408999999993 -15.4853
-13.2987123 5.314385700000001 -15.4521
-7.3498023 11.7660303 -15.4241
2.7160703999999996 -1.9604240999999996 -15.3751
1.7364078000000014 -6.0742224 -15.3614
13.3509654 -9.970832699999999 -15.3399
1.4072346000000016 -10.2890142 -15.308
-3.5856755999999996 -8.246780099999999 -15.2879
11.3304528 -8.740440000000001 -15.2855
3.112524899999999 -10.394581500000001 -15.2546
-4.7441565 -8.5275369 -15.157
-10.670181300000001 -4.1065217999999994 -15.1079
5.1974649 -7.768531799999999 -15.0764
-2.3891894999999996 12.752747999999999 -15.0751
-5.0137515 -2.1299220000000005 -15.0706
12.100319999999998 12.997951200000001 -15.0583
-9.039654 -9.7506909 -15.0426
-9.6644907 11.317346999999998 -15.0136
-11.4596883 2.537176500000001 -14.978
5.353457400000001 11.872998899999999 -14.9382
-9.0543285 3.0554765999999995 -14.9352
6.858901800000001 -5.258827800000001 -14.9034
-13.6562571 -5.4985284000000005 -14.8938
-8.9784261 9.3576978 -14.8317
-12.5886231 5.8111641 -14.8269
11.39454 -8.8974315 -14.8248
7.8964227000000005 -9.1841877 -14.8106
0.4746637800 -0.0088956900 -7.3928000000
0.4765251600 0.8139441600 -6.4523000000
0.3778277400 0.1948004100 -6.4322000000
0.2841696000 0.6794282700 -6.0121000000
0.1546265700 0.8006836500 -5.3884000000
-0.2754750600 0.7330751100 -5.0836000000
1.3130580600 -0.3456391500 -5.0836000000
-0.1517424300 -0.2909790000 -4.8488000000
-0.0025857900 0.2760976800 -4.7577000000
1.1261300400 1.2695448600 -4.7303000000
-0.8150136300 -0.1659503700 -4.6584000000
-0.4249519200 -0.3408191100 -4.2690000000
-0.1512302400 -1.3041453600 -4.1331000000
-0.9042011100 0.3202070400 -3.9207000000
-0.2808502200 0.0869526900 -3.6179000000
-0.3611001600 -1.2629530800 -3.5785000000
-0.2152283400 -0.9066762000 -3.5380000000
-0.1660362300 1.0242547200 -3.4949000000
0.8039147400 0.7387310700 -3.4949000000
0.4863250800 -1.2245620500 -3.3566000000
1.3076688600 -0.0270621000 -3.3561000000
0.7415971200 0.6925883400 -3.2526000000
0.9645347700 -0.0185020200 -3.1970000000
0.5433296400 1.1440747800 -3.1387000000
-1.2955877100 0.0657274500 -3.1382000000
-1.0341000000 0.7805281500 -3.1381000000
0.2530634400 0.9125181900 -3.0764000000
-0.2925339300 -0.5246526600 -3.0763000000
-0.4238195400 0.5111059500 -3.0762000000
0.8478483300 -0.3427312500 -2.9406000000
1.0841517900 -1.1367000000 -2.9405000000
1.3815000900 -0.7600500000 -2.8653000000
0.7079335200 -0.6399159300 -2.6985000000
1.0797653700 0.9868500000 -2.6982000000
-1.3755676500 -0.3231438300 -2.6981000000
-1.0636812000 0.1112340600 -2.6979000000
0.0189000000 -1.0233000000 -2.6042000000
-0.1957594500 -1.2419616600 -2.6039000000
-1.2395926800 -0.7242507000 -2.6035000000
0.0217317600 0.3213000000 -2.6035000000
Loading

0 comments on commit 0a265ab

Please sign in to comment.