Skip to content

Commit

Permalink
Merge pull request #139 from davemfish/task/127-update-lulc-data
Browse files Browse the repository at this point in the history
Task/127 update lulc data
  • Loading branch information
dcdenu4 authored Aug 27, 2024
2 parents e29effb + 7c1180b commit 45e991f
Show file tree
Hide file tree
Showing 20 changed files with 8,234 additions and 8,083 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ These are data used by the python worker. Download these to your local

local path which mounts in container | (bucket where source file can be found)
- `appdata/lulc_overlay_3857.tif` | (natcap-urban-online-datasets-**public**)
- `appdata/invest-data/CGIAR_et0_annual_epsg_3857.tif` | (natcap-urban-online-datasets)

- `appdata/invest-data/et0_annual_cgiar_3857.tif` | (natcap-urban-online-datasets)
- `appdata/invest-data/acs_tract_3857.gpkg` | (natcap-urban-online-datasets)
- `appdata/invest-data/acs_tract_poverty.csv` | (natcap-urban-online-datasets)
- `appdata/invest-data/acs_tract_race.csv` | (natcap-urban-online-datasets)
- `appdata/invest-data/population_san_antonio_updated_02_27.tif` | (natcap-urban-online-datasets)
- `appdata/invest-data/population_per_pixel_2020_3857.tif` | (natcap-urban-online-datasets)

Data Documentation:
https://drive.google.com/drive/u/1/folders/1FxlHVWFfICc5j-f7z9sWUBrVJj1Lw1zQ
https://drive.google.com/drive/u/1/folders/1ZUF_RLc2L-fglFdsJOVg-xSD7J9Gz1BF


## Necessary API tokens
Expand Down
2,109 changes: 2,109 additions & 0 deletions appdata/invest-data/biophysical_tables/carbon__nlcd_nlud_tree.csv

Large diffs are not rendered by default.

1,985 changes: 1,985 additions & 0 deletions appdata/invest-data/biophysical_tables/ucm__nlcd_nlud_tree.csv

Large diffs are not rendered by default.

2,401 changes: 0 additions & 2,401 deletions appdata/invest-data/biophysical_tables/ucm_nlcd_simple_nlud_trees.csv

This file was deleted.

1,985 changes: 1,985 additions & 0 deletions appdata/invest-data/biophysical_tables/una__nlcd_nlud_tree.csv

Large diffs are not rendered by default.

2,401 changes: 0 additions & 2,401 deletions appdata/invest-data/biophysical_tables/urban_carbon_nlcd_simple_nlud_trees.csv

This file was deleted.

This file was deleted.

2,773 changes: 1,985 additions & 788 deletions appdata/lulc_crosswalk.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion appdata/lulc_crosswalk.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions appdata/nlud_colormap.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"color": "#3690eb",
"name": "Waterbody (Artificial)"
},
"4": {
"color": "#d1def8",
"name": "Waterbody (Perennial Ice/Snow)"
},
"11": {
"color": "#645CBB",
"name": "Residential (Dense urban)"
Expand Down Expand Up @@ -43,6 +47,14 @@
"color": "#df73ff",
"name": "Institutional"
},
"41": {
"color": "#df73ff",
"name": "Institutional (Private)"
},
"42": {
"color": "#df73ff",
"name": "Institutional (Public)"
},
"51": {
"color": "#9c9c9c",
"name": "Transportation (Airport)"
Expand Down Expand Up @@ -83,10 +95,18 @@
"color": "#4ce600",
"name": "Undifferentiated park"
},
"131": {
"color": "#4ce600",
"name": "Developed park (Urban park)"
},
"132": {
"color": "#55ff00",
"name": "Developed park (Golf course)"
},
"133": {
"color": "#55ff00",
"name": "Developed park (Resort/ski area)"
},
"134": {
"color": "#4ce600",
"name": "Developed park (Other)"
Expand All @@ -95,8 +115,16 @@
"color": "#057548",
"name": "Natural park"
},
"151": {
"color": "#267300",
"name": "Conservation (Public)"
},
"152": {
"color": "#267300",
"name": "Conservation (Public-limited access)"
},
"153": {
"color": "#267300",
"name": "Conservation (Private easement)"
}
}
57 changes: 27 additions & 30 deletions backend-worker/invest_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,53 @@
f"Could not find {INVEST_DATA} at any known locations")
LOGGER.info(f"Using InVEST data at {INVEST_BASE_PATH}")

EVAPOTRANSPIRATION = os.path.join(
INVEST_BASE_PATH, "et0_annual_cgiar_3857.tif")
CARBON_TABLE_PATH = os.path.join(
INVEST_BASE_PATH, 'biophysical_tables',
'carbon__nlcd_nlud_tree.csv')
UCM_TABLE_PATH = os.path.join(
INVEST_BASE_PATH, 'biophysical_tables',
'ucm__nlcd_nlud_tree.csv')
UNA_TABLE_PATH = os.path.join(
INVEST_BASE_PATH, 'biophysical_tables',
'una__nlcd_nlud_tree.csv')
POPULATION_RASTER_PATH = os.path.join(
INVEST_BASE_PATH,
'population_per_pixel_2020_3857.tif')


