-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibIGCM_sys.py
632 lines (534 loc) · 30.3 KB
/
libIGCM_sys.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# -*- coding: utf-8 -*-
'''
! @brief Defines libIGCM directories, depending of the computer
@file libIGCM_sys.py
@mainpage libIGCM_sys
@section description_main Description
This library if a layer under some usefull
environment variables and commands.
All those definitions depend on host particularities.
@section author_doxygen_example Author(s)
- Created Olivier Marti on 05/27/2020.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
Warning, to install, configure, run, use any of Olivier Marti's
software or to read the associated documentation you'll need at least
one (1) brain in a reasonably working order. Lack of this implement
will void any warranties (either express or implied).
O. Marti assumes no responsability for errors, omissions,
data loss, or any other consequences caused directly or indirectly by
the usage of his software by incorrectly or partially configured
personal.
'''
import os, subprocess, configparser, types, sys, time
import numpy as np
from Utils import Container
import libIGCM_date
# Where do we run ?
SysName, NodeName, Release, Version, Machine = os.uname ()
## ============================================================================
def Mach (long:bool=False) -> str :
'''
Find the computer we are on
On Irene, Mach returns Irene, Irene-Next, Rome or Rome-Prev if long==True
:returns: A standardized name of the computer we run on,
'''
zmach = None
if SysName == 'Darwin' and ( 'lsce5138' in NodeName or 'sargas028' in NodeName ) : zmach = 'Spip'
if 'obelix' in NodeName : zmach = 'Obelix'
if 'jupyter' in NodeName and "/home/users/" in os.path.abspath ("") : zmach = 'Obelix'
if 'forge' in NodeName : zmach = 'Forge'
if 'ciclad' in NodeName : zmach = 'Ciclad'
if 'climserv' in NodeName : zmach = 'SpiritX'
if 'spirit' in NodeName : zmach = 'SpiritJ'
if 'spiritj' in NodeName : zmach = 'SpiritJ'
if 'spiritx' in NodeName : zmach = 'SpiritX'
if 'irene' in NodeName : zmach = 'Irene'
if 'jean-zay' in NodeName : zmach = 'Jean-Zay'
if long :
zmachfull = zmach
if zmach == 'Irene' :
CPU = subprocess.getoutput ('lscpu')
ccc_os = subprocess.getoutput ('ccc_os')
if "Intel(R) Xeon(R) Platinum" in CPU :
zmachfull = 'Irene'
if "AMD" in CPU : zmachfull = 'Rome'
zmach = zmachfull
return zmach
MASTER = Mach (long=False)
LocalUser = os.environ ['USER']
IGCM_Catalog = None
IGCM_Catalog_list = ['IGCM_Catalog.json',]
if LocalUser in ['marti', 'omamce', 'p25mart', 'p86mart', 'rces009' ] :
IGCM_Catalog_list.append (os.path.join(os.environ['HOME'], 'Python', 'Library', 'IGCM_Catalog.json'))
# =======================================================================
if 'IGCM_Catalog' in os.environ :
IGCM_Catalog_list = os.environ['IGCM_Catalog']
if isinstance (IGCM_Catalog_list, str) :
print ( ' string {IGCM_Catalog_list=}' )
if os.path.isfile (IGCM_Catalog_list) :
IGCM_Catalog = IGCM_Catalog_list
if os.path.isdir (IGCM_Catalog_list) :
IGCM_Catalog = os.path.join (IGCM_Catalog_list, 'IGCM_Catalog.json')
if isinstance (IGCM_Catalog_list, list) :
for file in IGCM_Catalog_list :
if os.path.isfile (file) :
IGCM_Catalog = file
break
if os.path.isdir (file) :
IGCM_Catalog = os.path.join (file, 'IGCM_Catalog.json')
break
OPTIONS = Container (
Debug=False, Trace=False, Timing=None, t0=None, Depth=None, Stack=None,
TGCC_User = 'p86mart',
TGCC_Group = 'gen12006',
IDRIS_User = 'rces009',
IDRIS_Group = 'ces',
TGCC_DapPrefix = 'https://thredds-su.ipsl.fr/thredds/dodsC/tgcc_thredds',
TGCC_ThreddsPrefix = 'https://thredds-su.ipsl.fr/thredds/fileServer/tgcc_thredds',
IDRIS_DapPrefix = 'https://thredds-su.ipsl.fr/thredds/dodsC/idris_thredds',
IDRIS_ThreddsPrefix = 'https://thredds-su.ipsl.fr/thredds/fileServer/idris_thredds',
DapPrefix = None,
ThreddsPrefix = None,
IGCM_Catalog = IGCM_Catalog,
)
class set_options :
'''
! Set options for libIGCM_sys
'''
def __init__ (self, **kwargs) :
self.old = Container ()
for k, v in kwargs.items () :
if k not in OPTIONS:
raise ValueError ( f"argument name {k!r} is not in the set of valid options {set(OPTIONS)!r}" )
self.old[k] = OPTIONS[k]
self._apply_update (kwargs)
def _apply_update (self, options_dict) : OPTIONS.update (options_dict)
def __enter__ (self) : return
def __exit__ (self, type, value, traceback) : self._apply_update (self.old)
def get_options () :
'''
! Get options for libIGCM_sys
See Also
----------
set_options
'''
return OPTIONS
def return_stack () :
return OPTIONS['Stack']
def push_stack (string:str) :
if OPTIONS['Depth'] : OPTIONS['Depth'] += 1
else : OPTIONS['Depth'] = 1
if OPTIONS['Trace'] : print ( ' '*(OPTIONS['Depth']-1), f'-->{__name__}.{string}' )
#
if OPTIONS['Stack'] : OPTIONS['Stack'].append (string)
else : OPTIONS['Stack'] = [string,]
#
if OPTIONS['Timing'] :
if OPTIONS['t0'] :
OPTIONS['t0'].append ( time.time() )
else :
OPTIONS['t0'] = [ time.time(), ]
def pop_stack (string:str) :
if OPTIONS['Timing'] :
dt = time.time() - OPTIONS['t0'][-1]
OPTIONS['t0'].pop()
else :
dt = None
if OPTIONS['Trace'] or dt :
if dt :
if dt < 1e-3 :
print ( ' '*(OPTIONS['Depth']-1), f'<--{__name__}.{string} : time: {dt*1e6:5.1f} micro s')
if dt >= 1e-3 and dt < 1 :
print ( ' '*(OPTIONS['Depth']-1), f'<--{__name__}.{string} : time: {dt*1e3:5.1f} milli s')
if dt >= 1 :
print ( ' '*(OPTIONS['Depth']-1), f'<--{__name__}.{string} : time: {dt*1:5.1f} second')
else :
print ( ' '*(OPTIONS['Depth']-1), f'<--{__name__}.{string}')
#
OPTIONS['Depth'] -= 1
if OPTIONS['Depth'] == 0 : OPTIONS['Depth'] = None
OPTIONS['Stack'].pop ()
if OPTIONS['Stack'] == list () : OPTIONS['Stack'] = None
#
# Where do we run ?
SysName, NodeName, Release, Version, Machine = os.uname ()
class Config :
'''
! Defines the libIGCM directories
Source : for Spip
Possibilities :
Local : local (~/Data/IGCMG/...)
TGCC_sshfs : TGCC disks mounted via sshfs
TGCC_thredds : thredds TGCC via IPSL
IDRIS_thredds : thredds IDRIS via IPSL
'''
## Public functions
def update (self, dico=None, **kwargs):
'''Use a dictionnary to update values'''
if dico :
for attr in dico.keys () : super().__setattr__(attr, dico[attr])
self.__dict__.update (kwargs)
for attr in dico.keys () : super().__setattr__(attr, dico[attr])
def keys (self) : return self.__dict__.keys()
def values (self) : return self.__dict__.values()
def items (self) : return self.__dict__.items()
def dict (self) : return self.__dict__()
## Hidden functions
def __str__ (self) : return str (self.__dict__)
def __repr__ (self) : return repr (self.__dict__)
def __name__ (self) : return self.__class__.__name__
def __getitem__ (self, attr) : return getattr (self, attr)
def __setitem__ (self, attr, value) : setattr (self, attr, value)
def __iter__ (self) : return self.__dict__.__iter__()
def __next__ (self) : return self.__dict__.__next__()
def __len__ (self) : return len(self.__dict__)
def __init__ (self, JobName=None, TagName=None, SpaceName=None, ExperimentName=None,
LongName=None, ModelName=None, ShortName=None, Comment=None,
Source=None, MASTER=None, ConfigCard=None, RunCard=None, User=None, Group=None,
TGCC_User=None, TGCC_Group=None, IDRIS_User=None, IDRIS_Group=None,
ARCHIVE=None, SCRATCHDIR=None, STORAGE=None, R_IN=None, R_OUT=None,
R_FIG=None, L_EXP=None,
R_SAVE=None, R_FIGR=None, R_BUF=None, R_BUFR=None, R_BUF_KSH=None,
REBUILD_DIR=None, POST_DIR=None,
ThreddsPrefix=None, DapPrefix=None, R_GRAF=None, DB=None,
IGCM_OUT=None, IGCM_OUT_name=None, rebuild=None, TmpDir=None,
Debug=None, TGCC_ThreddsPrefix=None, TGCC_DapPrefix=None, IDRIS_ThreddsPrefix=None, IDRIS_DapPrefix=None,
DateBegin=None, DateEnd=None, YearBegin=None, YearEnd=None, PeriodLength=None,
SeasonalFrequency=None, CalendarType=None,
DateBeginGregorian=None, DateEndGregorian=None, FullPeriod=None, DatePattern=None,
ColorLine=None, ColorShading=None, Marker=None, Line=None,
OCE=None, ATM=None,
CMIP6_BUF=None, Custom=None ) :
if not Debug : Debug = OPTIONS.Debug
if not TGCC_User : TGCC_User = OPTIONS.TGCC_User
if not TGCC_Group : TGCC_Group = OPTIONS.TGCC_Group
if not IDRIS_User : IDRIS_User = OPTIONS.IDRIS_User
if not IDRIS_Group : IDRIS_Group = OPTIONS.IDRIS_Group
if not TGCC_ThreddsPrefix : TGCC_ThreddsPrefix = OPTIONS.TGCC_ThreddsPrefix
if not TGCC_DapPrefix : TGCC_DapPrefix = OPTIONS.TGCC_DapPrefix
if not IDRIS_ThreddsPrefix : IDRIS_ThreddsPrefix = OPTIONS.IDRIS_ThreddsPrefix
if not IDRIS_DapPrefix : IDRIS_DapPrefix = OPTIONS.IDRIS_DapPrefix
if not ThreddsPrefix : ThreddsPrefix = OPTIONS.ThreddsPrefix
if not DapPrefix : DapPrefix = OPTIONS.DapPrefix
if not MASTER : MASTER = Mach (long=False)
if not MASTER : MASTER = 'Unknown'
if Debug :
print ( f'libIGCM_sys : {MASTER=}' )
print ( f'libIGCM_sys : {LocalUser=}' )
# ===========================================================================================
# Reads config.card if available
if ConfigCard :
# Text existence of ConfigCard
if not os.path.exists (ConfigCard ) :
raise FileExistsError ( f"File not found : {ConfigCard = }" )
## Creates parser for reading .ini input file
MyReader = configparser.ConfigParser (interpolation=configparser.ExtendedInterpolation() )
MyReader.optionxform = str # To keep capitals
MyReader.read (ConfigCard)
if not JobName : JobName = MyReader['UserChoices']['JobName']
#----- Short Name of Experiment
if not ExperimentName : ExperimentName = MyReader['UserChoices']['ExperimentName']
#----- DEVT TEST PROD
if not SpaceName : SpaceName = MyReader['UserChoices']['SpaceName']
if not LongName : LongName = MyReader['UserChoices']['LongName']
if not ModelName : ModelName = MyReader['UserChoices']['ModelName']
if not TagName : TagName = MyReader['UserChoices']['TagName']
# Reads run.card if available
if RunCard :
# Text existence of RunCard
if not os.path.exists (RunCard ) :
raise FileExistsError ( f"File not found : {RunCard = }" )
## Creates parser for reading .ini input file
MyReader = configparser.ConfigParser (interpolation=configparser.ExtendedInterpolation() )
MyReader.optionxform = str # To keep capitals
MyReader.read (ConfigCard)
if not PeriodDateBegin : PeriodDateBegin = MyReader['Configuration']['PeriodDateBegin']
if not PeriodDateEnd : PeriodDateEnd = MyReader['Configuration']['PeriodDateEnd']
if not CumulPeriod : CumulPeriod = MyReader['Configuration']['CumulPeriod']
if not PeriodState : PeriodState = MyReader['Configuration']['PeriodState']
## ===========================================================================================
if YearBegin and not DateBegin : DateBegin = f'{YearBegin}-01-01'
if YearEnd and not DateEnd : DateEnd = f'{YearEnd}-12-31'
if DateBegin and not DateBeginGregorian : DateBeginGregorian = libIGCM_date.ConvertFormatToGregorian (DateBegin)
if DateEnd and not DateEndGregorian : DateEndGregorian = libIGCM_date.ConvertFormatToGregorian (DateEnd )
if not FullPeriod and DateBeginGregorian and DateEndGregorian : FullPeriod = f'{DateBeginGregorian}_{DateEndGregorian}'
### ===========================================================================================
## Part specific to access by OpenDAP/Thredds server
# ===========================================================================================
if Source == 'TGCC_thredds' :
if not User and TGCC_User : User = TGCC_User
if not Group and TGCC_Group : Group = TGCC_Group
if not ThreddsPrefix : ThreddsPrefix = OPTIONS.TGCC_ThreddsPrefix
if not DapPrefix : DapPrefix = OPTIONS.TGCC_DapPrefix
if not ARCHIVE : ARCHIVE = f'{DapPrefix}/store/{TGCC_User}'
if not R_FIG : R_FIG = f'{DapPrefix}/work/{TGCC_User}'
if not R_IN : R_IN = f'{DapPrefix}/work/igcmg/IGCM'
if not R_GRAF : R_GRAF = f'{DapPrefix}/work/p86mart/GRAF/DATA'
# ===========================================================================================
if Source == 'IDRIS_thredds' :
if not User and IDRIS_User : User = IDRIS_User
if not Group and IDRIS_Group : Group = IDRIS_Group
if not ThreddsPrefix : ThreddsPrefix = OPTIONS.IDRIS_ThreddsPrefix
if not DapPrefix : DapPrefix = OPTIONS.IDRIS_DapPrefix
if not ARCHIVE : ARCHIVE = f'{DapPrefix}/store/{IDRIS_User}'
if not R_FIG : R_FIG = f'{DapPrefix}/work/{IDRIS_User}'
if not R_IN : R_IN = f'{DapPrefix}/work/igcmg/IGCM'
if not R_GRAF : R_GRAF = 'https://thredds-su.ipsl.fr/thredds/dodsC/tgcc_thredds/work/p86mart/GRAF/DATA'
### ===========================================================================================
## Machine dependant part
# ===========================================================================================
if MASTER == 'Obelix' :
if not User : User = LocalUser
if Source : IGCM_OUT_name = ''
else : IGCM_OUT_name = 'IGCM_OUT'
if not ARCHIVE : ARCHIVE = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not SCRATCHDIR : SCRATCHDIR = os.path.join ( os.path.expanduser ('~'), 'Scratch' )
if not R_BUF : R_BUF = os.path.join ( os.path.expanduser ('~'), 'Scratch' )
if not R_FIG : R_FIG = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not STORAGE : STORAGE = ARCHIVE
if not R_IN : R_IN = os.path.join ( '/home', 'orchideeshare', 'igcmg', 'IGCM' )
if not R_GRAF or 'http' in R_GRAF : R_GRAF = os.path.join ( os.path.expanduser ('~marti'), 'GRAF', 'DATA' )
if not DB : DB = os.path.join ( '/home', 'biomac1', 'geocean', 'ocmip' )
if not TmpDir : TmpDir = os.path.join ( os.path.expanduser ('~'), 'Scratch' )
# ===========================================================================================
if MASTER == 'Spip' :
if not User : User = LocalUser
if Source : IGCM_OUT_name = ''
else : IGCM_OUT_name = 'IGCM_OUT'
if not ARCHIVE : ARCHIVE = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not SCRATCHDIR : SCRATCHDIR = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not R_BUF : R_BUF = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not R_FIG : R_FIG = os.path.join ( os.path.expanduser ('~'), 'Data' )
if not STORAGE : STORAGE = ARCHIVE
if not R_IN : R_IN = os.path.join ( os.path.expanduser ('~'), 'Data', 'IGCM' )
if not R_GRAF or 'http' in R_GRAF : R_GRAF = os.path.join ( os.path.expanduser ('~'), 'GRAF', 'DATA' )
if not DB : DB = os.path.join ( os.path.expanduser ('~'), 'marti', 'GRAF', 'DB' )
if not TmpDir : TmpDir = os.path.join ( os.path.expanduser ('~'), 'Scratch' )
# ===========================================================================================
if ( 'Irene' in MASTER ) or ( 'Rome' in MASTER ) :
ccc_home = os.path.isfile ( subprocess.getoutput ( 'which ccc_home'))
if not User or User == 'marti' :
if not TGCC_User : User = LocalUser
else : User = TGCC_User
if not Group :
if TGCC_Group : Group = TGCC_Group
else : Group = LocalGroup
LocalHome = subprocess.getoutput ( 'ccc_home --ccchome' )
LocalGroup = os.path.basename ( os.path.dirname (LocalHome))
if not Source : IGCM_OUT_name = 'IGCM_OUT'
if not R_IN :
if ccc_home : R_IN = os.path.join ( subprocess.getoutput ('ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM')
else : R_IN = '/ccc/work/cont003/igcmg/igcmg/IGCM'
if not ARCHIVE :
if ccc_home : ARCHIVE = subprocess.getoutput ( f'ccc_home --cccstore -u {User} -d {Group}')
else : ARCHIVE = f'/ccc/store/cont003/{TGCC_Group}/{TGCC_User}'
if not STORAGE :
if ccc_home : STORAGE = subprocess.getoutput ( f'ccc_home --cccwork -u {User} -d {Group}')
else : STORAGE = f'/ccc/store/cont003/{TGCC_Group}/{TGCC_User}'
if not SCRATCHDIR :
if ccc_home : SCRATCHDIR = subprocess.getoutput ( f'ccc_home --cccscratch -u {User} -d {Group}')
else : SCRATCHDIR = f'/ccc/scratch/cont003/{TGCC_Group}/{TGCC_User}'
if not R_BUF :
if ccc_home : R_BUF = subprocess.getoutput ( f'ccc_home --cccscratch -u {User} -d {Group}')
else : R_BUF = f'/ccc/scratch/cont003/{TGCC_Group}/{TGCC_User}'
if not R_FIG :
if ccc_home : R_FIG = subprocess.getoutput ( f'ccc_home --cccwork -u {User} -d {Group}')
else : R_FIG = f'/ccc/store/cont003/{TGCC_Group}/{TGCC_User}'
if not R_GRAF or 'http' in R_GRAF :
if ccc_home : R_GRAF = os.path.join ( subprocess.getoutput ('ccc_home --cccwork -d drf -u p86mart'), 'GRAF', 'DATA')
else : R_GRAF = f'/ccc/store/cont003/drf/p86mart'
if not DB :
if ccc_home : DB = os.path.join ( subprocess.getoutput ('ccc_home --cccwork -d igcmg -u igcmg'), 'database')
else : DB = f'/ccc/store/cont003/igcmg/igcmg/database'
if not rebuild :
rebuild = os.path.join ( subprocess.getoutput ('ccc_home --ccchome -d igcmg -u igcmg' ),
'Tools', 'irene', 'rebuild_nemo', 'bin', 'rebuild_nemo' )
if not TmpDir :
if ccc_home : TmpDir = subprocess.getoutput (f'ccc_home --cccscratch')
else : TmpDir = f'/ccc/scratch/cont003/{TGCC_Group}/{TGCC_User}'
# ===========================================================================================
if MASTER in ['SpiritJ', 'SpiritX', 'Spirit'] :
if not IGCM_OUT_name : IGCM_OUT_name = ''
if not User :
if TGCC_User : User = TGCC_User
else : User = LocalUser
if not ARCHIVE :
ARCHIVE = os.path.join ( '/', 'thredds', 'tgcc', 'store', User )
if not STORAGE :
STORAGE = os.path.join ( '/', 'thredds', 'tgcc', 'work' , User )
if not R_IN :
R_IN = os.path.join ( '/', 'projsu', 'igcmg', 'IGCM' )
#if not R_GRAF : R_GRAF = os.path.join ('/', 'data', 'omamce', 'GRAF', 'DATA' )
if not R_GRAF or 'http' in R_GRAF :
R_GRAF = os.path.join ( '/', 'thredds', 'tgcc', 'work', 'p86mart', 'GRAF', 'DATA' )
if not DB :
DB = os.path.join ( '/', 'data', 'igcmg', 'database' )
if not TmpDir :
if MASTER in ['SpiritJ',] : TmpDir = os.path.join ( '/', 'scratchu', LocalUser )
if MASTER in ['SpiritX',] : TmpDir = os.path.join ( '/', 'scratchx', LocalUser )
# ===========================================================================================
if MASTER == 'Jean-Zay' :
if not User : User = os.environ ['USER']
LocalGroup = os.path.basename ( os.path.dirname ( os.path.expanduser ('~') ))
if not Group : Group = LocalGroup
if not Source : IGCM_OUT_name = 'IGCM_OUT'
if not ARCHIVE :
ARCHIVE = os.path.join ( '/', 'gpfsstore' , 'rech', Group, User )
if not STORAGE :
STORAGE = os.path.join ( '/', 'gpfswork' , 'rech', Group, User )
if not SCRATCHDIR :
SCRATCHDIR = os.path.join ( '/', 'gpfsscratch', 'rech', Group, User )
if not R_FIG :
R_FIG = os.path.join ( '/', 'cccwork' , 'rech', Group, User )
if not R_BUF :
R_BUF = os.path.join ( '/', 'gpfsscratch', 'rech', Group, User )
if not R_IN :
R_IN = os.path.join ( '/', 'gpfswork' , 'rech', 'psl', 'commun', 'IGCM' )
if not R_GRAF :
R_GRAF = os.path.join ( '/', 'gpfswork' , 'rech', Group, User, 'GRAF', 'DATA' )
if not DB :
DB = os.path.join ( '/', 'gpfswork' , 'rech', 'psl', 'commun', 'database' )
if not rebuild :
rebuild = os.path.join ( '/', 'gpfswork', 'rech', 'psl', 'commun', 'Tools',
'rebuild', 'modipsl_IOIPSL_PLUS_v2_2_4', 'bin', 'rebuild' )
if not TmpDir : TmpDir = os.path.join ( '/', 'gpfsscratch', 'rech',
os.path.basename ( os.path.dirname ( os.path.expanduser ('~') )), LocalUser )
### ===========================================================================================
### The construction of the following variables is not machine dependant
### ===========================================================================================
if SpaceName == 'TEST' :
if SCRATCHDIR and not R_OUT : R_OUT = SCRATCHDIR
if SCRATCHDIR and not R_FIG : R_FIG = SCRATCHDIR
else :
if ARCHIVE and not R_OUT : R_OUT = ARCHIVE
if STORAGE and not R_FIG : R_FIG = STORAGE
if IGCM_OUT_name :
R_OUT = os.path.join ( R_OUT, IGCM_OUT_name )
R_FIG = os.path.join ( R_FIG, IGCM_OUT_name )
if SCRATCHDIR and not R_BUF : R_BUF = os.path.join ( SCRATCHDIR, IGCM_OUT_name )
if not IGCM_OUT : IGCM_OUT = R_OUT
if TagName and SpaceName and ExperimentName and JobName :
if not L_EXP : L_EXP = os.path.join ( TagName, SpaceName, ExperimentName, JobName )
if Debug :
print ( f'libIGCM_sys : {R_BUF=}' )
print ( f'libIGCM_sys : {IGCM_OUT_name=}' )
print ( f'libIGCM_sys : {L_EXP=}' )
if R_OUT and not R_SAVE : R_SAVE = os.path.join ( R_OUT , L_EXP )
if IGCM_OUT_name :
if STORAGE and not R_FIGR : R_FIGR = os.path.join ( STORAGE, IGCM_OUT_name, L_EXP )
else :
if STORAGE and not R_FIGR : R_FIGR = os.path.join ( STORAGE, L_EXP )
if R_BUF and not R_BUFR : R_BUFR = os.path.join ( R_BUF , IGCM_OUT_name, L_EXP )
if R_BUFR and not R_BUF_KSH : R_BUF_KSH = os.path.join ( R_BUFR , 'Out' )
if R_BUF and not REBUILD_DIR : REBUILD_DIR = os.path.join ( R_BUF , L_EXP, 'REBUILD' )
if R_BUF and not POST_DIR : POST_DIR = os.path.join ( R_BUF , L_EXP, 'Out' )
if STORAGE and not CMIP6_BUF : CMIP6_BUF = os.path.join ( STORAGE, IGCM_OUT_name )
### =========
if not ColorLine is None :
if OPTIONS.Debug : print ( f'{type(ColorLine) = } - {ColorLine =}' )
if isinstance (ColorLine, list) :
ColorLine = np.array (ColorLine)
if isinstance (ColorLine, np.ndarray) :
if np.max (ColorLine) > 1.0 : ColorLine = ColorLine / 255.
if not ColorShading is None :
if isinstance (ColorShading, list) :
ColorShading = np.array (ColorShading)
if isinstance (ColorShading, np.ndarray) :
if np.max (ColorShading) > 1.0 : ColorShading = ColorShading / 255.
### ===========================================================================================
## Builds the class attributes
self.TagName = TagName
self.SpaceName = SpaceName
self.ExperimentName = ExperimentName
self.JobName = JobName
self.LongName = LongName
self.ModelName = ModelName
self.ShortName = ShortName
self.Comment = Comment
self.ConfigCard = ConfigCard
self.DateBegin = DateBegin
self.DateEnd = DateEnd
self.YearBegin = YearBegin
self.YearEnd = YearEnd
self.PeriodLength = PeriodLength
self.SeasonalFrequency = SeasonalFrequency
self.CalendarType = CalendarType
self.DateBeginGregorian = DateBeginGregorian
self.DateEndGregorian = DateEndGregorian
self.FullPeriod = FullPeriod
self.RunCard = RunCard
self.ARCHIVE = ARCHIVE
self.STORAGE = STORAGE
self.SCRATCHDIR = SCRATCHDIR
self.R_OUT = R_OUT
self.R_BUF = R_BUFR
self.R_GRAF = R_GRAF
self.DB = DB
self.IGCM_OUT = IGCM_OUT
self.R_SAVE = R_SAVE
self.R_FIGR = R_FIGR
self.R_BUFR = R_BUFR
self.REBUILD_DIR = REBUILD_DIR
self.POST_DIR = POST_DIR
self.R_IN = R_IN
self.MASTER = MASTER
self.Source = Source
self.User = User
self.Group = Group
self.IGCM_OUT_name = IGCM_OUT_name
self.rebuild = rebuild
self.TmpDir = TmpDir
self.TGCC_User = TGCC_User
self.TGCC_Group = TGCC_Group
self.IDRIS_User = IDRIS_User
self.IDRIS_Group = IDRIS_Group
self.TGCC_DapPrefix = TGCC_DapPrefix
self.IDRIS_DapPrefix = IDRIS_DapPrefix
self.TGCC_ThreddsPrefix = TGCC_ThreddsPrefix
self.IDRIS_ThreddsPrefix = IDRIS_ThreddsPrefix
self.DapPrefix = DapPrefix
self.ThreddsPrefix = ThreddsPrefix
self.CMIP6_BUF = CMIP6_BUF
self.Debug = Debug
self.DatePattern = DatePattern
self.ColorLine = ColorLine
self.ColorShading = ColorShading
self.Line = Line
self.Marker = Marker
self.OCE = OCE
self.ATM = ATM
### ===========================================================================================
## Add user defined attributes
if Custom :
for attr, value in Custom.items() :
super().__setattr__(attr, value)
### ===========================================================================================
## Add custom attributes
return None
### ===========================================================================
def Dap2Thredds (file, mm=None) :
'''
! Convert a Dap URL to http URL
'''
push_stack ( f'Dap2Thredds ({file=}, {mm=})' )
replaced = False
zfile = file
if mm :
if not replaced and mm.DapPrefix and mm.ThreddsPrefix :
zfile = zfile.replace (mm.DapPrefix , mm.ThreddsPrefix )
replace = True
if not replaced and mm.TGCC_DapPrefix and mm.TGCC_ThreddsPrefix :
zfile = zfile.replace (mm.TGCC_DapPrefix , mm.TGCC_ThreddsPrefix )
replace = True
if not replaced and mm.IDRIS_DapPrefix and mm.IDRIS_ThreddsPrefix :
zfile = zfile.replace (mm.IDRIS_DapPrefix , mm.IDRIS_ThreddsPrefix)
replace = True
if not replaced :
zfile = zfile.replace ( 'dodsC', 'fileServer' )
pop_stack ( f'Dap2Thredds -> {zfile=}' )
return zfile