RSGISLib Image Calibration

Radiance

rsgislib.imagecalibration.landsat_to_radiance(output_img, gdalformat, bandDefnSeq)

Converts Landsat DN values to at sensor radiance.

Parameters
  • output_img – is a string containing the name of the output file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • bandDefnSeq – is a sequence of rsgislib.imagecalibration.CmdsLandsatRadianceGainsOffsets objects that define the inputs * bandName - Name of image band in output file. * fileName - input image file. * bandIndex - Index (starting from 1) of the band in the image file. * lMin - lMin value from Landsat header. * lMax - lMax value from Landsat header. * qCalMin - qCalMin value from Landsat header. * qCalMax - qCalMax value from Landsat header.

rsgislib.imagecalibration.landsat_to_radiance_multi_add(output_img, gdalformat, bandDefnSeq)

Converts Landsat DN values to at sensor radiance.

Parameters
  • output_img – is a string containing the name of the output file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • bandDefnSeq – is a sequence of rsgislib.imagecalibration.CmdsLandsatRadianceGainsOffsets objects that define the inputs * bandName - Name of image band in output file. * fileName - input image file. * bandIndex - Index (starting from 1) of the band in the image file. * addVal - RADIANCE_ADD value from Landsat header. * multiVal - RADIANCE_MULT value from Landsat header.

rsgislib.imagecalibration.spot5_to_radiance(input_img, output_img, gdalformat, band_defs)

Converts WorldView2 DN values to at sensor radiance.

Parameters
  • input_img – is a string containing the name of the input file

  • output_img – is a string containing the name of the output file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • band_defs – is a sequence of rsgislib.imagecalibration.CmdsSPOT5RadianceGainsOffsets objects in order of the input image bands that define the inputs * bandName - Name of image band in output file. * bandIndex - Index (starting from 1) of the output image band order (i.e., to reorder the image bands). * gain - PHYSICAL_GAIN value from SPOT5 XML header. * bias - PHYSICAL_BIAS value from SPOT5 XML header.

rsgislib.imagecalibration.worldview2_to_radiance(input_img, output_img, gdalformat, band_defs)

Converts WorldView2 DN values to at sensor radiance.

Parameters
  • input_img – is a string containing the name of the input file

  • output_img – is a string containing the name of the output file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • band_defs – is a sequence of rsgislib.imagecalibration.CmdsWorldView2RadianceGainsOffsets objects that define the inputs * bandName - Name of image band in output file. * bandIndex - Index (starting from 1) of the band in the image file. * absCalFact - ABSCALFACTOR value from WorldView2 XML header. * effBandWidth - EFFECTIVEBANDWIDTH value from WorldView2 XML header.

rsgislib.imagecalibration.toa_refl_to_radiance(input_imgs, output_img, gdalformat, datatype, scale_factor, solar_dist, solar_zenith, solar_irradiance)

Converts at sensor (Top of Atmosphere; TOA) reflectance values to at sensor radiance. This is the inverse of imagecalibration.radiance_to_toa_refl().

Parameters
  • input_imgs – can be either a single input image file with the same number of bands as the list of ESUN values or a list of single band images (same number of as the number of ESUN values).

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 if not wanted.

  • solar_dist – is a float specifying the solar-earth distance (see imagecalibration.calc_solar_distance).

  • solar_zenith – is a a float with the solar zenith in degrees at the time of the acquisition (note 90-solarElevation = solarZenith).

  • solar_irradiance – is a sequence of floats each with the name ‘irradiance’ (ESUN) which is in order of the bands in the input image.

Top-of Atmosphere Reflectance

rsgislib.imagecalibration.radiance_to_toa_refl(input_img, output_img, gdalformat, datatype, scale_factor, year, month, day, solar_zenith, solar_irradiance)

Converts at sensor radiance values to Top of Atmosphere Reflectance.

