def task(filename, task_params):
    ''' Return a hot pixel in the defined region.
    @author
    @param task_params -
    @return
    '''

    # Assume the arguments are passed in this format:
    # [region_of_interest, N(the threshold value)]
    # if ROI is 'all', then by default it will find all the hot pixels in the image.
    # NOTE: for test purpose we ignore [region file] for now.

    # CMD: hot_pixel ffview max rect 200 200 400 400
    # Example JSON:
    # {"filename":"default", "threshold":"max", "region":{"rect":[0,0,100,100]}}
    hdulist = fits.open(filename)
    threshold, roi = task_params['threshold'], task_params['region']
    region_type, value = roi['type'], roi['value']
    # Region
    region = hdulist[0].data

    try:
        if (region_type=='rect'):
            region_slice = parseRegion_rect(value)
        elif (region_type=='all'):
            region_slice = slice(None)
        else:
            return ['Input region type not supported.']
    except Exception as e:
        return ["Error reading the input region."]

    # print(region_slice)
    region = region[region_slice]
    # os.system("echo %d %d %d %d > /www/algorithm/debug_file" % (x_start, x_end, y_start, y_end))
    # Threshold
    if (threshold == 'max'):
        threshold = float(np.max(region))
    else:
        try:
            threshold = float(threshold)
        except Exception as e:
            return ["Error reading the input threshold."]

    cols, rows = np.where(region>=threshold)

    num_points = 500  # Set to 500 so that at most it will return 1000 points
    num_points = rows.size if num_points>rows.size else num_points

    rows = rows[::rows.size//num_points]
    cols = cols[::cols.size//num_points]
    l = np.zeros((rows.size, 2))
    l[:,0] = cols + region_slice[0].start
    l[:,1] = rows + region_slice[1].start

    hdulist.close()
    return l.tolist(), None
def task(filename, task_params):
    ''' Simple task calculating average value in a region. Boundary assumes the expected format being sent in.
    @author Wei Ren
    @param filename - file name of the FITS image
    @param task_params - Region to calculate mean value on. Currently support `rect` and `circle` regions.
    @return Mean value of the results or Error info.
    '''

    hdulist = fits.open(filename)
    region = hdulist[0].data
    region_type, value = task_params['type'], task_params['value']

    if (region_type=='rect'):
        region_slice = parseRegion_rect(value)
        ROI = region[region_slice]
        avg = str(np.mean(ROI))
    elif (region_type=='circle'):
        mask = circle_mask(region, value)
        avg = str(gf(region, np.mean, footprint=mask))
    else:
        avg = "Region type is not recognized."

    hdulist.close()
    return {"result":avg},None