@@ -85,7 +85,31 @@ def find(pattern, path):
85
85
86
86
'''NetCDF operations'''
87
87
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
+ """
89
113
os .makedirs (path_to_create , exist_ok = True )
90
114
91
115
'''creating empty netcdf'''
@@ -166,7 +190,27 @@ def create_netcdf(indice_name: str, tile_name : str, start_year: int, path_to_cr
166
190
167
191
168
192
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
+ """
170
214
nc_path = output_path + nc_file_name
171
215
172
216
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
236
280
237
281
238
282
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
+
239
296
#TODO
240
297
# rajouter un '/' a la fin de src_path et de output_dir_path si le caractère n'est pas présent
241
298
@@ -296,6 +353,14 @@ def concat_nc(nc_paths: list, concat_file_name: str, path_to_create: str = 'down
296
353
297
354
'''Metadata operations'''
298
355
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
+ """
299
364
300
365
'''Formating template'''
301
366
df ['Data' ] = ''
@@ -349,6 +414,12 @@ def df_to_csv(df, tile: str):
349
414
350
415
351
416
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
+ """
352
423
try :
353
424
gc = gspread .service_account (filename = 'sodium-replica-389612-2dec563dbdbb.json' )
354
425
@@ -373,18 +444,36 @@ def gsheet_to_df(region):
373
444
374
445
'''Data operations'''
375
446
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
+ """
377
457
# Convert to Path object
378
458
dir = Path (dir )
379
459
380
460
print ('Creating ' + filename )
381
461
462
+ # TODO
463
+ # Do not create an empty zip while there is no data in the directory
382
464
with zipfile .ZipFile (filename , "w" , zipfile .ZIP_DEFLATED ) as zip_file :
383
465
for entry in dir .rglob (wd ):
384
466
zip_file .write (entry , entry .relative_to (dir ))
385
467
386
468
387
469
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
+ """
388
477
datatogeoflow_folder = '/home/g2oi/sen2val'
389
478
os .chdir (datatogeoflow_folder )
390
479
0 commit comments