Parameters
  • input_img – is a string containing the name of the input image file

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 if not wanted.

  • year – is an int with the year of the sensor acquisition.

  • month – is an int with the month of the sensor acquisition.

  • day – is an int with the day of the sensor acquisition.

  • solar_zenith – is a a float with the solar zenith in degrees at the time of the acquisition (note 90-solarElevation = solarZenith).

  • solar_irradiance – is a sequence of floats each with the name ‘irradiance’ which is in order of the bands in the input image.

rsgislib.imagecalibration.landsat_thermal_rad_to_brightness(input_img, output_img, gdalformat, datatype, scale_factor, band_defs)

Converts Landsat TM thermal radiation to degrees celsius for at sensor temperature.

Parameters
  • input_img – is a string containing the name of the input file path.

  • output_img – is a string containing the name of the output file path.

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 for no scaling.

  • band_defs – is a sequence of rsgislib.imagecalibration.CmdsLandsatThermalCoeffs objects that define the inputs * bandName - Name of image band in output file. * bandIndex - Index (starting from 1) of the band in the image file. * k1 - k1 coefficient from Landsat header. * k2 - k2 coefficient from Landsat header.

Surface Reflectance (6S)

rsgislib.imagecalibration.apply_6s_coeff_single_param(input_img, output_img, gdalformat, datatype, scale_factor, no_data_val, use_no_data, band_coeffs)

Converts at sensor radiance values to surface reflectance by applying coefficients from the 6S model for each band (aX, bX, cX).

Parameters
  • input_img – is a string containing the name of the input image file

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 for no scaling.

  • no_data_val – is a float which if all bands contain that value will be ignored.

  • use_no_data – is a boolean as to whether the no data value specified is to be used.

  • band_coeffs – is a sequence of objects with the following named fields. * band - An integer specifying the image band in the input file. * aX - A float for the aX coefficient. * bX - A float for the bX coefficient. * cX - A float for the cX coefficient.

rsgislib.imagecalibration.apply_6s_coeff_elev_aot_lut_param(in_rad_img, in_dem_img, in_aot_img, output_img, gdalformat, datatype, scale_factor, no_data_val, use_no_data, band_lut_coeffs)

Converts at sensor radiance values to surface reflectance by applying coefficients from the 6S model for each band (aX, bX, cX), where the coefficients can be varied for surface elevation.

