more cleanup
This commit is contained in:
parent
0f24212f0a
commit
059264ef6c
|
@ -738,7 +738,6 @@ def execute(args):
|
|||
op=numpy.multiply, # PET = ET0 * KC
|
||||
rasters=[eto_path, tmp_Kc_raster_path],
|
||||
target_path=tmp_pet_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=nodata_dict['out_nodata']),
|
||||
target_path_list=[tmp_pet_path],
|
||||
dependent_task_list=[create_Kc_raster_task],
|
||||
|
@ -770,8 +769,7 @@ def execute(args):
|
|||
op=wyield_op,
|
||||
rasters=[fractp_path, precip_path],
|
||||
target_path=wyield_path,
|
||||
target_nodata=nodata_dict['out_nodata'],
|
||||
target_dtype=numpy.float32),
|
||||
target_nodata=nodata_dict['out_nodata']),
|
||||
target_path_list=[wyield_path],
|
||||
dependent_task_list=[calculate_fractp_task, align_raster_stack_task],
|
||||
task_name='calculate_wyield')
|
||||
|
@ -784,8 +782,7 @@ def execute(args):
|
|||
op=numpy.multiply, # AET = fractp * precip
|
||||
rasters=[fractp_path, precip_path],
|
||||
target_path=aet_path,
|
||||
target_nodata=nodata_dict['out_nodata'],
|
||||
target_dtype=numpy.float32),
|
||||
target_nodata=nodata_dict['out_nodata']),
|
||||
target_path_list=[aet_path],
|
||||
dependent_task_list=[
|
||||
calculate_fractp_task, create_veg_raster_task,
|
||||
|
|
|
@ -459,7 +459,6 @@ def execute(args):
|
|||
rasters=[file_registry['tot_c_' + scenario_type],
|
||||
file_registry['tot_c_cur']],
|
||||
target_path=file_registry[output_key],
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_CARBON_NODATA),
|
||||
target_path_list=[file_registry[output_key]],
|
||||
dependent_task_list=[
|
||||
|
|
|
@ -1515,12 +1515,12 @@ def _calculate_npv(
|
|||
(1 + discount_rate) ** years_since_baseline))
|
||||
|
||||
pygeoprocessing.raster_map(
|
||||
op=lambda *seq_arrays: numpy.sum(seq, axis=0) * valuation_factor,
|
||||
op=lambda *seq_arrays: numpy.sum(
|
||||
seq_arrays, axis=0) * valuation_factor,
|
||||
rasters=[
|
||||
path for year, path in net_sequestration_rasters.items() if
|
||||
year <= target_raster_year],
|
||||
target_path=target_raster_path,
|
||||
target_dtype=numpy.float32)
|
||||
target_path=target_raster_path)
|
||||
|
||||
|
||||
def _calculate_stocks_after_baseline_period(
|
||||
|
@ -1550,8 +1550,7 @@ def _calculate_stocks_after_baseline_period(
|
|||
pygeoprocessing.raster_map(
|
||||
op=lambda baseline, accum: baseline + (accum * n_years),
|
||||
rasters=[baseline_stock_raster_path, yearly_accumulation_raster_path],
|
||||
target_path=target_raster_path,
|
||||
target_dtype=numpy.float32)
|
||||
target_path=target_raster_path)
|
||||
|
||||
|
||||
def _calculate_accumulation_over_time(
|
||||
|
|
|
@ -775,7 +775,6 @@ def calculate_crop_production(lulc_path, yield_path, crop_lucode,
|
|||
lulc == crop_lucode, _yield * pixel_area_ha, 0),
|
||||
rasters=[lulc_path, yield_path],
|
||||
target_path=target_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_NODATA_YIELD)
|
||||
|
||||
|
||||
|
|
|
@ -723,7 +723,6 @@ def execute(args):
|
|||
phosphorus_yield_raster_path,
|
||||
potassium_yield_raster_path],
|
||||
target_path=crop_production_raster_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_NODATA_YIELD),
|
||||
target_path_list=[crop_production_raster_path],
|
||||
dependent_task_list=dependent_task_list,
|
||||
|
|
|
@ -825,8 +825,7 @@ def _calculate_total_degradation(
|
|||
pygeoprocessing.raster_map(
|
||||
op=total_degradation,
|
||||
rasters=deg_raster_list,
|
||||
target_path=deg_sum_raster_path,
|
||||
target_dtype=numpy.float32)
|
||||
target_path=deg_sum_raster_path)
|
||||
|
||||
|
||||
def _compute_rarity_operation(
|
||||
|
@ -872,8 +871,7 @@ def _compute_rarity_operation(
|
|||
pygeoprocessing.raster_map(
|
||||
op=lambda base, cover_x: cover_x,
|
||||
rasters=[base_lulc_path_band[0], lulc_path_band[0]],
|
||||
target_path=new_cover_path[0],
|
||||
target_dtype=numpy.float32)
|
||||
target_path=new_cover_path[0])
|
||||
|
||||
LOGGER.info('Starting rarity computation on'
|
||||
f' {os.path.basename(lulc_path_band[0])} land cover.')
|
||||
|
@ -1019,8 +1017,7 @@ def _decay_distance(dist_raster_path, max_dist, decay_type, target_path):
|
|||
pygeoprocessing.raster_map(
|
||||
op=decay_op,
|
||||
rasters=[dist_raster_path],
|
||||
target_path=target_path,
|
||||
target_dtype=numpy.float32)
|
||||
target_path=target_path)
|
||||
|
||||
|
||||
def _validate_threat_path(threat_path, lulc_key):
|
||||
|
|
|
@ -756,7 +756,6 @@ def execute(args):
|
|||
op=_inverse_op,
|
||||
rasters=[f_reg['thresholded_slope_path']],
|
||||
target_path=f_reg['s_factor_inverse_path'],
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA),
|
||||
target_path_list=[f_reg['s_factor_inverse_path']],
|
||||
dependent_task_list=[threshold_slope_task],
|
||||
|
@ -827,7 +826,6 @@ def execute(args):
|
|||
op=_mult_op,
|
||||
rasters=[load_path, f_reg['runoff_proxy_index_path']],
|
||||
target_path=modified_load_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA),
|
||||
target_path_list=[modified_load_path],
|
||||
dependent_task_list=[load_task, runoff_proxy_index_task],
|
||||
|
@ -893,7 +891,6 @@ def execute(args):
|
|||
op=numpy.multiply, # export = load * ndr
|
||||
rasters=[surface_load_path, ndr_path],
|
||||
target_path=surface_export_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA),
|
||||
target_path_list=[surface_export_path],
|
||||
dependent_task_list=[
|
||||
|
@ -933,7 +930,6 @@ def execute(args):
|
|||
op=numpy.multiply, # export = load * ndr
|
||||
rasters=[f_reg['sub_load_n_path'], f_reg['sub_ndr_n_path']],
|
||||
target_path=f_reg['n_subsurface_export_path'],
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA),
|
||||
target_path_list=[f_reg['n_subsurface_export_path']],
|
||||
dependent_task_list=[
|
||||
|
@ -948,7 +944,6 @@ def execute(args):
|
|||
op=_sum_op,
|
||||
rasters=[surface_export_path, f_reg['n_subsurface_export_path']],
|
||||
target_path=f_reg['n_total_export_path'],
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA),
|
||||
target_path_list=[f_reg['n_total_export_path']],
|
||||
dependent_task_list=[
|
||||
|
@ -1417,7 +1412,6 @@ def _calculate_ndr(
|
|||
(1 + numpy.exp((ic_0_param - ic) / k_param))),
|
||||
rasters=[effective_retention_path, ic_factor_path],
|
||||
target_path=target_ndr_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA)
|
||||
|
||||
|
||||
|
@ -1430,7 +1424,6 @@ def _calculate_sub_ndr(
|
|||
(1 - numpy.exp(-5 * dist_to_channel / crit_len_sub))),
|
||||
rasters=[dist_to_channel_path],
|
||||
target_path=target_sub_ndr_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_TARGET_NODATA)
|
||||
|
||||
|
||||
|
|
|
@ -1401,7 +1401,7 @@ def _sum_arrays(*array_list):
|
|||
def _calculate_habitat_nesting_index(
|
||||
substrate_path_map, species_substrate_index_map,
|
||||
target_habitat_nesting_index_path):
|
||||
"""Closure for HN(x, s) = max_n(N(x, n) ns(s,n)) calculation."""
|
||||
"""Calculate HN(x, s) = max_n(N(x, n) ns(s,n))."""
|
||||
|
||||
substrate_path_list = [
|
||||
substrate_path_map[substrate_id]
|
||||
|
@ -1436,11 +1436,14 @@ def _multiply_by_scalar(raster_path, scalar, target_path):
|
|||
def _calculate_pollinator_supply_index(
|
||||
habitat_nesting_suitability_path, floral_resources_path,
|
||||
species_abundance, target_path):
|
||||
"""Create a closure for species abundance to multiply later.
|
||||
"""Calculate pollinator supply index..
|
||||
|
||||
Args:
|
||||
species_abundance (float): value to use in `__call__` when
|
||||
calculating pollinator abundance.
|
||||
habitat_nesting_suitability_path (str): path to habitat nesting
|
||||
suitability raster
|
||||
floral_resources_path (str): path to floral resources raster
|
||||
species_abundance (float): species abundance value
|
||||
target_path (str): path to write out result raster
|
||||
|
||||
Returns:
|
||||
None.
|
||||
|
|
|
@ -727,7 +727,6 @@ def execute(args):
|
|||
# Taskgraph needs a __name__ attribute, so adding one here.
|
||||
# kernel_creation_functions[KERNEL_LABEL_POWER].__name__ = (
|
||||
# 'functools_partial_decay_power')
|
||||
#
|
||||
|
||||
decay_function = args['decay_function']
|
||||
LOGGER.info(f'Using decay function {decay_function}')
|
||||
|
|
|
@ -508,7 +508,6 @@ class TestCBC2(unittest.TestCase):
|
|||
'price_table_path': os.path.join(target_dir,
|
||||
'price_table.csv'),
|
||||
'discount_rate': 4,
|
||||
'n_workers': 1
|
||||
}
|
||||
|
||||
with open(args['price_table_path'], 'w') as price_table:
|
||||
|
|
|
@ -427,7 +427,8 @@ class SDRTests(unittest.TestCase):
|
|||
target_ls_factor_path)
|
||||
|
||||
ls = pygeoprocessing.raster_to_numpy_array(target_ls_factor_path)
|
||||
nodata = float(numpy.finfo(numpy.float32).max)
|
||||
expected_ls = numpy.array(
|
||||
[[0.253996, 0.657229, 1.345856, 1.776729, 49.802994, -1]],
|
||||
[[0.253996, 0.657229, 1.345856, 1.776729, 49.802994, nodata]],
|
||||
dtype=numpy.float32)
|
||||
numpy.testing.assert_allclose(ls, expected_ls, rtol=1e-6)
|
||||
|
|
|
@ -412,21 +412,6 @@ class UCMTests(unittest.TestCase):
|
|||
header='column', header_name='green_area'))]
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_flat_disk_kernel(self):
|
||||
"""UCM: test flat disk kernel."""
|
||||
import natcap.invest.urban_cooling_model
|
||||
|
||||
kernel_filepath = os.path.join(self.workspace_dir, 'kernel.tif')
|
||||
natcap.invest.urban_cooling_model.flat_disk_kernel(
|
||||
1000, kernel_filepath)
|
||||
|
||||
kernel_raster = gdal.OpenEx(kernel_filepath, gdal.OF_RASTER)
|
||||
kernel_band = kernel_raster.GetRasterBand(1)
|
||||
self.assertAlmostEqual(
|
||||
numpy.sum(kernel_band.ReadAsArray())/1000,
|
||||
numpy.ceil(1000**2*numpy.pi/1000),
|
||||
places=0)
|
||||
|
||||
def test_do_energy_valuation_option(self):
|
||||
"""UCM: test separate valuation options."""
|
||||
import natcap.invest.urban_cooling_model
|
||||
|
|
|
@ -169,45 +169,16 @@ class UNATests(unittest.TestCase):
|
|||
population_array.sum(), resampled_population_array.sum(),
|
||||
rtol=1e-3)
|
||||
|
||||
def test_density_decay_simple(self):
|
||||
"""UNA: Test density decay."""
|
||||
def test_density_kernel(self):
|
||||
"""UNA: Test the density kernel."""
|
||||
from natcap.invest import urban_nature_access
|
||||
|
||||
expected_distance = 200
|
||||
kernel_filepath = os.path.join(self.workspace_dir, 'kernel.tif')
|
||||
|
||||
urban_nature_access._create_kernel_raster(
|
||||
urban_nature_access._kernel_density,
|
||||
expected_distance, kernel_filepath)
|
||||
|
||||
expected_shape = (expected_distance*2+1,) * 2
|
||||
kernel_info = pygeoprocessing.get_raster_info(kernel_filepath)
|
||||
kernel_array = pygeoprocessing.raster_to_numpy_array(kernel_filepath)
|
||||
self.assertEqual(kernel_info['raster_size'], expected_shape)
|
||||
numpy.testing.assert_allclose(
|
||||
47123.867, # obtained from manual inspection
|
||||
kernel_array.sum())
|
||||
self.assertEqual(0.75, kernel_array.max())
|
||||
self.assertEqual(0, kernel_array.min())
|
||||
|
||||
def test_density_decay_normalized(self):
|
||||
"""UNA: Test normalized density decay."""
|
||||
from natcap.invest import urban_nature_access
|
||||
|
||||
expected_distance = 200
|
||||
kernel_filepath = os.path.join(self.workspace_dir, 'kernel.tif')
|
||||
|
||||
urban_nature_access._create_kernel_raster(
|
||||
urban_nature_access._kernel_density,
|
||||
expected_distance, kernel_filepath, normalize=True)
|
||||
|
||||
expected_shape = (expected_distance*2+1,) * 2
|
||||
kernel_info = pygeoprocessing.get_raster_info(kernel_filepath)
|
||||
kernel_array = pygeoprocessing.raster_to_numpy_array(kernel_filepath)
|
||||
self.assertEqual(kernel_info['raster_size'], expected_shape)
|
||||
numpy.testing.assert_allclose(1, kernel_array.sum())
|
||||
self.assertAlmostEqual(1.5915502e-05, kernel_array.max())
|
||||
self.assertEqual(0, kernel_array.min())
|
||||
max_distance = 3
|
||||
distance = numpy.array([0, 1, 2, 3, 4])
|
||||
kernel = urban_nature_access._kernel_density(distance, max_distance)
|
||||
# These regression values are calculated by hand
|
||||
expected_array = numpy.array([.75, 2/3, 5/12, 0, 0])
|
||||
numpy.testing.assert_allclose(expected_array, kernel)
|
||||
|
||||
def test_power_kernel(self):
|
||||
"""UNA: Test the power kernel."""
|
||||
|
|
Loading…
Reference in New Issue