def select_objects(segimg, objimg, centroids, header=None): """Select objects based on given positions Input: - segimg <ndarray> : Numpy array with SEGMENTATION image information - objimg <ndarray> : Numpy array with OBJECTS/original image information - centroids <list:(int,int)> : List of tuples with positions to search for objects [(x0,y0),(x1,y1),...] """ # Initialize object IDs list.. # objIDs = []; # Is there an identified object on given (xo,yo) point? If yes, store its ID.. # for o_o in centroids: xo, yo = o_o; objid = segimg[yo,xo]; if ( objid != 0 ): objIDs.append(objid); else: print >> sys.stdout, "No objects were identified for (x=%s,y=%s) position." % (xo,yo); # Read out the objects recognized from images.. # objs, hdrs = imcp.sextamp( segimg, objimg, header, increase=2, relative_increase=True, objIDs=objIDs ); # image_out, hdr = cutout( obj_img, header=hdr, xo=int(xo), yo=int(yo), x_size=int(x_size), y_size=int(y_size), mask=ind ); return ({'IDs' : objIDs, 'images' : objs, 'headers' : hdrs});
def select_objects(segimg, objimg, centroids, header=None): """Select objects based on given positions Input: - segimg <ndarray> : Numpy array with SEGMENTATION image information - objimg <ndarray> : Numpy array with OBJECTS/original image information - centroids <list:(int,int)> : List of tuples with positions to search for objects [(x0,y0),(x1,y1),...] """ # Initialize object IDs list.. # objIDs = [] # Is there an identified object on given (xo,yo) point? If yes, store its ID.. # for o_o in centroids: xo, yo = o_o objid = segimg[yo, xo] if (objid != 0): objIDs.append(objid) else: print >> sys.stdout, "No objects were identified for (x=%s,y=%s) position." % ( xo, yo) # Read out the objects recognized from images.. # objs, hdrs = imcp.sextamp(segimg, objimg, header, increase=2, relative_increase=True, objIDs=objIDs) # image_out, hdr = cutout( obj_img, header=hdr, xo=int(xo), yo=int(yo), x_size=int(x_size), y_size=int(y_size), mask=ind ); return ({ 'IDs': objIDs, 'images': objs, 'headers': hdrs })
def pickout_obj(fits_image, xo, yo, params=[], args={}, use_header=True, increase=0, preset=''): """ Function to run SExtractor for objects segmentation and poststamp creation of a given image. A reference (e.g, a object centroid) point is expected. The function receives a FITS image and a pair of coordinates [xo,yo] matching a object. The output is the matching object image array, header and ID from segmentation step. SExtractor's command-line arguments can be passed through a dictionary [args] { 'key_argument' : 'value_option', ... } , and features to output (See SE's default.param file) at catalog through a list [params]. To have borders around the identified object use [increase] to define the size of them. The output image will have "increase" times the extracted object size. (Notice that 0 < increase < 1 is possible and will return a poststamp with part of the object) Preset SE's configuration parameters, for different telescope images, are available. The [preset] parameters are chosen to be *good* parameters for those instruments: 'HST','DC4','DC5','CFHT' Notice that this preset choices do not disable other parameters. The flag [use_header] gives the option to use or not the header instance information. Input: - fits_image <str> : FITs image filename - xo <int> : X object position in pixels - yo <int> : Y object position in pixels - params <list str> : list of parameters to output on sextractor catalogue - args <dic> : dictionary with sextractor command-line arguments - use_header <bool> : Whether or not to use (and update) header info - increase <float> : multiplicative factor for poststamp sizing - preset <str> : HST, DC4, DC5, CFHT Output: - <dic> : dictionary structure with the keys 'objIDs', 'images' and 'headers'. Each of them is a list with corresponding information. """ params.append('NUMBER') # Deal with fits files and SExtracting the image.. out = _file_2_arrays(fits_image, use_header, params, args, preset) if not out: print >> sys.stderr, "Error: An error occured while running SE and extracting FITS files." return (False) objimg, segimg, header, cat = out[0], out[1], out[2], out[3] # Is there an identified object on given (xo,yo) point?.. objid = segimg[yo, xo] if (objid != 0): pass else: print >> sys.stdout, "No objects were identified on given (line=%s,column=%s) position." % ( yo, xo) return (None) ## objects_IDfy return a list of arrays; result from the objIDs objects located in seg image merged with obj image. # So, each object in objIDs is returned (also inside a/the list) as array with their corresponding pixels.. # objs, hdrs = imcp.sextamp(segimg, objimg, header, increase=increase, relative_increase=True, objIDs=[objid]) #objout = objs[0]; #hdrout = hdrs[0]; return ({ 'IDs': [objid], 'images': objs, 'headers': hdrs })
def readout_objs(filename, params=[], args={}, use_header=True, increase=0, preset=''): """ Function to run SExtractor for objects identification and creates poststamp images. The function receives a FITS image filename and optionally some other arguments. The output are the identified object image arrays, headers and IDs from segmentation step. SExtractor's command-line arguments can be passed through a dictionary [args] { 'key_argument' : 'value_option', ... } , and features to output (See SE's default.param file) at catalog through a list [params]. To have borders around the identified object use [increase] to define the size of them. The output image will have "increase" times the extracted object size. (Notice that 0 < increase < 1 is possible and will return a poststamp with part of the object) Preset SE's configuration parameters, for different telescope images, are available. The [preset] parameters are chosen to be *good* parameters for those instruments: 'HST','DC4','DC5','CFHT' Notice that this preset choices do not disable other parameters. The flag [use_header] gives the option to use or not the header instance information. Input: - fits_image <str> : FITs image filename - params <list str> : list of parameters to output on sextractor catalogue - args <dic> : dictionary with sextractor command-line arguments - use_header <bool> : Whether or not to use (and update) header info - increase <float> : multiplicative factor for poststamp sizing - preset <str> : HST, DC4, DC5, CFHT Output: - <dic> : dictionary structure with the keys 'objIDs', 'images' and 'headers'. Each of them is a list with corresponding information. """ filename = fits_image params.append('NUMBER') # Deal with fits files and SExtracting the image.. out = _file_2_arrays(fits_image, use_header, params, args, preset) if not out: print >> sys.stderr, "Error: An error occured while running SE and extracting FITS files." return (False) objimg, segimg, header, cat = out[0], out[1], out[2], out[3] # Open "segmentation" output catalog from SE. Notice that object IDs are supposed to lie on 1st column.. # - # ASCII: # try: # objIDs = list( cat[:,0].astype(np.int32) ); # except: # objIDs = list( cat.astype(np.int32) ); # - # FITS: objIDs = cat.data.field('NUMBER') if (len(objIDs) == 0): print >> sys.stdout, "No objects were identified on given image." return (None) ## objects_IDfy return a list of arrays; result from the objIDs objects located in seg image merged with obj image. # So, each object in objIDs is returned (also inside a/the list) as array with their corresponding pixels.. # objs, hdrs = imcp.sextamp(segimg, objimg, header, increase=increase, relative_increase=True, objIDs=objIDs) return ({ 'IDs': objIDs, 'images': objs, 'headers': hdrs })
def pickout_obj(fits_image, xo, yo, params=[], args={}, use_header=True, increase=0, preset=''): """ Function to run SExtractor for objects segmentation and poststamp creation of a given image. A reference (e.g, a object centroid) point is expected. The function receives a FITS image and a pair of coordinates [xo,yo] matching a object. The output is the matching object image array, header and ID from segmentation step. SExtractor's command-line arguments can be passed through a dictionary [args] { 'key_argument' : 'value_option', ... } , and features to output (See SE's default.param file) at catalog through a list [params]. To have borders around the identified object use [increase] to define the size of them. The output image will have "increase" times the extracted object size. (Notice that 0 < increase < 1 is possible and will return a poststamp with part of the object) Preset SE's configuration parameters, for different telescope images, are available. The [preset] parameters are chosen to be *good* parameters for those instruments: 'HST','DC4','DC5','CFHT' Notice that this preset choices do not disable other parameters. The flag [use_header] gives the option to use or not the header instance information. Input: - fits_image <str> : FITs image filename - xo <int> : X object position in pixels - yo <int> : Y object position in pixels - params <list str> : list of parameters to output on sextractor catalogue - args <dic> : dictionary with sextractor command-line arguments - use_header <bool> : Whether or not to use (and update) header info - increase <float> : multiplicative factor for poststamp sizing - preset <str> : HST, DC4, DC5, CFHT Output: - <dic> : dictionary structure with the keys 'objIDs', 'images' and 'headers'. Each of them is a list with corresponding information. """ params.append('NUMBER'); # Deal with fits files and SExtracting the image.. out = _file_2_arrays(fits_image, use_header, params, args, preset); if not out: print >> sys.stderr, "Error: An error occured while running SE and extracting FITS files."; return (False); objimg, segimg, header, cat = out[0], out[1], out[2], out[3]; # Is there an identified object on given (xo,yo) point?.. objid = segimg[yo,xo]; if ( objid != 0 ): pass; else: print >> sys.stdout, "No objects were identified on given (line=%s,column=%s) position." % (yo,xo); return (None); ## objects_IDfy return a list of arrays; result from the objIDs objects located in seg image merged with obj image. # So, each object in objIDs is returned (also inside a/the list) as array with their corresponding pixels.. # objs, hdrs = imcp.sextamp( segimg, objimg, header, increase=increase, relative_increase=True, objIDs=[objid] ); #objout = objs[0]; #hdrout = hdrs[0]; return ({'IDs' : [objid], 'images' : objs, 'headers' : hdrs});
def readout_objs(filename, params=[], args={}, use_header=True, increase=0, preset=''): """ Function to run SExtractor for objects identification and creates poststamp images. The function receives a FITS image filename and optionally some other arguments. The output are the identified object image arrays, headers and IDs from segmentation step. SExtractor's command-line arguments can be passed through a dictionary [args] { 'key_argument' : 'value_option', ... } , and features to output (See SE's default.param file) at catalog through a list [params]. To have borders around the identified object use [increase] to define the size of them. The output image will have "increase" times the extracted object size. (Notice that 0 < increase < 1 is possible and will return a poststamp with part of the object) Preset SE's configuration parameters, for different telescope images, are available. The [preset] parameters are chosen to be *good* parameters for those instruments: 'HST','DC4','DC5','CFHT' Notice that this preset choices do not disable other parameters. The flag [use_header] gives the option to use or not the header instance information. Input: - fits_image <str> : FITs image filename - params <list str> : list of parameters to output on sextractor catalogue - args <dic> : dictionary with sextractor command-line arguments - use_header <bool> : Whether or not to use (and update) header info - increase <float> : multiplicative factor for poststamp sizing - preset <str> : HST, DC4, DC5, CFHT Output: - <dic> : dictionary structure with the keys 'objIDs', 'images' and 'headers'. Each of them is a list with corresponding information. """ filename = fits_image; params.append('NUMBER'); # Deal with fits files and SExtracting the image.. out = _file_2_arrays(fits_image, use_header, params, args, preset); if not out: print >> sys.stderr, "Error: An error occured while running SE and extracting FITS files."; return (False); objimg, segimg, header, cat = out[0], out[1], out[2], out[3]; # Open "segmentation" output catalog from SE. Notice that object IDs are supposed to lie on 1st column.. # - # ASCII: # try: # objIDs = list( cat[:,0].astype(np.int32) ); # except: # objIDs = list( cat.astype(np.int32) ); # - # FITS: objIDs = cat.data.field('NUMBER'); if ( len(objIDs) == 0 ): print >> sys.stdout, "No objects were identified on given image."; return (None); ## objects_IDfy return a list of arrays; result from the objIDs objects located in seg image merged with obj image. # So, each object in objIDs is returned (also inside a/the list) as array with their corresponding pixels.. # objs, hdrs = imcp.sextamp( segimg, objimg, header, increase=increase, relative_increase=True, objIDs=objIDs ); return ({'IDs' : objIDs, 'images' : objs, 'headers' : hdrs});