Newer
Older
Jeremy Auclair
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: UTF-8 -*-
# Python
"""
04-07-2023
@author: jeremy auclair
Calculate NDVI images with xarray
"""
import os # for path exploration
import csv # open csv files
from typing import List, Union # to declare variables
import xarray as xr # to manage dataset
import dask.array as da # dask xarray
from dask.distributed import Client, LocalCluster # to parallelise calculations
def calculate_ndvi(download_path: Union[List[str], str]) -> str:
# Start local cluster client
client = Client()
client
# If a file name is provided instead of a list of paths, load the csv file that contains the list of paths
if type(download_path) == str:
with open(download_path, 'r') as file:
download_path = []
csvreader = csv.reader(file, delimiter='\n')
for row in csvreader:
download_path.append(row[0])
products = xr.open_mfdataset(download_path, parallel = True) #, chunks = {'latitude': 100, 'longitude': 100})
ndvi_cube_path =''
return ndvi_cube_path