def carbon(lulc_path, workspace_dir, study_area_wkt):
args_dict = {
"workspace_dir": workspace_dir,
"calc_sequestration": True,
"carbon_pools_path": "",
"carbon_pools_path": CARBON_TABLE_PATH,
"do_redd": False,
"do_valuation": False,
"lulc_cur_path": lulc_path
}

args_dict['carbon_pools_path'] = os.path.join(
INVEST_BASE_PATH,
'biophysical_tables',
'urban_carbon_nlcd_simple_nlud_trees.csv')

return args_dict


def urban_cooling(lulc_path, workspace_dir, study_area_wkt):
# Parameter values from
# https://github.com/chrisnootenboom/urban-workflow/blob/master/configs/inputs_config.yaml
cooling_distance = 450 # meters
lulc_info = pygeoprocessing.get_raster_info(lulc_path)
aoi_vector_path = os.path.join(workspace_dir, 'aoi.geojson')
aoi_geom = shapely.wkt.loads(study_area_wkt).buffer(cooling_distance)
pygeoprocessing.shapely_geometry_to_vector(
[aoi_geom], aoi_vector_path, lulc_info['projection_wkt'], 'GEOJSON')

# Parameter values from
# https://github.com/chrisnootenboom/urban-workflow/blob/master/configs/inputs_config.yaml
args_dict = {
"workspace_dir": workspace_dir,
"aoi_vector_path": aoi_vector_path,
"lulc_raster_path": lulc_path,
"biophysical_table_path": UCM_TABLE_PATH,
"do_energy_valuation": False,
"do_productivity_valuation": False,
"ref_eto_raster_path": os.path.join(
INVEST_BASE_PATH, "CGIAR_et0_annual_epsg_3857.tif"),
"ref_eto_raster_path": EVAPOTRANSPIRATION,
"cc_method": "factors",
"cc_weight_albedo": "0.2",
"cc_weight_eti": "0.2",
Expand All @@ -66,17 +81,6 @@ def urban_cooling(lulc_path, workspace_dir, study_area_wkt):
# "uhi_max": "3.56" # TODO: derive from location
}

lulc_info = pygeoprocessing.get_raster_info(lulc_path)

aoi_geom = shapely.wkt.loads(study_area_wkt).buffer(cooling_distance)
pygeoprocessing.shapely_geometry_to_vector(
[aoi_geom], aoi_vector_path, lulc_info['projection_wkt'], 'GEOJSON')

args_dict['biophysical_table_path'] = os.path.join(
INVEST_BASE_PATH,
'biophysical_tables',
'ucm_nlcd_simple_nlud_trees.csv')

return args_dict


Expand All @@ -88,21 +92,14 @@ def urban_nature_access(lulc_path, workspace_dir, study_area_wkt):
pygeoprocessing.shapely_geometry_to_vector(
[aoi_geom], aoi_vector_path, lulc_info['projection_wkt'], 'GEOJSON')

