Skip to content

Commit 8a13d23

Browse files
import odc 1.9 fixes from branch
2 parents f2d10a9 + cb87aea commit 8a13d23

14 files changed

Lines changed: 66 additions & 70 deletions

.github/workflows/test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
- name: Pre-pull layers
2020
run: docker compose pull
2121

22-
- name: Activate Docker cache
23-
uses: satackey/action-docker-layer-caching@v0.0.8
24-
# Ignore the failure of a step and avoid terminating the job.
25-
continue-on-error: true
26-
2722
- name: Build dea-conflux image
2823
run: |
2924
docker compose build

dea_conflux/__main__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import geopandas as gpd
2020
from datacube.ui import click as ui
2121
from rasterio.errors import RasterioIOError
22-
2322
import dea_conflux.__version__
2423
import dea_conflux.db
2524
import dea_conflux.drill
@@ -70,7 +69,7 @@ def id_field_values_is_unique(shapefile_path: str, id_field) -> bool:
7069
has_s3 = "s3" in gpd.io.file._VALID_URLS
7170
gpd.io.file._VALID_URLS.discard("s3")
7271
logger.info(f"Attempting to read {shapefile_path} to check id field.")
73-
gdf = gpd.read_file(shapefile_path, driver="ESRI Shapefile")
72+
gdf = gpd.read_file(shapefile_path)
7473
if has_s3:
7574
gpd.io.file._VALID_URLS.add("s3")
7675
return len(set(gdf[id_field])) == len(gdf)
@@ -176,7 +175,7 @@ def load_and_reproject_shapefile(
176175
has_s3 = "s3" in gpd.io.file._VALID_URLS
177176
gpd.io.file._VALID_URLS.discard("s3")
178177
logger.info(f"Attempting to read {shapefile} to load polgyons.")
179-
shapefile = gpd.read_file(shapefile, driver="ESRI Shapefile")
178+
shapefile = gpd.read_file(shapefile)
180179
if has_s3:
181180
gpd.io.file._VALID_URLS.add("s3")
182181

@@ -332,7 +331,6 @@ def run_one(
332331
Run dea-conflux on one scene.
333332
"""
334333
logging_setup(verbose)
335-
336334
# Read the plugin as a Python module.
337335
plugin = run_plugin(plugin)
338336
logger.info(f"Using plugin {plugin.__file__}")
@@ -703,7 +701,7 @@ def nrt_run_from_queue(
703701

704702
logger.info(f"Processing {id_} ({i + 1}/{len(ids)})")
705703
logger.info(f"Processing {id_} ({i + 1}/{len(ids)})")
706-
704+
707705
# if id_ is uuid
708706
if len(id_) != 36:
709707
import json
@@ -1384,7 +1382,7 @@ def db_to_csv(
13841382
has_s3 = "s3" in gpd.io.file._VALID_URLS
13851383
gpd.io.file._VALID_URLS.discard("s3")
13861384
logger.info(f"Attempting to read {shapefile} to load polgyons.")
1387-
shapefile = gpd.read_file(shapefile, driver="ESRI Shapefile")
1385+
shapefile = gpd.read_file(shapefile)
13881386
if has_s3:
13891387
gpd.io.file._VALID_URLS.add("s3")
13901388

dea_conflux/drill.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,15 @@ def filter_dataset(dss, shapefile, worker_num=1):
389389
-------
390390
filtered_datasets: [str]
391391
"""
392-
with multiprocessing.Pool(processes=worker_num) as pool:
393-
filtered_datasets = list(
394-
tqdm.tqdm(pool.imap(partial(polygon_in_dataset, shapefile=shapefile), dss))
395-
)
392+
if __name__ == "__main__":
393+
with multiprocessing.Pool(processes=worker_num) as pool:
394+
filtered_datasets = list(
395+
tqdm.tqdm(
396+
pool.imap(partial(polygon_in_dataset, shapefile=shapefile), dss)
397+
)
398+
)
396399

397-
return [e for e in filtered_datasets if e]
400+
return [e for e in filtered_datasets if e]
398401

399402

400403
def polygon_in_dataset(ds, shapefile):

dea_conflux/stack.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ def remove_timeseries_with_duplicated(df: pd.DataFrame) -> pd.DataFrame:
199199
df = df.drop_duplicates("DAY", keep="first")
200200

201201
if "date" in df.columns and len(df) > 1:
202-
df['TIMEDIFF'] = pd.to_datetime(df['date'].shift(-1)) - pd.to_datetime(df['date'])
203-
df = df[~(df['TIMEDIFF'] < timedelta(seconds=60))]
202+
df["TIMEDIFF"] = pd.to_datetime(df["date"].shift(-1)) - pd.to_datetime(
203+
df["date"]
204+
)
205+
df = df[~(df["TIMEDIFF"] < timedelta(seconds=60))]
204206
df = df.drop(columns=["TIMEDIFF"])
205207

206208
# Remember to remove the temp column day in result_df
@@ -290,7 +292,6 @@ def save_df_as_csv(single_polygon_df, feature_id, outpath, remove_duplicated_dat
290292
single_polygon_df.drop(
291293
["overall_veg_num", "veg_areas", "index"], axis=1, inplace=True
292294
)
293-
294295
if not outpath.startswith("s3://"):
295296
os.makedirs(Path(filename).parent, exist_ok=True)
296297
with fsspec.open(filename, "w") as f:
@@ -315,9 +316,9 @@ def stack_wit_tooling_to_single_file(
315316
316317
verbose : bool
317318
"""
319+
318320
polygon_df_list = []
319321
logger.info("Reading...")
320-
321322
# Note: the stack_wit_tooling_to_single_file() input files are CSV file, which generate by save_df_as_csv()
322323
# then we assume they already had the norm_pv, norm_npv, norm_bs there.
323324
with tqdm(total=len(paths)) as bar:
@@ -391,7 +392,8 @@ def stack_wit_tooling(
391392
"""
392393
wit_df_list = []
393394
logger.info("Reading...")
394-
395+
# Note: the stack_wit_tooling_to_single_file() input files are CSV file, which generate by save_df_as_csv()
396+
# then we assume they already had the norm_pv, norm_npv, norm_bs there.
395397
with tqdm(total=len(paths)) as bar:
396398
with concurrent.futures.ThreadPoolExecutor(max_workers=32) as executor:
397399
wit_df_list = []
@@ -424,7 +426,6 @@ def stack_wit_tooling(
424426

425427
# delete the temp result to release RAM
426428
del wit_result
427-
428429
with tqdm(total=len(feature_ids)) as bar:
429430
with concurrent.futures.ThreadPoolExecutor(
430431
max_workers=multiprocessing.cpu_count()

examples/wit_ls9.conflux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def transform(inputs: xr.Dataset) -> xr.Dataset:
7373
# not apply poly_raster cause we will do it before summarise
7474

7575
open_water = wo_ds.water & (1 << 7) > 0
76-
76+
7777
# Thresholding
7878
# set wet pixels where not masked and above threshold of -350
7979
wet = tcw.where(mask) > -350

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"pyarrow",
2121
"fsspec",
2222
"s3fs",
23-
"moto[s3]",
23+
"moto[all]",
2424
"tqdm",
2525
"SQLAlchemy",
26-
# "python-geohash",
26+
"python-geohash",
2727
],
2828
entry_points={
2929
"console_scripts": ["dea-conflux=dea_conflux.__main__:main"],

tests/data/sum_pv_wet.conflux.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import xarray as xr
22

3-
product_name = 'sum_pv_wet'
4-
version = '0.0.1'
3+
product_name = "sum_pv_wet"
4+
version = "0.0.1"
55

66
input_products = {
7-
'ga_ls_wo_3': ['water'],
8-
'ga_ls_fc_3': ['PV'],
7+
"ga_ls_wo_3": ["water"],
8+
"ga_ls_fc_3": ["PV"],
99
}
1010

1111

1212
def transform(inputs: xr.Dataset) -> xr.Dataset:
13-
return xr.Dataset({
14-
'water': inputs.water == 128,
15-
'pv': inputs.PV > 0.5,
16-
})
13+
return xr.Dataset(
14+
{
15+
"water": inputs.water == 128,
16+
"pv": inputs.PV > 0.5,
17+
}
18+
)
1719

1820

1921
def summarise(inputs: xr.Dataset) -> xr.Dataset:

tests/data/sum_wet.conflux.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import xarray as xr
22

3-
product_name = 'sum_wet'
4-
version = '0.0.1'
3+
product_name = "sum_wet"
4+
version = "0.0.1"
55
resolution = (-30, 30)
6-
output_crs = 'EPSG:3577'
6+
output_crs = "EPSG:3577"
77

88
input_products = {
9-
'ga_ls_wo_3': ['water'],
9+
"ga_ls_wo_3": ["water"],
1010
}
1111

1212

tests/data/sum_wet_c3.conflux.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import xarray as xr
22

3-
product_name = 'sum_wet_c3'
4-
version = '0.0.1'
3+
product_name = "sum_wet_c3"
4+
version = "0.0.1"
55
resolution = (-30, 30)
6-
output_crs = 'EPSG:3577'
7-
resampling = 'nearest'
6+
output_crs = "EPSG:3577"
7+
resampling = "nearest"
88

99
input_products = {
10-
'ga_ls_wo_3': ['water'],
10+
"ga_ls_wo_3": ["water"],
1111
}
1212

1313

tests/data/sum_wet_missing_transform.conflux.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import xarray as xr
22

3-
product_name = 'sum_wet'
4-
version = '0.0.1'
3+
product_name = "sum_wet"
4+
version = "0.0.1"
55

66
input_products = {
7-
'ga_ls_wo_3': ['water'],
7+
"ga_ls_wo_3": ["water"],
88
}
99

1010

0 commit comments

Comments
 (0)