Skip to content

Commit b8e9157

Browse files
author
csouton
committed
add fucntions documentation
1 parent 596bb2a commit b8e9157

File tree

1 file changed

+92
-3
lines changed

1 file changed

+92
-3
lines changed

main.py

+92-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,31 @@ def find(pattern, path):
8585

8686
'''NetCDF operations'''
8787
def create_netcdf(indice_name: str, tile_name : str, start_year: int, path_to_create: str, nc_file_name: str, y_size: int = 0, x_size: int = 0, times_size: int = 0, crs_code:str = '', wkt:str = ''):
88-
88+
"""Create an empty netCDF with given dimension lengths
89+
90+
Parameters
91+
----------
92+
indice_name : str
93+
Band name
94+
tile_name : str
95+
tile id
96+
start_year : int
97+
Year value that start the time serie
98+
path_to_create : str
99+
Path to the netCDF file
100+
nc_file_name : str
101+
Name of the netCDF file with extension
102+
y_size : int, optional
103+
y dimension length
104+
x_size : int, optional
105+
x dimension length
106+
times_size : int, optional
107+
time dimension length
108+
crs_code : str, optional
109+
Code of the coordonates representation system. Found in the JPEG2000 header
110+
wkt : str, optional
111+
Spatial representation metadata. Found in the JPEG2000 header
112+
"""
89113
os.makedirs(path_to_create, exist_ok=True)
90114

91115
'''creating empty netcdf'''
@@ -166,7 +190,27 @@ def create_netcdf(indice_name: str, tile_name : str, start_year: int, path_to_cr
166190

167191

168192
def concat_jpeg_to_netcdf(indice_name: str, tile_name: str, time_index: int, path_jp2: str, output_path: str, nc_file_name:str, ds_nc, time_size: int = 0, overwrite:bool = False):
169-
193+
"""Concat a JPEG2000 file into an existing netCDF or create a new one
194+
Parameters
195+
----------
196+
indice_name : str
197+
indice id
198+
tile_name : str
199+
tile id
200+
time_index : str
201+
index of the image from the netCDF time serie tab
202+
path_jp2 : str
203+
path of the JPEG2000 source file to add
204+
output_path : str
205+
name and path of the output netCDF file
206+
ds_nc :
207+
netCDF dataset to concat at if it already exists
208+
time_size : int, optional
209+
length of the time serie dimension
210+
overwrite : bool, optional
211+
Overwrite a time serie for the given date if it's correspond to an already existing time serie
212+
default = false, skipping time serie with the given date and only add data after
213+
"""
170214
nc_path = output_path + nc_file_name
171215

172216
img = rasterio.open(path_jp2, driver='JP2OpenJPEG')
@@ -236,6 +280,19 @@ def concat_jpeg_to_netcdf(indice_name: str, tile_name: str, time_index: int, pat
236280

237281

238282
def sen2chain_to_netcdf(src_path:str, indices: list, tiles: list, output_dir_path: str, ext: str = '.jp2'):
283+
"""Create Netcdf time serie file based on JPEG2000 data directory
284+
Parameters
285+
----------
286+
src_path : str
287+
Data directory path
288+
indices_tiles : dict
289+
{NDVI:[40KCB, 40KEC, ...], ...}
290+
output_dir_path : str
291+
Path to output nc file
292+
ext : str
293+
File extension filter string
294+
"""
295+
239296
#TODO
240297
# rajouter un '/' a la fin de src_path et de output_dir_path si le caractère n'est pas présent
241298

@@ -296,6 +353,14 @@ def concat_nc(nc_paths: list, concat_file_name: str, path_to_create: str = 'down
296353

297354
'''Metadata operations'''
298355
def df_to_csv(df, tile: str):
356+
"""Convert a dataframe based on Geoflow template to a csv by replacing tagged variables based on the given tile id
357+
Parameters
358+
----------
359+
df : DataFrame
360+
standard 15 columns Geolow DataFrame with 11 lignes (one by Indice)
361+
tile : str
362+
tile identifier
363+
"""
299364

300365
'''Formating template'''
301366
df['Data'] = ''
@@ -349,6 +414,12 @@ def df_to_csv(df, tile: str):
349414

350415

351416
def gsheet_to_df(region):
417+
"""Get gsheet Geoflow template and for given tiles, create completed csv
418+
Parameters
419+
----------
420+
region : list
421+
List of tile ids
422+
"""
352423
try:
353424
gc = gspread.service_account(filename='sodium-replica-389612-2dec563dbdbb.json')
354425

@@ -373,18 +444,36 @@ def gsheet_to_df(region):
373444

374445
'''Data operations'''
375446
def zip_dir(dir: Union[Path, str], filename: Union[Path, str], wd: str):
376-
"""Zip the provided directory without navigating to that directory using `pathlib` module"""
447+
"""Zip the provided time serie directory
448+
Parameters
449+
----------
450+
src_dir : str
451+
Data directory path
452+
filename : str
453+
Path and name of the zip destination file
454+
wd : str
455+
File filter string
456+
"""
377457
# Convert to Path object
378458
dir = Path(dir)
379459

380460
print('Creating '+filename)
381461

462+
# TODO
463+
# Do not create an empty zip while there is no data in the directory
382464
with zipfile.ZipFile(filename, "w", zipfile.ZIP_DEFLATED) as zip_file:
383465
for entry in dir.rglob(wd):
384466
zip_file.write(entry, entry.relative_to(dir))
385467

386468

387469
def zenodo_upload(metadata_path: str):
470+
"""Push entities from a Geoflow csv to a Zenodo deposit
471+
472+
Parameters
473+
----------
474+
matadata_path : str
475+
Path to csv metadata
476+
"""
388477
datatogeoflow_folder = '/home/g2oi/sen2val'
389478
os.chdir(datatogeoflow_folder)
390479

0 commit comments

Comments
 (0)