lulc_attribute_table_path = os.path.join(
INVEST_BASE_PATH,
'biophysical_tables',
'urban_nature_access_nlcd_simple_nlud_trees.csv')
population_raster_path = os.path.join(
INVEST_BASE_PATH,
'population_san_antonio_updated_02_27.tif')
args_dict = {
"workspace_dir": workspace_dir,
"admin_boundaries_vector_path": aoi_vector_path,
"aggregate_by_pop_group": False,
"decay_function": "dichotomy",
"lulc_attribute_table": lulc_attribute_table_path,
"lulc_attribute_table": UNA_TABLE_PATH,
"lulc_raster_path": lulc_path,
"population_raster_path": population_raster_path,
"population_raster_path": POPULATION_RASTER_PATH,
"search_radius": search_radius,
"search_radius_mode": "uniform radius",
"urban_nature_demand": "16.7"
Expand Down
6 changes: 3 additions & 3 deletions backend-worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from osgeo import osr
from PIL import Image

from natcap.invest import carbon
from natcap.invest import urban_cooling_model
from natcap.invest import urban_nature_access
from natcap.invest import utils

import carbon_urban_pools # Modified from natcap.invest.carbon w/ carbon pools
import invest_args
import invest_results

Expand All @@ -50,7 +50,7 @@

LULC_FILENAME = 'lulc_overlay_3857.tif'
LULC_RASTER_PATHS = {
'vsigs': f'/vsigs/natcap-urban-online-datasets-public/{LULC_FILENAME}',
'vsigs': f'/vsigs/natcap-urban-online-datasets-public/{LULC_FILENAME}', # TODO: does not work
'docker': f'/opt/appdata/{LULC_FILENAME}',
'local': os.path.join(os.path.dirname(__file__), '..', 'appdata',
LULC_FILENAME)
Expand Down Expand Up @@ -97,7 +97,7 @@
"derive_results": invest_results.urban_cooling,
},
CARBON: {
"api": carbon_urban_pools,
"api": carbon,
"build_args": invest_args.carbon,
"derive_results": invest_results.carbon,
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-bullseye
FROM node:20

# Just install the packages; the source code will be loaded in later.
RUN mkdir /opt/frontend
Expand Down
88 changes: 45 additions & 43 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
{
"name": "urban-es-modeler",
"private": true,
"version": "0.0.0",
"scripts": {
"start": "vite",
"start-docker": "cross-env MODE=docker vite --host 0.0.0.0 --port 3000",
"build": "vite build",
"serve": "vite preview",
"test": "vitest run --dir tests --coverage",
"test-e2e": "vitest run --dir tests-e2e"
},
"dependencies": {
"@blueprintjs/core": "^4.4.0",
"dotenv": "^16.0.0",
"jsts": "^2.9.3",
"localforage": "^1.10.0",
"ol": "^6.15.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.18.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@vitejs/plugin-react": "^4.0.1",
"@vitest/coverage-v8": "^0.32.2",
"c8": "^7.11.3",
"cross-env": "^7.0.3",
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^39.3.2",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"happy-dom": "^9.20.3",
"jsdom": "^22.1.0",
"puppeteer": "^20.7.4",
"vite": "^4.4.9",
"vitest": "^0.34.0"
}
}
"name": "urban-es-modeler",
"private": true,
"version": "0.0.0",
"scripts":
{
"start": "vite",
"start-docker": "cross-env MODE=docker vite --host 0.0.0.0 --port 3000",
"build": "vite build",
"serve": "vite preview",
"test": "vitest run --dir tests --coverage",
"test-e2e": "vitest run --dir tests-e2e"
},
"dependencies":
{
"@blueprintjs/core": "^4.4.0",
"dotenv": "^16.0.0",
"jsts": "^2.9.3",
"localforage": "^1.10.0",
"ol": "^6.15.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies":
{
"@babel/eslint-parser": "^7.18.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@vitejs/plugin-react": "^4.0.1",
"@vitest/coverage-v8": "^0.32.2",
"c8": "^7.11.3",
"cross-env": "^7.0.3",
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"happy-dom": "^9.20.3",
"jsdom": "^22.1.0",
"puppeteer": "^20.7.4",
"vite": "^4.4.9",
"vitest": "^0.34.0"
}
}
18 changes: 14 additions & 4 deletions frontend/src/edit/lulcMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
getNLUDTier2,
getNLUDTier3,
getNLCD,
getTreeCover,
getLucode,
} from '../requests';

const treeOptions = ['none', 'low', 'medium', 'high'];

export default function LulcMenu(props) {
const [nlud2Options, setNlud2Options] = useState([]);
const [nlud3Options, setNlud3Options] = useState([]);
const [nlcdOptions, setNlcdOptions] = useState([]);
const [treeOptions, setTreeOptions] = useState([]);
const [nlud2, setNlud2] = useState(null);
const [nlud3, setNlud3] = useState(null);
const [nlcd, setNlcd] = useState(null);
const [tree, setTree] = useState(treeOptions[0]);
const [tree, setTree] = useState(null);

useEffect(() => {
(async () => {
Expand Down Expand Up @@ -48,7 +48,17 @@ export default function LulcMenu(props) {
setNlcd(options[0]);
}
})();
}, [nlud3]);
}, [nlud2, nlud3]);

useEffect(() => {
(async () => {
if ([nlud2, nlud3, nlcd].every((x) => typeof x === 'string')) {
const options = await getTreeCover(nlud2, nlud3, nlcd);
setTreeOptions(options);
setTree(options[0]);
}
})();
}, [nlud2, nlud3, nlcd]);

useEffect(() => {
if ([nlud2, nlud3, nlcd, tree].every((x) => typeof x === 'string')) {
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,22 @@ export async function getNLCD(tier2, tier3) {
);
}

export async function getTreeCover(tier2, tier3, nlcd) {
return (
window.fetch(`${apiBaseURL}/lucodes/tree`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
nlud_tier_2: tier2,
nlud_tier_3: tier3,
nlcd: nlcd,
}),
})
.then((response) => response.json())
.catch((error) => console.log(error))
);
}

export async function getLucode(tier2, tier3, nlcd, tree) {
return (
window.fetch(`${apiBaseURL}/lucodes/lucode`, {
Expand Down
1 change: 1 addition & 0 deletions scripts/lulc_crosswalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
with open('../appdata/lulc_crosswalk.json', 'w', encoding='utf-8') as file:
jsonstring = json.dumps(data)
file.write(jsonstring + '\n')

Loading

0 comments on commit 45e991f

Please sign in to comment.