Skip to content

Commit

Permalink
Edits to code formatting
Browse files Browse the repository at this point in the history
Simple edits to improve compliance with PEP8 (https://www.python.org/dev/peps/pep-0008/). Top-level functions & classes surrounded by two blank lines. Imports reordered & split across separate lines.
  • Loading branch information
bheberlein committed Apr 12, 2021
1 parent 1c214d1 commit 3023f6d
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 19 deletions.
8 changes: 7 additions & 1 deletion hypro/AtmCorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@

""" Functions to do atmospheric corrections. """

import logging, os, numpy as np
import os
import logging

import numpy as np

logger = logging.getLogger(__name__)


def atm_corr_band(atm_lut_WVC, atm_lut_VIS, atm_lut_VZA, atm_lut_RAA, atm_lut,
wvc_image, vis_image, vza_image, raa_image, rdn_image,
bg_mask):
Expand Down Expand Up @@ -63,6 +68,7 @@ def atm_corr_band(atm_lut_WVC, atm_lut_VIS, atm_lut_VZA, atm_lut_RAA, atm_lut,

return rho


def atm_corr_image(flight_dict):
""" Do atmospheric corrections on the whole image.
Expand Down
12 changes: 11 additions & 1 deletion hypro/AtmLUT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

""" Functions to build an atmospheric lookup table (LUT). """

import logging, os, numpy as np
import os
import logging

import numpy as np

logger = logging.getLogger(__name__)

# Define atmosphere database parameters. Do not make any change to them.
Expand All @@ -23,6 +27,7 @@
atm_db_VZA = np.array([0, 5, 10, 15, 20, 25, 30, 40]) # view zenith angle, in [deg]
atm_db_RAA = np.array([0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180]) # relative azimuth angle, in [deg]


def build_atm_lut(flight_dict):
""" Make an atmospheric lookup table.
Expand Down Expand Up @@ -154,6 +159,7 @@ def build_atm_lut(flight_dict):

logger.info('Write the raw ALT to %s.' %flight_dict['raw_atm_lut_file'])


def resample_atm_lut(resampled_atm_lut_file, raw_atm_lut_file, rdn_header_file):
""" Resample atmosphere lookup table radiance to sensor wavelengths.
Expand Down Expand Up @@ -218,6 +224,7 @@ def resample_atm_lut(resampled_atm_lut_file, raw_atm_lut_file, rdn_header_file):

logger.info('Write the resampled ALT to %s.' %resampled_atm_lut_file)


def write_binary_metadata(metadata_file, metadata):
""" Write the metadata of a binary file.
Expand Down Expand Up @@ -246,6 +253,7 @@ def write_binary_metadata(metadata_file, metadata):
fid.write('%s = %s\n' %(key, value))
fid.close()


def read_binary_metadata(metadata_file):
""" Read the metadata of a binary file.
Expand Down Expand Up @@ -286,6 +294,7 @@ def read_binary_metadata(metadata_file):

return metadata


def get_interp_range(xs, x):
""" Get the interpolation range. """

Expand All @@ -296,6 +305,7 @@ def get_interp_range(xs, x):

return {x_index0: x_delta0, x_index1: x_delta1}


def combos(indices):
""" Return all combinations of indices in a list of index sublists.
Expand Down
9 changes: 8 additions & 1 deletion hypro/Boresight.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@

""" Functions to do boresight calibration. """

import logging, os, numpy as np
import os
import logging

import numpy as np

logger = logging.getLogger(__name__)


def boresight_calibration(boresight_file, gcp_file, imugps_file, sensor_model_file, dem_image_file, boresight_options):
""" Do boresight calibration.
Expand Down Expand Up @@ -145,6 +150,7 @@ def boresight_calibration(boresight_file, gcp_file, imugps_file, sensor_model_fi

logger.info('Write boresight data to %s.' %boresight_file)


def cost_fun(boresight_offsets, flight_xyz, flight_imu, flight_sensor_model, dem_image, dem_ulxy, dem_pixel_size, gcp_xyz, boresight_options):
""" Cost function for boresight calibration.
Expand Down Expand Up @@ -178,6 +184,7 @@ def cost_fun(boresight_offsets, flight_xyz, flight_imu, flight_sensor_model, dem

return cost


def estimate_gcp_xyz(boresight_offsets, flight_xyz, flight_imu, flight_sensor_model, dem_image, dem_ulxy, dem_pixel_size, boresight_options):
""" Cestimate GCP map coordinates.
Expand Down
7 changes: 6 additions & 1 deletion hypro/Classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@

""" Functions to do image classifications. """

import logging, os, numpy as np
import os
import logging

import numpy as np

logger = logging.getLogger(__name__)

solar_flux_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),'data','solar_flux.dat')


def pre_classification(pre_class_image_file, rdn_image_file, sun_zenith, distance, background_mask_file=None):
""" Pre-classify the image.
Expand Down
3 changes: 2 additions & 1 deletion hypro/CreateSCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# Dept. of Forest and Wildlife Ecology
# University of Wisconsin - Madison

from ENVI import read_envi_header, write_envi_header
import numpy as np

from ENVI import read_envi_header, write_envi_header

if __name__ == "__main__":

raw_sca_file = '/media/nanfeng/My Passport/Hyspex/Output/CEDAR-CREEK-EW_20180724_01/merge/CEDAR-CREEK-EW_20180724_01_SCA'
Expand Down
8 changes: 7 additions & 1 deletion hypro/DEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@

""" Functions to process DEM data. """

import os
import logging

import numpy as np
from osgeo import gdal
import logging, os, numpy as np

logger = logging.getLogger(__name__)


def get_avg_elev(dem_image_file):
""" Get the average elevation of a DEM image.
Expand All @@ -39,6 +44,7 @@ def get_avg_elev(dem_image_file):

return avg_elev


def prepare_dem(dem_image_file, dem, imugps_file, fov, map_crs, pixel_size):
""" Prepare DEM data.
Expand Down
4 changes: 4 additions & 0 deletions hypro/ENVI.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
'z plot range',
'z plot titles']


def read_envi_header(file):
""" Read ENVI header.
Expand Down Expand Up @@ -164,6 +165,7 @@ def read_envi_header(file):

return header


def check_envi_required_fields(header):
""" Check ENVI required fields.
Expand All @@ -183,6 +185,7 @@ def check_envi_required_fields(header):
if header[field] is None:
raise ValueError('No value for %s!' %field)


def empty_envi_header():
""" Generate an empty ENVI header.
Expand All @@ -198,6 +201,7 @@ def empty_envi_header():

return header


def write_envi_header(file, header):
""" Write ENVI header.
Expand Down
14 changes: 13 additions & 1 deletion hypro/Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

""" Functions to make figures. """

import logging, os, matplotlib.pyplot as plt, numpy as np
import os
import logging

import numpy as np
from osgeo import gdal
import matplotlib.pyplot as plt

mpl_logger = logging.getLogger('matplotlib')
mpl_logger.setLevel(logging.WARNING)
logger = logging.getLogger(__name__)


def plot_angle_geometry(angle_geometry_figure_file, sca_image_file):
""" Plot the sun-target-view geometry in a polar coordinate system.
Expand Down Expand Up @@ -60,6 +65,7 @@ def plot_angle_geometry(angle_geometry_figure_file, sca_image_file):

logger.info('Save the angle geometry figure to %s.' %angle_geometry_figure_file)


def plot_image_area(image_area_figure_file, dem_image_file, igm_image_file, imugps_file):
""" Plot image area (DEM is used as the background).
Expand Down Expand Up @@ -124,6 +130,7 @@ def plot_image_area(image_area_figure_file, dem_image_file, igm_image_file, imug

logger.info('Save the image-area figure to %s.' %image_area_figure_file)


def linear_percent_stretch(raw_image):
""" Do linear percent stretch.
Expand Down Expand Up @@ -153,6 +160,7 @@ def linear_percent_stretch(raw_image):

return stretched_image


def make_quicklook(quicklook_figure_file, rdn_image_file, glt_image_file):
""" Make a RGB quicklook image.
Expand Down Expand Up @@ -235,6 +243,7 @@ def make_quicklook(quicklook_figure_file, rdn_image_file, glt_image_file):

logger.info('Save the quicklook figure to %s.' %quicklook_figure_file)


def plot_avg_rdn(avg_rdn_figure_file, avg_rdn_file):
""" Plot average radiance to a figure.
Expand Down Expand Up @@ -273,6 +282,7 @@ def plot_avg_rdn(avg_rdn_figure_file, avg_rdn_file):

logger.info('Save the average radiance spectra figure to %s.' %avg_rdn_figure_file)


def plot_wvc_model(wvc_model_figure_file, wvc_model_file):
""" Plot the WVC model to a figure.
Expand Down Expand Up @@ -312,6 +322,7 @@ def plot_wvc_model(wvc_model_figure_file, wvc_model_file):

logger.info('Save the WVC model figure to %s.' %wvc_model_file)


def plot_smile_effect(smile_effect_at_atm_features_figure_file, smile_effect_at_atm_features_file):
""" Plot smile effects at different atmosphere absorption features.
Expand Down Expand Up @@ -412,6 +423,7 @@ def plot_smile_effect(smile_effect_at_atm_features_figure_file, smile_effect_at_

logger.info('Save smile effect at atmosphere absorption features figure to %s.' %smile_effect_at_atm_features_figure_file)


def plot_wvc_histogram(wvc_histogram_figure_file, water_vapor_column_image_file):
""" Plot water vapor column histogram.
Expand Down
9 changes: 8 additions & 1 deletion hypro/GeoRectification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@

""" Functions to do geo-rectification. """

import logging, os, numpy as np
import os
import logging

import numpy as np

logger = logging.getLogger(__name__)


def orthorectify_sca(ortho_sca_image_file, sca_image_file, glt_image_file):
""" Do orthorectifications on SCA.
Expand Down Expand Up @@ -88,6 +93,7 @@ def orthorectify_sca(ortho_sca_image_file, sca_image_file, glt_image_file):

logger.info('Write the geo-rectified SCA image to %s.' %ortho_sca_image_file)


def orthorectify_dem(ortho_dem_image_file, igm_image_file, glt_image_file):
""" Do orthorectifications on DEM.
Expand Down Expand Up @@ -160,6 +166,7 @@ def orthorectify_dem(ortho_dem_image_file, igm_image_file, glt_image_file):

logger.info('Write the geo-rectified DEM image to %s.' %ortho_dem_image_file)


def orthorectify_rdn(ortho_rdn_image_file, rdn_image_file, glt_image_file):
""" Do orthorectifications on radiance.
Expand Down
19 changes: 16 additions & 3 deletions hypro/GeoReferencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@

""" Functions to do geo-referencing. """

import os
import logging
import warnings

import numpy as np
from osgeo import gdal
import logging, os, numpy as np
logger = logging.getLogger(__name__)
from numba import guvectorize, jit
import warnings


logger = logging.getLogger(__name__)

warnings.filterwarnings("ignore")


def calculate_igm(igm_image_file, imugps_file, sensor_model_file, dem_image_file, boresight_options):
""" Create an input geometry (IGM) image.
Expand Down Expand Up @@ -137,6 +144,7 @@ def calculate_igm(igm_image_file, imugps_file, sensor_model_file, dem_image_file

logger.info('Write the IGM to %s.' %igm_image_file)


def calculate_sca(sca_image_file, imugps_file, igm_image_file, sun_angles):
""" Create a scan angle (SCA) image.
Expand Down Expand Up @@ -223,6 +231,7 @@ def calculate_sca(sca_image_file, imugps_file, igm_image_file, sun_angles):

logger.info('Write the SCA to %s.' %sca_image_file)


def build_glt(glt_image_file, igm_image_file, pixel_size, map_crs):
""" Create a geographic lookup table (GLT) image.
Expand Down Expand Up @@ -417,6 +426,7 @@ def build_glt(glt_image_file, igm_image_file, pixel_size, map_crs):

logger.info('Write the GLT to %s.' %glt_image_file)


def get_scan_vectors(imu, sensor_model):
""" Get scan vectors.
Expand Down Expand Up @@ -507,6 +517,7 @@ def get_scan_vectors(imu, sensor_model):

return L0


def get_xyz0_xyz1(xyz, L0, h_min, h_max):
""" Get the starting and ending locations of ray tracing.
Expand Down Expand Up @@ -548,6 +559,7 @@ def get_xyz0_xyz1(xyz, L0, h_min, h_max):

return xyz0, xyz1


@guvectorize(['void(f8[:,:,:], f8[:,:,:], f8[:,:,:], f8[:,:], f8[:], f8[:,:,:])'],
'(b,n,m), (b,n,m), (b,n,m), (u,v), (c) -> (b,m,n)', cache=True)
def ray_tracer_ufunc(xyz0, xyz1, L0, dem, dem_gt, output):
Expand Down Expand Up @@ -596,6 +608,7 @@ def ray_tracer_ufunc(xyz0, xyz1, L0, dem, dem_gt, output):
for j in range(xyz0.shape[2]): # Iterate over scanlines
output[:,j,i] = ray_tracing(xyz0[:,i,j], xyz1[:,i,j], L0[:,i,j], dem, dem_origin, resolution)


@jit
def ray_tracing(XYZ0, XYZ1, V, DEM, DEM_X0Y0, DEM_Resolution):
""" Implement ray-tracing to get the pixel's geo-location and elevation.
Expand Down
Loading

0 comments on commit 3023f6d

Please sign in to comment.