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 Feb 5, 2024
1 parent 569afd8 commit 3219968
Show file tree
Hide file tree
Showing 35 changed files with 378 additions and 533 deletions.
2 changes: 1 addition & 1 deletion carbonplan_trace/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
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
11 changes: 4 additions & 7 deletions carbonplan_trace/v1/landsat_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ def grab_ds(item, bands_of_interest, cog_mask, utm_zone, utm_letter):
'''

if type(item) == str:
url_list = [item + '_{}.TIF'.format(band) for band in bands_of_interest]
url_list = [item + f'_{band}.TIF' for band in bands_of_interest]
else:
url_list = [
fix_link(item._stac_obj.assets['{}.TIF'.format(band)]['href'])
for band in bands_of_interest
fix_link(item._stac_obj.assets[f'{band}.TIF']['href']) for band in bands_of_interest
]
da_list = []
for url in url_list:
Expand Down Expand Up @@ -265,7 +264,6 @@ def grab_scene_coord_info(metadata):


def get_scene_utm_info(url, json_client):

'''
Get the USGS-provided UTM zone and letter for the specific landsat scene
Expand Down Expand Up @@ -330,7 +328,6 @@ def calc_NDVI(ds):


def calc_NDII(ds):

'''
Calculate NDII (Hardisky et al, 1984) based upon bands 4 and 5. *Note* only valid
for landsat 5 and 7 right now.
Expand Down Expand Up @@ -379,7 +376,7 @@ def make_datestamps(months, year):
include landsat scenes from jan/feb 2004.
'''
years = [year + 1 if int(month) < 3 else year for month in months]
return ['{}{}'.format(year, month) for (year, month) in zip(years, months)]
return [f'{year}{month}' for (year, month) in zip(years, months)]


def scene_seasonal_average(
Expand Down Expand Up @@ -425,7 +422,7 @@ def scene_seasonal_average(
valid_files.append(scene_store)
for file in valid_files:
scene_id = file[-40:]
url = 's3://{}/{}'.format(file, scene_id)
url = f's3://{file}/{scene_id}'
# try:
utm_zone, utm_letter = get_scene_utm_info(url, test_client)
cloud_mask_url = url + '_SR_CLOUD_QA.TIF'
Expand Down
4 changes: 1 addition & 3 deletions carbonplan_trace/v1/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def biomass(tiles, year):
complete_df = None
for tile in tiles:
if tile not in no_biomass_data_tiles:
file_mapper = fs.get_mapper(
's3://carbonplan-climatetrace/v1/biomass/{}.zarr'.format(tile)
)
file_mapper = fs.get_mapper(f's3://carbonplan-climatetrace/v1/biomass/{tile}.zarr')
ds = xr.open_zarr(file_mapper, consolidated=True)
df = ds.stack(unique_index=("record_index", "shot_number")).to_dataframe()
df = df[df['biomass'].notnull()]
Expand Down
4 changes: 2 additions & 2 deletions carbonplan_trace/v1/training_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def add_parquet_urls(df):
def find_pertinent_scenes_for_shots(lat_tag, lon_tag, scenes_in_tile_gdf):

file_mapper = fs.get_mapper(
"carbonplan-climatetrace/v2/data/intermediates/biomass/{}_{}.zarr".format(lat_tag, lon_tag)
f"carbonplan-climatetrace/v2/data/intermediates/biomass/{lat_tag}_{lon_tag}.zarr"
)
biomass = xr.open_zarr(file_mapper, consolidated=True).load().drop("spatial_ref")

Expand Down Expand Up @@ -245,7 +245,7 @@ def aggregate_parquet_files(
full_df = pd.concat([full_df, df])
if write:
tile_parquet_file_path = fs.get_mapper(
"carbonplan-climatetrace/v2/training/tiles/data_{}_{}.parquet".format(lat_tag, lon_tag)
f"carbonplan-climatetrace/v2/training/tiles/data_{lat_tag}_{lon_tag}.parquet"
)
utils.write_parquet(df, tile_parquet_file_path, access_key_id, secret_access_key)
else:
Expand Down
Loading

0 comments on commit 3219968

Please sign in to comment.