Skip to content

Instantly share code, notes, and snippets.

@vatch123
Created March 24, 2019 14:54
Show Gist options
  • Save vatch123/00c38687bfae80a7d8d68794cc2a51e6 to your computer and use it in GitHub Desktop.
Save vatch123/00c38687bfae80a7d8d68794cc2a51e6 to your computer and use it in GitHub Desktop.

OCCULT-2 Pseudocode

This a schenmatic representation of the structure of the OCCULT-2 algorithm highlighting the four major steps.

Background Suppression

def backgd_sup(image,  zmin, qmed):
  
  """
  Parameters:
  
  image : numpy.ndarray (map data)
  zmin : The minimum value of intensity which is allowed
  qmed : The scaling factor with which the median is multiplied to fill the 
  values below ```zmin```
        
  return : numpy.ndarray 
  Image with background supressed
  
  """
  
  zmed = np.median(image_data)
  image = np.where( image < zmin, qmed * zmed, image )
  
  return image
  

Band Pass Filter

The actual filtering routine will depend on which scipy filtering module we will be using. This is just a pseudocode.

def filter(image, nsm1, nsm2):
  
  """
  Parameters:
      
       image : <numpy.ndarray>
               Background supressed image
       nsm1 : <int>
              Low pass filter constant. This must be odd.
       nsm2 : <int>
              High pass filter constant.
              ns2-ns1 = 2 is the optimum choice 
    
       return : numpy.ndarray 
  """
  if(nsm1>=nsm2):
    raise ValueError ("nsm1 should be less than nsm2")

  result_image = band_pass_filter(image)

  return result_image

Initialization of Loop Structures (Find Loop)

def find_loop(image_data):
  """
  image : <numpy.ndarray>
          band passed image
  
  returns <numpy.array>
          array of the position of individual loops
  """
  while(image.max() != 0):  # until the entire image is zeroed out
      pixel_pos = np.argwhere(image == image.max())
      loop_coords = trace_loop(image, pixel_pos) # new data with the traced loop being zeroed out
      image = subtract_loop(image, loop_coords)
      
return loop_coords # the array of the position of individual loops

Loop Tracing (trace_loop)

def trace_loop(image_data, pix):
  """
  image : <numpy.ndarray>
          Processed image 
  pix :  <np.array>
        Loop start position [X,Y]
  
  returns  <numpy.array>
            loop_coordinates
  """
  # implement the algorithm as described in the paper
  
  return s # loop_coordinates range(1,ns)

Loop Subtraction

def subtract_loop(image,loop_coords):
  """
  image : <numpy.ndarray>
          Processed image
  loop_coords : <numpy.ndarray>
                Positions comprising a loop

  returns :  <numpy.ndarray>
              Image with the loop subtracted
  """

  image[loop_coords] = 0
  
  return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment