Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 22, 2024
1 parent c38078f commit 779a65b
Show file tree
Hide file tree
Showing 41 changed files with 368 additions and 547 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ updates:
directory: "/"
schedule:
interval: daily
- package-ecosystem: 'github-actions'
directory: '/'
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: 'daily'
interval: "daily"
2 changes: 0 additions & 2 deletions carbonplan_trace/fire/grid_viirs_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def calc_buffer_distance(lats, buffer_m=375):


def rasterize_geom(geoms, transform, shape):

r = rasterize(
[(geom, 1) for geom in geoms],
out_shape=shape,
Expand Down Expand Up @@ -85,7 +84,6 @@ def open_target_grid(tile_id):


def process_one_year(year):

print(year)
gdf = geopandas.read_parquet(
f's3://carbonplan-climatetrace/inputs/processed/viirs/{year}.parquet'
Expand Down
3 changes: 1 addition & 2 deletions carbonplan_trace/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@


def get_cf_global_attrs(**attrs):

if 'history' not in attrs:
attrs['history'] = 'Created: {}'.format(time.ctime(time.time()))
attrs['history'] = f'Created: {time.ctime(time.time())}'

if 'insitution' not in attrs:
attrs['institution'] = 'CarbonPlan'
Expand Down
229 changes: 114 additions & 115 deletions carbonplan_trace/v0/data/catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ plugins:
- module: intake_xarray

sources:

hansen_change:
description: Global 30m treecover and loss/gain
metadata:
url: 'https://storage.cloud.google.com/earthenginepartners-hansen/GFC-2020-v1.8/download.html'
url: "https://storage.cloud.google.com/earthenginepartners-hansen/GFC-2020-v1.8/download.html"
tags:
- forest
parameters:
Expand All @@ -25,13 +24,13 @@ sources:
default: 060W
driver: rasterio
args:
urlpath: 'https://storage.googleapis.com/earthenginepartners-hansen/GFC-2020-v1.8/Hansen_GFC-2020-v1.8_{{ variable }}_{{ lat }}_{{ lon }}.tif'
chunks: {'y': 4000, 'x': 4000}
urlpath: "https://storage.googleapis.com/earthenginepartners-hansen/GFC-2020-v1.8/Hansen_GFC-2020-v1.8_{{ variable }}_{{ lat }}_{{ lon }}.tif"
chunks: { "y": 4000, "x": 4000 }

gfw_biomass:
description: Global 30m above ground biomass
metadata:
url: 'http://data.globalforestwatch.org/datasets/8f93a6f94a414f9588ce4657a39c59ff_1'
url: "http://data.globalforestwatch.org/datasets/8f93a6f94a414f9588ce4657a39c59ff_1"
tags:
- biomass
parameters:
Expand All @@ -45,125 +44,125 @@ sources:
default: 060W
driver: rasterio
args:
urlpath: 'http://gfw2-data.s3.amazonaws.com/climate/WHRC_biomass/WHRC_V4/Processed/{{ lat }}_{{lon}}_t_aboveground_biomass_ha_2000.tif'
chunks: {'y': 4000, 'x': 4000}
urlpath: "http://gfw2-data.s3.amazonaws.com/climate/WHRC_biomass/WHRC_V4/Processed/{{ lat }}_{{lon}}_t_aboveground_biomass_ha_2000.tif"
chunks: { "y": 4000, "x": 4000 }

gfw_emissions:
description: Global 30m emissions from Harris et al. 2021
metadata:
url: 'https://data.globalforestwatch.org/datasets/forest-greenhouse-gas-emissions-1'
tags:
- biomass
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: rasterio
args:
urlpath: 'https://data-api.globalforestwatch.org/dataset/gfw_forest_carbon_gross_emissions/v20210331/download/geotiff?grid=10/40000&tile_id={{ lat }}_{{lon}}&pixel_meaning={{ unit }}'
chunks: {'y': 4000, 'x': 4000}
description: Global 30m emissions from Harris et al. 2021
metadata:
url: "https://data.globalforestwatch.org/datasets/forest-greenhouse-gas-emissions-1"
tags:
- biomass
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: rasterio
args:
urlpath: "https://data-api.globalforestwatch.org/dataset/gfw_forest_carbon_gross_emissions/v20210331/download/geotiff?grid=10/40000&tile_id={{ lat }}_{{lon}}&pixel_meaning={{ unit }}"
chunks: { "y": 4000, "x": 4000 }

emissions_30m_partitioned:
description: Global 30m emissions from CarbonPlan partitioned into fire and non-fire related components. See carbonplan.org/blog/climate-trace-release for more information.
metadata:
url: ''
tags:
- emissions_partitioned
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: zarr
args:
urlpath: 'https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/tiles/30m/{{ lat }}_{{ lon }}_split.zarr'
consolidated: True
description: Global 30m emissions from CarbonPlan partitioned into fire and non-fire related components. See carbonplan.org/blog/climate-trace-release for more information.
metadata:
url: ""
tags:
- emissions_partitioned
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: zarr
args:
urlpath: "https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/tiles/30m/{{ lat }}_{{ lon }}_split.zarr"
consolidated: True

emissions_30m:
description: Global 30 m emissions from CarbonPlan
metadata:
url: ''
tags:
- emissions
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: zarr
args:
urlpath: 'https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/tiles/30m/{{ lat }}_{{ lon }}_tot.zarr'
consolidated: True
description: Global 30 m emissions from CarbonPlan
metadata:
url: ""
tags:
- emissions
parameters:
lat:
description: latitude of northwest corner of tile
type: str
default: 00N
lon:
description: longitude of northwest corner of tile
type: str
default: 060W
unit:
description: emission units
type: str
default: Mg_CO2e_ha
driver: zarr
args:
urlpath: "https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/tiles/30m/{{ lat }}_{{ lon }}_tot.zarr"
consolidated: True

emissions_3km:
description: Global 3 km emissions from CarbonPlan
metadata:
url: ''
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: 'https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/global/3000m/raster_tot.zarr'
consolidated: True
description: Global 3 km emissions from CarbonPlan
metadata:
url: ""
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: "https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/global/3000m/raster_tot.zarr"
consolidated: True

emissions_3km_partitioned:
description: Global 3 km emissions from CarbonPlan partitioned into fire and non-fire related components
metadata:
url: ''
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: 'https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/global/3000m/raster_split.zarr'
consolidated: True
description: Global 3 km emissions from CarbonPlan partitioned into fire and non-fire related components
metadata:
url: ""
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: "https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/global/3000m/raster_split.zarr"
consolidated: True

emissions_one_degree:
description: Global 1-degree resolution emissions from CarbonPlan
metadata:
url: ''
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: 'https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/blog/total_emissions.zarr'
consolidated: True
description: Global 1-degree resolution emissions from CarbonPlan
metadata:
url: ""
tags:
- emissions
parameters:
unit:
description: emission units
type: str
default: Mg_CO2e
driver: zarr
args:
urlpath: "https://carbonplan-climatetrace.s3.us-west-2.amazonaws.com/v0.4/blog/total_emissions.zarr"
consolidated: True
5 changes: 0 additions & 5 deletions carbonplan_trace/v0/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def process_one_tile(tile_id):

# calc emissions
if not (skip_existing and zarr_is_complete(tot_mapper) and zarr_is_complete(split_mapper)):

lat, lon = tile_id.split('_')
fire_da = open_fire_mask(tile_id).fillna(0)
change_ds = open_hansen_change_tile(lat, lon)
Expand Down Expand Up @@ -112,7 +111,6 @@ def process_one_tile(tile_id):
(tot_mapper, coarse_tot_mapper, tot_encoding),
(split_mapper, coarse_split_mapper, split_encoding),
]:

if not (skip_existing and zarr_is_complete(out_mapper)):
ds = xr.open_zarr(in_mapper, consolidated=True)

Expand All @@ -134,7 +132,6 @@ def combine_all_tiles(encoding_kinds=None):
encoding_kinds = [('tot', tot_encoding), ('split', split_encoding)]
print('combining all tiles')
for kind, encoding in encoding_kinds:

mapper = fsspec.get_mapper(coarse_full_template.format(kind=kind))

if not (skip_existing and zarr_is_complete(mapper)):
Expand Down Expand Up @@ -169,13 +166,11 @@ def rollup_shapes():
('tot', ['emissions']),
('split', ['emissions_from_clearing', 'emissions_from_fire']),
]:

ds = xr.open_zarr(coarse_full_template.format(kind=kind), consolidated=True)

mask = regionmask.mask_geopandas(shapes_df, ds['lon'], ds['lat'], numbers='numbers')

for var in var_names:

# this will trigger dask compute
df = ds[var].groupby(mask).sum().to_pandas()

Expand Down
3 changes: 0 additions & 3 deletions carbonplan_trace/v1/emissions_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def coarsen_tile(tile_id):
for in_mapper, out_mapper, encoding in [
(split_mapper, coarse_split_mapper, split_encoding),
]:

if not (skip_existing and zarr_is_complete(out_mapper)):
ds = utils.open_result_tile(
tile_id, variable='emissions', version='v1.2', resolution='30m', apply_masks=True
Expand All @@ -233,7 +232,6 @@ def combine_all_tiles(encoding_kinds=None):
print('combining all tiles')

for kind, encoding in encoding_kinds:

mapper = fsspec.get_mapper(coarse_full_template.format(kind=kind))

if not (skip_existing and zarr_is_complete(mapper)):
Expand Down Expand Up @@ -270,7 +268,6 @@ def rollup_shapes():
var_names = ['emissions_from_clearing', 'emissions_from_fire', 'sinks', 'net']

for var in var_names:

# this will trigger dask compute
df = ds[var].groupby(mask).sum().to_pandas()

Expand Down
2 changes: 1 addition & 1 deletion carbonplan_trace/v1/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def write_crs_dataset(ds, zone=None, overwrite=False):
one already exists!) so be sure you want to do that!
'''
if zone is None:
zone = '{}{}'.format(ds.utm_zone_number, ds.utm_zone_letter)
zone = f'{ds.utm_zone_number}{ds.utm_zone_letter}'
crs = CRS.from_dict({'proj': 'utm', 'zone': zone})
ds = ds.rio.set_crs(crs)
return ds
Expand Down
Loading

0 comments on commit 779a65b

Please sign in to comment.