Parameters
  • in_rad_img – is a string containing the name of the input Radiance image file

  • in_dem_img – is a string containing the name of the input DEM image file (needs to be the same projection and resolution as radiance image.)

  • in_aot_img – is a string containing the name of the input AOT image file

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 for no scaling.

  • no_data_val – is a float which if all bands contain that value will be ignored.

  • use_no_data – is a boolean as to whether the no data value specified is to be used.

  • band_lut_coeffs

    is a sequence of objects with the following named fields - note these are expected to be in elevation order (low to high and then AOT order (low to high). * ‘Elev’ - The elevation for the element in the LUT (in metres).

    • ’AOT’ - The AOT value for this element within the LUT.

    • ’Coeffs’ - The sequence of 6S coeffecients for the given elevation and AOT for the element in the LUT.
      • ’band’ - An integer specifying the image band in the input file (band numbers start at 1).

      • ’aX’ - A float for the aX coefficient.

      • ’bX’ - A float for the bX coefficient.

      • ’cX’ - A float for the cX coefficient.

rsgislib.imagecalibration.apply_6s_coeff_elev_lut_param(in_rad_img, in_dem_img, output_img, gdalformat, datatype, scale_factor, no_data_val, use_no_data, band_lut_coeffs)

Converts at sensor radiance values to surface reflectance by applying coefficients from the 6S model for each band (aX, bX, cX), where the coefficients can be varied for surface elevation.

Parameters
  • in_rad_img – is a string containing the name of the input Radiance image file

  • in_dem_img – is a string containing the name of the input DEM image file (needs to be the same projection and resolution as radiance image.)

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • scale_factor – is a float which can be used to scale the output pixel values (e.g., multiple by 1000), set as 1 for no scaling.

  • no_data_val – is a float which if all bands contain that value will be ignored.

  • use_no_data – is a boolean as to whether the no data value specified is to be used.

  • band_lut_coeffs

    is a sequence of objects with the following named fields - note these are expected to be in elevation order (low to high). * ‘Elev’ - The elevation for the element in the LUT (in metres). * ‘Coeffs’ - The sequence of 6S coeffecients for the given elevation for the element in the LUT.

    • ’band’ - An integer specifying the image band in the input file (band numbers start at 1).

    • ’aX’ - A float for the aX coefficient.

    • ’bX’ - A float for the bX coefficient.

    • ’cX’ - A float for the cX coefficient.

rsgislib.imagecalibration.calc_standardised_reflectance_sd2010(in_data_msk_img, in_sref_img, in_solar_irr_img, in_inc_angle_img, in_exit_angle_img, output_img, gdalformat, scale_factor, brdf_beta, out_inc_angle, out_exit_angle)

Calculate standardised reflectance, with respect to solar and view angles, as defined by Shepherd and Dymond (2010)

Parameters
  • in_data_msk_img – is a string containing the name and path to a binary mask specifying the region to be calculated (1 = True)

  • in_sref_img – is a surface reflectance image

  • in_solar_irr_img – is the solar irradiance for each band of the SREF image. The image will have four times the number of bands as the SREF with Direct, Diffuse, Environment and Total irradiance for each (generated by imagecalibration.calc_irradiance_img_elev_lut).

  • in_inc_angle_img – is a string containing the name and path to a file with the incidence angle for each pixel.

  • in_exit_angle_img – is a string containing the name and path to a file with the existance angle for each pixel.

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • scale_factor – is a float with the scale factor to convert the SREF image to a range of 0-1 (e.g., 1000)

  • brdf_beta – is the beta parameters in equation 8 in Shepherd and Dymond (2010) for solar elevations between 50 - 70 degrees a value of 1 can be used.

  • out_inc_angle – is the incidence angle to which the output image is standardised to (Recommend: 0).

  • out_exit_angle – is the exitance angle to which the output image is standardised to (Recommend: 0).

Surface Reflectance (DOS)

rsgislib.imagecalibration.apply_subtract_offsets(input_img, in_offs_img, output_img, gdalformat, datatype, non_neg_int, use_no_data, no_data_val, dark_refl_val)

This function performs a dark obejct subtraction (DOS) using a set of defined offsets for retriving surface reflectance.

Parameters
  • input_img – is a string containing the name of the input image file

  • in_offs_img – is a string containing the name of the input offsets image file, which must have the same number of bands as the input image.:param output_img: is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • non_neg_int – is a boolean specifying whether any negative values from the offset application should be removed (i.e., set to 1; 0 being no data).

  • use_no_data – a boolean specifying whether a no data value is present within the input image.

  • no_data_val – is a float specifying the no data value for the input image.

  • dark_refl_val – is a float specifying the minimum value within the reflectance value used for the dark targets used for the subtraction

rsgislib.imagecalibration.apply_subtract_single_offsets(input_img, output_img, gdalformat, datatype, non_neg_int, use_no_data, no_data_val, dark_refl_val, band_offsets)

This function performs a dark object subtraction (DOS) using a set of defined offsets for retriving surface reflectance.

Parameters
  • input_img – is a string containing the name of the input image file

  • outputFile – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • datatype – is an containing one of the values from rsgislib.TYPE_*

  • non_neg_int – is a boolean specifying whether any negative values from the offset application should be removed (i.e., set to 1; 0 being no data).

  • use_no_data – a boolean specifying whether a no data value is present within the input image.

  • no_data_val – is a float specifying the no data value for the input image.

  • dark_refl_val – is a float specifying the minimum value within the reflectance value used for the dark targets used for the subtraction:param band_offsets: is a list of offset values to be applied to the input image bands (specified with keyword ‘offset’).

rsgislib.imagecalibration.perform_dos_calc(inputFile, outputFile, gdalformat='KEA', nonNegative=True, noDataVal=0, darkObjReflVal=0, darkObjPercentile=0.01, copyBandNames=True, calcStatsPyd=True)

A command to perform a dark object subtraction (DOS) on an input image.

Parameters
  • inputFile – input image to which the DOS method is to be applied. Typically, this image with be in top of atmosphere reflectance (TOA)

  • outputFile – the output image file

  • gdalformat – the output image file format (default = KEA)

  • nonNegative – is a boolean specifying where negative output pixel values will be accepted (Dafualt is True; i.e., no negative values)

  • noDataVal – is the no data value within the input image file.

  • darkObjReflVal – is an offset which is applied to all pixel values to make a minimum reflectance value (Default = 0)

  • darkObjPercentile – is the percentile of the input image used to define the dark object threshold, range is 0 - 1 (Default is 0.01; i.e., 1%).

  • copyBandNames – is a boolean specifying that the band names of the input image should be copied to the output image file (Default: True)

  • calcStatsPyd – is a boolean specifying that the image stats and pyramids should be calculated on the output image (Default: True)

import rsgislib.imagecalibration
rsgislib.imagecalibration.perform_dos_calc("LS5TM_20110701_lat52lon421_r24p204_rad_toa.kea", 'LS5TM_20110701_lat52lon421_r24p204_rad_toa_dos.kea")

Irradiance

rsgislib.imagecalibration.calc_irradiance_img_elev_lut(in_data_msk_img, in_dem_img, in_inc_angle_img, in_slope_img, in_sref_img, in_shadow_img, output_img, gdalformat, solar_zenith, scale_factor, coeff_lut)

Calculate the incoming irradiance (Direct, Diffuse, Environment and Total) for sloped surfaces (Eq 1. Shepherd and Dymond 2010).

Parameters
  • in_data_msk_img – is a string containing the name and path to a binary mask specifying the region to be calculated (1 = True)

  • in_dem_img – is a string containing the name of the input DEM image file.

  • in_inc_angle_img – is a string containing the name and path to a file with the incidence angle for each pixel.

  • in_slope_img – is a string containing the name and path to a file with the slope in degrees for each pixel.

  • in_sref_img – is a surface reflectance image with the same number of bands for measurements are provided for in the LUT

  • in_shadow_img – is a binary mask image for the areas of the image in direct shadow (pixel value 1) and therefore don’t recieve any direct irradiance.

  • output_img – is a string containing the name of the output image file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • solar_zenith – is a float with the solar zenith for the whole scene.

  • scale_factor – is a float with the scale factor to convert the SREF image to a range of 0-1

  • coeff_lut

    is a sequence of objects with the following named fields - note these are expected to be in elevation order (low to high). * ‘Elev’ - The elevation for the element in the LUT (in metres). * ‘BandVals’ - The sequence of solar irradiance values for the bands in the SREF image.

    • ’band’ - An integer specifying the image band in the input file (band numbers start at 1).

    • ’DirIrr’ - A float for the direct irradiance for this band and elevation (i.e., as provided by 6S).

    • ’DifIrr’ - A float for the diffuse irradiance for this band and elevation (i.e., as provided by 6S).

    • ’EnvIrr’ - A float for the environment irradiance for this band and elevation (i.e., as provided by 6S).

Cloud Masking

rsgislib.imagecalibration.calc_clear_sky_regions(cloudsImg, validAreaImg, outputClearSkyMask, outFormat, tmpPath='tmpClearSky', deleteTmpFiles=True, initClearSkyRegionDist=5000, initClearSkyRegionMinSize=3000, finalClearSkyRegionDist=1000, morphSize=21)

Given a cloud mask, identify the larger extent regions of useful clear-sky regions.

Parameters
  • cloudsImg – An image with the input mask of the cloud (pixel == 1) and shadow (pixel == 2)

  • validAreaImg – A mask of the image data area (1 = valid and 0 = not-valid; i.e., outside of the data area)

  • outputClearSkyMask – The output mask of the clear sky areas

  • outFormat – The output image format.

  • tmpPath – The path for temporay images produced during the processing to be stored (Default: ‘tmpClearSky’; Note. all temp files are generated as KEA files).

  • deleteTmpFiles – Boolean as to whether the intermediate files should be deleted following processing (Default: True - delete files).

  • initClearSkyRegionDist – The distance in metres from a cloud/shadow object for the initial identification of clear sky regions (Default: 5000)

  • initClearSkyRegionMinSize – The minimum size (in pixels) of the initial clear sky regions (Default: 3000 pixels)

  • finalClearSkyRegionDist – The distance in metres from a cloud/shadow object for the final boundaries of the clear sky regions (Default: 1000)

  • morphSize – the size of the circular morphological operator used to tidy up the result (Default: 21)

import rsgislib.imagecalibration
cloudsImg = "Outputs/LS8_20160605_lat52lon261_r24p203_clouds.kea"
validAreaImg = "Outputs/LS8_20160605_lat52lon261_r24p203_valid.kea"
outputMask = "Outputs/LS8_20160605_lat52lon261_r24p203_openskyvalid.kea"
tmpPath = "temp"
rsgislib.imagecalibration.calc_clear_sky_regions(cloudsImg, validAreaImg, outputMask, 'KEA', tmpPath)
rsgislib.imagecalibration.calc_cloud_shadow_mask(in_cld_msk_img, in_refl_img, in_vld_img, output_img, dark_band, gdalformat, scale_factor, tmp_img_base, tmp_img_ext, solar_azimuth, solar_zenith, sensor_azimuth, sensor_zenith, rm_tmp_imgs)

Calculate a cloud shadow mask from an inputted cloud mask.

Parameters
  • in_cld_msk_img – is a string containing the name of the input cloud mask

  • in_refl_img – is a string containing the name of the input image TOA reflectance file

  • in_vld_img – is a string containing the name of a binary image specifying the valid area of the image data (1 is valid area)

  • output_img – is a string containing the name of the output image file

  • dark_band – is an integer specifying the image band from the reflectance image which is to used to find the shadows (the NIR is often recommended).

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • scale_factor – is a float with the scale factor used to multiple the input image reflectance data.

  • tmp_img_base – is a string specifying a base path and name for the tmp images used for this processing

  • tmp_img_ext – is a string for the file extention of the output images (e.g., .kea)

  • solar_azimuth – is the solar azimuth of the input image

  • solar_zenith – is the solar azimuth of the input image

  • sensor_azimuth – is the sensor azimuth of the input image

  • sensor_zenith – is the sensor azimuth of the input image

  • rm_tmp_imgs – is a bool specifying whether the tmp images should be deleted at the end of the processing (Optional; Default = True)

Utilities

rsgislib.imagecalibration.saturated_pixels_mask(output_img, gdalformat, band_defs)

Creates a mask of the saturated image pixels on a per band basis.

Parameters
  • output_img – is a string containing the name of the output file

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • band_defs – is a sequence of rsgislib.imagecalibration.CmdsSaturatedPixel objects that define the inputs * bandName - Name of image band in output file. * fileName - input image file. * bandIndex - Index (starting from 1) of the band in the image file. * satVal - Saturation value for the image band.

rsgislib.imagecalibration.calc_nadir_img_view_angle(input_img, output_img, gdalformat, altitude, min_xx_col, min_xy_col, max_xx_col, max_xy_col, min_yx_col, min_yy_col, max_yx_col, max_yy_col)

Calculate the sensor view angle for each pixel for a nadir sensor. Need to provide the satellite altitude in metres, for Landsat this is 705000.0.

Parameters
  • input_img – is a string containing the name/path of the input file for the image footprint. This file needs to be to have a RAT with only one clump with pixel value 1.

  • output_img – is a string for the name/path of the output file with the view angles.

  • gdalformat – is a string for the GDAL format

  • altitude – is a float in metres for the satellite altitude.

  • min_xx_col – is a string for the minXX column in the RAT.

  • min_xy_col – is a string for the minXY column in the RAT.

  • max_xx_col – is a string for the maxXX column in the RAT.

  • max_xy_col – is a string for the maxXY column in the RAT.

  • min_yx_col – is a string for the minYX column in the RAT.

  • min_yy_col – is a string for the minYY column in the RAT.

  • max_yx_col – is a string for the maxYX column in the RAT.

  • max_yy_col – is a string for the maxYY column in the RAT.

rsgislib.imagecalibration.get_julian_day(year, month, day)

Calculates the julian day for the input date.

Parameters
  • year – is an int with the year of the sensor acquisition.

  • month – is an int with the month of the sensor acquisition.

  • day – is an int with the day of the sensor acquisition.

Returns

julianDay - float

rsgislib.imagecalibration.calc_solar_distance(julian_day)

Calculates the earth-solar distance from the given julian day.

Parameters

julian_day – is an int with the julian day of the sensor acquisition.

Returns

solarDistance - float

rsgislib.imagecalibration.get_esun_value(radiance, toaRefl, day, month, year, solarZenith)

Get the ESUN value where a radiance and TOA Reflectance value are known for a pixel.

Parameters
  • radiance – input at sensor radiance value.

  • toaRefl – input the known at sensor (top of atmosphere) reflectance value for the given radiance.

  • day – input the day of the acquisition.

  • month – input the month of the acquisition.

  • year – input the year of the acquisition.

  • solarZenith – input the solar zenith angle for the acquisition.

Returns

esun radiance

Solar Angles

rsgislib.imagecalibration.solarangles.get_solar_irr_convention_solar_azimuth_from_usgs(solarAz)

IN: USGS Convertion:

         N (0)
         |
W (-90)-----E (90)
         |
  (-180) S (180)

OUT: Solar Irradiance Convertion:

         N (0)
         |
W (270)-----E (90)
         |
         S (180)
rsgislib.imagecalibration.solarangles.get_solar_irr_convention_solar_azimuth_from_trad(solarAz)

IN: Traditional Convertion:

  (-180) N (180)
         |
W (-90)-----E (90)
         |
         S (0)

OUT: Solar Irradiance Convertion:

         N (0)
         |
W (270)-----E (90)
         |
         S (180)
rsgislib.imagecalibration.solarangles.calc_solar_azimuth_zenith(inputImg, inImgDateTime, outputImg, gdalformat)

Function which calculate a solar azimuth (band 1) and zenith (band 2) image.

Parameters
  • inputImg – input image file (can be any image with a spatial header)

  • inImgDateTime – a datatime object for the data/time of the acquasition

  • outputImg – output image file and path

  • gdalformat – output file format (e.g., KEA)

Landsat Collection 2 Utilities

rsgislib.imagecalibration.sensorlvl1data.create_stacked_toa_ls_oli_cl2_lv1_img(input_file: str, out_dir: str, tmp_dir: str, scale_factor: int = 10000, gdalformat: str = 'KEA', delete_inter_data: bool = True, inc_full_qa_pxl_img: bool = False)

A function which extracts the USGS collection-2 level-1 data and creates a single multi-band TOA image file in the output directory. Note the output data type is 32bit integer and the no data value is -9999. A cloud mask and valid area images are also provided and extracted from the pixel QA image provided in the collection 2 package. Note this function just works for Landsat 8 and 9 data.

Parameters
  • input_file – file name and path to the input TAR file.

  • out_dir – output directory where the output file will be written.

  • tmp_dir – a temporary directory where intermediate files will be written.

  • scale_factor – the scale factor applied to the output reflectance values. default is 10,000

  • gdalformat – the output file format.

  • delete_inter_data – delete any intermediate files created is True (Default)

  • inc_full_qa_pxl_img – Include the full pixel QA image split into individual bands in the output.

from rsgislib.imagecalibration.sensorlvl2data import create_stacked_sref_ls_oli_cl2_lv2_img
create_stacked_sref_ls_oli_cl2_lv2_img("LC08_L2SP_135046_20210319_20210328_02_T1.tar", "outputs", "tmp", gdalformat="GTIFF")
rsgislib.imagecalibration.sensorlvl2data.create_stacked_sref_ls_oli_cl2_lv2_img(input_file: str, out_dir: str, tmp_dir: str, scale_factor: int = 10000, gdalformat: str = 'KEA', delete_inter_data: bool = True, inc_full_qa_pxl_img: bool = False)

A function which extracts the USGS collection-2 level-2 data and creates a single multi-band image file in the output directory. Note the output data type is 32bit integer and the no data value is -9999. A cloud mask and valid area images are also provided and extracted from the pixel QA image provided in the collection 2 package. Note this function just works for Landsat 8 and 9 data.

Parameters
  • input_file – file name and path to the input TAR file.

  • out_dir – output directory where the output file will be written.

  • tmp_dir – a temporary directory where intermediate files will be written.

  • scale_factor – the scale factor applied to the output reflectance values. default is 10,000

  • gdalformat – the output file format.

  • delete_inter_data – delete any intermediate files created is True (Default)

  • inc_full_qa_pxl_img – Include the full pixel QA image split into individual bands in the output.

from rsgislib.imagecalibration.sensorlvl2data import create_stacked_sref_ls_oli_cl2_lv2_img
create_stacked_sref_ls_oli_cl2_lv2_img("LC08_L2SP_135046_20210319_20210328_02_T1.tar", "outputs", "tmp", gdalformat="GTIFF")
rsgislib.imagecalibration.sensorlvl2data.parse_landsat_c2_qa_pixel_img(input_img: str, output_img: str, gdalformat: str = 'KEA')

A function which will parse the bit QA Pixel image from Landsat Collection 2 and create a multi-band output - 1 band per variable. While this takes up more disk space than the bit encoded image it is much easier to use!

The output bands are:
  • Fill - No data regions (0-1)

  • DilatedCloud - Cloud dilation regions (0-1)

  • Cirrus - Cirrus clouds present (0-1)

  • Cloud - Clouds present (0-1)

  • CloudShadow - Cloud shadow present (0-1)

  • Snow - Snow present (0-1)

  • Clear - Clear sky pixel (0-1)

  • Water - Water present (0-1)

  • CloudConfidence - Confidence of cloud classification (1-4)

  • CloudShadowConfidence - Confidence of cloud shadows classification (1-4)

  • SnowIceConfidence - Confidence of snow and ice classification (1-4)

  • CirrusConfidence - Confidence of cirrus classification (1-4)

Parameters
  • input_img – The input landsat pixel QA image.

  • output_img – The output image path - the output image will have 12 bands.

  • gdalformat – the output image format.

Sentinel-2 Utilities

rsgislib.imagecalibration.sensorlvl2data.create_stacked_sen2_esa_l2a_img(input_safe: str, out_dir: str, tmp_dir: str, out_res_10m: bool = True, sharpen_10m: bool = True, scale_factor: int = 10000, gdalformat: str = 'KEA', datatype: int = 3, delete_inter_data: bool = True, resample_10m_method=2, resample_20m_method=5, use_multi_core: bool = False)
Parameters
  • input_safe

  • out_dir

  • tmp_dir

  • out_res_10m

  • sharpen_10m

  • scale_factor

  • gdalformat

  • datatype

  • delete_inter_data

  • resample_10m_method

  • resample_20m_method

  • use_multi_core