Commit 767ccc59 authored by Bryce Hepner's avatar Bryce Hepner

more docstrings

parent 410cc91f
...@@ -7,13 +7,26 @@ from scipy.stats import multivariate_normal ...@@ -7,13 +7,26 @@ from scipy.stats import multivariate_normal
from skimage.restoration import wiener from skimage.restoration import wiener
def setup_remote_sftpclient(): def setup_remote_sftpclient():
"""
Setup the SFTP client
Returns:
sftp_client (paramiko.SFTPClient): the SFTP client
"""
client = paramiko.SSHClient() client = paramiko.SSHClient()
client.load_system_host_keys() client.load_system_host_keys()
client.connect("192.168.0.107", username="elphel") client.connect("192.168.0.107", username="elphel")
sftp_client = client.open_sftp() sftp_client = client.open_sftp()
return sftp_client return sftp_client
def remove_noise(images, which_sensor): def create_average(images, which_sensor):
"""
Create an average image from a list of images
Parameters:
images (list): a list of images
which_sensor (int): the sensor number
Returns:
average_image (np.array): the average image
"""
same_sensor_images = [] same_sensor_images = []
which_sensor = str(which_sensor) which_sensor = str(which_sensor)
average_image = np.zeros_like(np.array(Image.open(images[0]))[1:]) average_image = np.zeros_like(np.array(Image.open(images[0]))[1:])
...@@ -31,6 +44,14 @@ def remove_noise(images, which_sensor): ...@@ -31,6 +44,14 @@ def remove_noise(images, which_sensor):
return average_image/len(same_sensor_images) return average_image/len(same_sensor_images)
def remote_create_average(images, which_sensor): def remote_create_average(images, which_sensor):
"""
Create an average image from a list of images
Parameters:
images (list): a list of images
which_sensor (int): the sensor number
Returns:
average_image (np.array): the average image
"""
sftp_client = setup_remote_sftpclient() sftp_client = setup_remote_sftpclient()
averages = [] averages = []
...@@ -81,6 +102,12 @@ def remote_file_extractor(headname = "/media/elphel/NVME/lwir16-proc/te0607/scen ...@@ -81,6 +102,12 @@ def remote_file_extractor(headname = "/media/elphel/NVME/lwir16-proc/te0607/scen
return scenes return scenes
def remote_image_extractor(scenes): def remote_image_extractor(scenes):
"""Find all the files in the directory
Parameters:
dirname (str): the directory name
Returns:
image_folder (list): a list of all the file paths in the directory
"""
sftp_client = setup_remote_sftpclient() sftp_client = setup_remote_sftpclient()
image_folder = [] image_folder = []
for scene in scenes: for scene in scenes:
...@@ -93,6 +120,14 @@ def remote_image_extractor(scenes): ...@@ -93,6 +120,14 @@ def remote_image_extractor(scenes):
sftp_client.close() sftp_client.close()
return image_folder #returns a list of file paths to .tiff files in the specified directory given in file_extractor return image_folder #returns a list of file paths to .tiff files in the specified directory given in file_extractor
def find_only_in_channel(images, channel_name = "10"): def find_only_in_channel(images, channel_name = "10"):
"""
Find the images that are only in the specified channel
Parameters:
images (list): a list of images
channel_name (str): the channel name
Returns:
same_sensor_images (list): a list of images that are only in the specified channel
"""
same_sensor_images = [] same_sensor_images = []
for i, image_name in enumerate(images): for i, image_name in enumerate(images):
if int(channel_name) > 9: if int(channel_name) > 9:
...@@ -103,6 +138,14 @@ def find_only_in_channel(images, channel_name = "10"): ...@@ -103,6 +138,14 @@ def find_only_in_channel(images, channel_name = "10"):
same_sensor_images.append(image_name) same_sensor_images.append(image_name)
return same_sensor_images return same_sensor_images
def adjust_to_original(new_image, average_image): def adjust_to_original(new_image, average_image):
"""
Adjust the image to the original image
Parameters:
new_image (np.array): the new image
average_image (np.array): the average image
Returns:
adjusted_image (np.array): the adjusted image
"""
original_image_min = np.min(new_image) original_image_min = np.min(new_image)
original_image_max = np.max(new_image) original_image_max = np.max(new_image)
average_image = average_image - np.mean(average_image) average_image = average_image - np.mean(average_image)
...@@ -126,12 +169,26 @@ def adjust_to_original(new_image, average_image): ...@@ -126,12 +169,26 @@ def adjust_to_original(new_image, average_image):
return adjusted_image.astype(np.uint16) return adjusted_image.astype(np.uint16)
def color_adjust(visual_array): def color_adjust(visual_array):
"""
Adjust the image to the original image
Parameters:
visual_array (np.array): the visual array
Returns:
adjusted_array (np.array): the adjusted image
"""
min_of_errors = np.min(visual_array) min_of_errors = np.min(visual_array)
adjusted_array = visual_array - min_of_errors adjusted_array = visual_array - min_of_errors
adjusted_array = adjusted_array/np.max(adjusted_array) adjusted_array = adjusted_array/np.max(adjusted_array)
return adjusted_array return adjusted_array
def save_new_average(quantity_of_images = 1500, channel = "10", head_dir = "/media/elphel/NVME/lwir16-proc/te0607/scenes/"): def save_new_average(quantity_of_images = 1500, channel = "10", head_dir = "/media/elphel/NVME/lwir16-proc/te0607/scenes/"):
"""
Save the new average image
Parameters:
quantity_of_images (int): the number of images to use in the average
channel (str): the channel name
head_dir (str): the head directory
"""
scenes = remote_file_extractor(head_dir) scenes = remote_file_extractor(head_dir)
images = find_only_in_channel(remote_image_extractor(scenes),channel) images = find_only_in_channel(remote_image_extractor(scenes),channel)
if quantity_of_images != "all": if quantity_of_images != "all":
...@@ -142,7 +199,14 @@ def save_new_average(quantity_of_images = 1500, channel = "10", head_dir = "/med ...@@ -142,7 +199,14 @@ def save_new_average(quantity_of_images = 1500, channel = "10", head_dir = "/med
average_savable_image = Image.fromarray(average_image) average_savable_image = Image.fromarray(average_image)
average_savable_image.save("Average_On_Channel(" + channel + ").tiff") average_savable_image.save("Average_On_Channel(" + channel + ").tiff")
def create_testable_images(images, selected_channel, quantity_of_images): def save_testable_images(images, selected_channel, quantity_of_images):
"""
Saves the testable images
Parameters:
images (list): a list of images
selected_channel (str): the channel name
quantity_of_images (int): the number of images to use in the average
"""
sftp_client = setup_remote_sftpclient() sftp_client = setup_remote_sftpclient()
images = find_only_in_channel(images, selected_channel) images = find_only_in_channel(images, selected_channel)
...@@ -174,8 +238,8 @@ def create_testable_images(images, selected_channel, quantity_of_images): ...@@ -174,8 +238,8 @@ def create_testable_images(images, selected_channel, quantity_of_images):
sftp_client.close() sftp_client.close()
def save_new_gauss(): def save_new_gauss():
"""\ """
creates gaussian kernel with side length `l` and a sigma of `sig` Save the new gauss image
""" """
# x,y = np.mgrid[-1:1:.003125, -1:1:.003125] # x,y = np.mgrid[-1:1:.003125, -1:1:.003125]
...@@ -206,7 +270,7 @@ if __name__ == "__main__": ...@@ -206,7 +270,7 @@ if __name__ == "__main__":
images = remote_image_extractor(scenes) images = remote_image_extractor(scenes)
images = find_only_in_channel(images, "11") images = find_only_in_channel(images, "11")
# average_image = np.array(Image.open("Average_On_Channel(" + "11" + ").tiff")) # average_image = np.array(Image.open("Average_On_Channel(" + "11" + ").tiff"))
# create_testable_images(images,"11",3) # save_testable_images(images,"11",3)
# plt.imshow(color_adjust(average_image),cmap='gray',vmin = 0, vmax=1) # plt.imshow(color_adjust(average_image),cmap='gray',vmin = 0, vmax=1)
# plt.show() # plt.show()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment