def determine_average_emissivity( outname, emissivity_output, landcover_map, avg_lse_expression, quiet=True, ): """ Produce an average emissivity map based on FROM-GLC map covering the region of interest. """ msg = ( '\n|i Determining average land surface emissivity based on a look-up table ' ) if not quiet: msg += ('| Expression:\n\n {exp}') msg = msg.format(exp=avg_lse_expression) g.message(msg) avg_lse_expression = replace_dummies( avg_lse_expression, instring=DUMMY_MAPCALC_STRING_FROM_GLC, outstring=landcover_map, ) avg_lse_equation = EQUATION.format( result=outname, expression=avg_lse_expression, ) grass.mapcalc(avg_lse_equation, overwrite=True) if not quiet: run('r.info', map=outname, flags='r') # save land surface emissivity map? if emissivity_output: run('g.rename', raster=(outname, emissivity_output))
def determine_delta_emissivity( outname, delta_emissivity_output, landcover_map, delta_lse_expression, quiet=True, ): """ Produce a delta emissivity map based on the FROM-GLC map covering the region of interest. """ msg = "\n|i Determining delta land surface emissivity based on a " "look-up table " if not quiet: msg += "| Expression:\n\n {exp}" msg = msg.format(exp=delta_lse_expression) g.message(msg) delta_lse_expression = replace_dummies( delta_lse_expression, instring=DUMMY_MAPCALC_STRING_FROM_GLC, outstring=landcover_map, ) delta_lse_equation = EQUATION.format(result=outname, expression=delta_lse_expression) grass.mapcalc(delta_lse_equation, overwrite=True) if not quiet: run("r.info", map=outname, flags="r") # save delta land surface emissivity map? if delta_emissivity_output: run("g.rename", raster=(outname, delta_emissivity_output))
def digital_numbers_to_radiance( outname, band, radiance_expression, null=False, quiet=False, ): """ Convert Digital Number values to TOA Radiance. For details, see in Landsat8 class. Zero (0) DNs set to NULL here (not via the class' function). """ if null: msg = "\n|i Setting zero (0) Digital Numbers in {band} to NULL" msg = msg.format(band=band) g.message(msg) run('r.null', map=band, setnull=0) msg = "\n|i Rescaling {band} digital numbers to spectral radiance " msg = msg.format(band=band) if not quiet: msg += '| Expression: ' msg += radiance_expression g.message(msg) radiance_expression = replace_dummies(radiance_expression, instring=DUMMY_MAPCALC_STRING_DN, outstring=band) radiance_equation = EQUATION.format(result=outname, expression=radiance_expression) grass.mapcalc(radiance_equation, overwrite=True) if not quiet: run('r.info', map=outname, flags='r')
def radiance_to_brightness_temperature( outname, radiance, temperature_expression, quiet=False, ): """ Convert Spectral Radiance to At-Satellite Brightness Temperature. For details see Landsat8 class. """ temperature_expression = replace_dummies( temperature_expression, instring=DUMMY_MAPCALC_STRING_RADIANCE, outstring=radiance) msg = "\n|i Converting spectral radiance to at-Satellite Temperature " if not quiet: msg += "| Expression: " + str(temperature_expression) g.message(msg) temperature_equation = EQUATION.format(result=outname, expression=temperature_expression) grass.mapcalc(temperature_equation, overwrite=True) if not quiet: run('r.info', map=outname, flags='r')
def determine_delta_emissivity( outname, delta_emissivity_output, landcover_map, delta_lse_expression, info=False, ): """ Produce a delta emissivity map based on the FROM-GLC map covering the region of interest. """ msg = ('\n|i Determining delta land surface emissivity based on a ' 'look-up table ') if info: msg += (f'\n Expression:\n\n {delta_lse_expression}') g.message(msg) delta_lse_expression = replace_dummies( delta_lse_expression, instring=DUMMY_MAPCALC_STRING_FROM_GLC, outstring=landcover_map, ) delta_lse_equation = EQUATION.format( result=outname, expression=delta_lse_expression, ) grass.mapcalc(delta_lse_equation, overwrite=True) if info: run('r.info', map=outname, flags='r') # save delta land surface emissivity map? if delta_emissivity_output: run('g.rename', raster=(outname, delta_emissivity_output))
def estimate_cwv_big_expression( outname, cwv_output, t10, t11, cwv_expression, quiet=True, ): """ Derive a column water vapor map using a single mapcalc expression based on eval. *** To Do: evaluate -- does it work correctly? *** ! """ msg = "\n|i Estimating atmospheric column water vapor " if quiet: msg += "| Expression:\n" g.message(msg) if quiet: msg = replace_dummies(cwv_expression, in_ti=t10, out_ti="T10", in_tj=t11, out_tj="T11") msg += "\n" g.message(msg) cwv_equation = EQUATION.format(result=outname, expression=cwv_expression) grass.mapcalc(cwv_equation, overwrite=True) if quiet: run("r.info", map=outname, flags="r") # save Column Water Vapor map? if cwv_output: # strings for metadata history_cwv = "FixMe -- Column Water Vapor model: " history_cwv += "FixMe -- Add equation?" title_cwv = "Column Water Vapor" description_cwv = "Column Water Vapor" units_cwv = "g/cm^2" source1_cwv = "FixMe" source2_cwv = "FixMe" # history entry run( "r.support", map=outname, title=title_cwv, units=units_cwv, description=description_cwv, source1=source1_cwv, source2=source2_cwv, history=history_cwv, ) run("g.rename", raster=(outname, cwv_output))
def estimate_lst( outname, t10, t11, landcover_map, landcover_class, avg_lse_map, delta_lse_map, cwv_map, lst_expression, rounding, celsius, quiet=True, ): """ Produce a Land Surface Temperature map based on a mapcalc expression returned from a SplitWindowLST object. Parameters ---------- outname t10 t11 landcover_map landcover_class avg_lse_map delta_lse_map cwv_map lst_expression rounding celsius quiet Inputs are: - brightness temperature maps t10, t11 - column water vapor map - a temporary filename - a valid mapcalc expression """ msg = "\n|i Estimating land surface temperature " g.message(msg) if not quiet: msg += "| Expression:\n" msg = lst_expression msg += "\n" g.message(msg) if landcover_map: split_window_expression = replace_dummies( lst_expression, in_avg_lse=DUMMY_MAPCALC_STRING_AVG_LSE, out_avg_lse=avg_lse_map, in_delta_lse=DUMMY_MAPCALC_STRING_DELTA_LSE, out_delta_lse=delta_lse_map, in_cwv=DUMMY_MAPCALC_STRING_CWV, out_cwv=cwv_map, in_ti=DUMMY_MAPCALC_STRING_T10, out_ti=t10, in_tj=DUMMY_MAPCALC_STRING_T11, out_tj=t11, ) elif landcover_class: split_window_expression = replace_dummies( lst_expression, in_cwv=DUMMY_MAPCALC_STRING_CWV, out_cwv=cwv_map, in_ti=DUMMY_MAPCALC_STRING_T10, out_ti=t10, in_tj=DUMMY_MAPCALC_STRING_T11, out_tj=t11, ) if rounding: split_window_expression = "(round({swe}, 2, 0.5))".format( swe=split_window_expression) if celsius: split_window_expression = "({swe}) - 273.15".format( swe=split_window_expression) split_window_equation = EQUATION.format( result=outname, expression=split_window_expression, ) grass.mapcalc( split_window_equation, overwrite=True, ) if not quiet: run("r.info", map=outname, flags="r")
def estimate_lst( outname, t10, t11, landcover_map, landcover_class, avg_lse_map, delta_lse_map, cwv_map, lst_expression, rounding, celsius, info=False, ): """ Produce a Land Surface Temperature map based on a mapcalc expression returned from a SplitWindowLST object. Parameters ---------- outname t10 t11 landcover_map landcover_class avg_lse_map delta_lse_map cwv_map lst_expression rounding celsius info Inputs are: - brightness temperature maps t10, t11 - column water vapor map - a temporary filename - a valid mapcalc expression """ msg = '\n|i Estimating land surface temperature ' if info: msg += f'\n Expression:\n {lst_expression}' g.message(msg) if landcover_map: split_window_expression = replace_dummies( lst_expression, in_avg_lse=DUMMY_MAPCALC_STRING_AVG_LSE, out_avg_lse=avg_lse_map, in_delta_lse=DUMMY_MAPCALC_STRING_DELTA_LSE, out_delta_lse=delta_lse_map, in_cwv=DUMMY_MAPCALC_STRING_CWV, out_cwv=cwv_map, in_ti=DUMMY_MAPCALC_STRING_T10, out_ti=t10, in_tj=DUMMY_MAPCALC_STRING_T11, out_tj=t11) elif landcover_class: split_window_expression = replace_dummies( lst_expression, in_cwv=DUMMY_MAPCALC_STRING_CWV, out_cwv=cwv_map, in_ti=DUMMY_MAPCALC_STRING_T10, out_ti=t10, in_tj=DUMMY_MAPCALC_STRING_T11, out_tj=t11) if rounding: split_window_expression = f'(round({split_window_expression}, 2, 0.5))' msg = '\n|i Rounding temperature figures to 2 decimals' g.message(msg) if celsius: split_window_expression = f'({split_window_expression}) - 273.15' msg = '\n|i Converting temperature figures to Celsius degrees' g.message(msg) split_window_equation = EQUATION.format( result=outname, expression=split_window_expression, ) grass.mapcalc( split_window_equation, overwrite=True, ) if info: run('r.info', map=outname, flags='r')
def estimate_cwv( temporary_map, cwv_map, t10, t11, window_size, median=False, info=False, ): """ Derive a column water vapor map using a single mapcalc expression based on eval. *** To Do: evaluate -- does it work correctly? *** ! """ msg = "\n|i Estimating atmospheric column water vapor" cwv = Column_Water_Vapor(window_size, t10, t11) if median: msg += f'\n|! Computing median value in a {window_size}^2 pixel neighborhood' cwv_expression = cwv._cwv_expression_median() else: cwv_expression = cwv._cwv_expression_mean() # if accuracy: # if median: # accuracy_expression = cwv._accuracy_expression_median() # else: # accuracy_expression = cwv._accuracy_expression_mean() # else: # accuracy_expression = str() if info: msg += '\n Expression:\n' msg = replace_dummies( cwv_expression, in_ti=t10, out_ti='T10', in_tj=t11, out_tj='T11', ) g.message(msg) cwv_equation = EQUATION.format( result=temporary_map, expression=cwv_expression, ) grass.mapcalc(cwv_equation, overwrite=True) # accuracy_equation = EQUATION.format(result=outname, expression=accuracy_expression) # grass.mapcalc(accuracy_equation, overwrite=True) if info: run('r.info', map=temporary_map, flags='r') if cwv_map: history_cwv = f'\nColumn Water Vapor = {cwv._equation}' history_cwv += f'\nSpatial window size: {cwv.window_size}^2' title_cwv = 'Column Water Vapor' description_cwv = 'Column Water Vapor based on MSWVCM' units_cwv = 'g/cm^2' source1_cwv = cwv.citation source2_cwv = 'FixMe' run("r.support", map=temporary_map, title=title_cwv, units=units_cwv, description=description_cwv, source1=source1_cwv, source2=source2_cwv, history=history_cwv, ) run('g.rename', raster=(temporary_map, cwv_map))