Skip to content

Commit

Permalink
Change structure
Browse files Browse the repository at this point in the history
Creates libIGCM and plotIGCM modules
  • Loading branch information
oliviermarti committed Jan 29, 2025
1 parent c516d62 commit 4b0a5c3
Show file tree
Hide file tree
Showing 18 changed files with 1,089 additions and 1,472 deletions.
285 changes: 114 additions & 171 deletions LMDZ_Gallery.ipynb

Large diffs are not rendered by default.

505 changes: 175 additions & 330 deletions ORCA_Gallery.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ephemerides.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import numpy as np
import xarray as xr
import cftime
from libIGCM_utils import Container
from libIGCM import Container

deg2rad = np.deg2rad (1.0)
rad2deg = np.rad2deg (1.0)
Expand Down
63 changes: 0 additions & 63 deletions interp1d.py

This file was deleted.

25 changes: 25 additions & 0 deletions libIGCM/Machines/spip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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' )
34 changes: 34 additions & 0 deletions libIGCM/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
'''
libIGCM
author: olivier.marti@lsce.ipsl.fr
This library if a layer under some usefull
environment variables and commands.
All those definitions depend on host particularities.
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.
'''

from libIGCM.utils import Container

from libIGCM import utils
from libIGCM.utils import set_options, get_options, reset_options, push_stack, pop_stack, return_stack
from libIGCM import date
from libIGCM import sys
from libIGCM import post

82 changes: 1 addition & 81 deletions libIGCM_date.py → libIGCM/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import time, copy
import numpy as np
import cftime
from libIGCM_utils import Container
from libIGCM.utils import Container, OPTIONS, set_options, get_options, reset_options, push_stack, pop_stack

# Characteristics of the gregorian calender
mth_length = np.array ( [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] )
Expand All @@ -67,86 +67,6 @@
# function IGCM_date_DaysInNextPeriod
# function IGCM_date_DaysInPreviousPeriod

# libIGCM_date internal options
DEFAULT_OPTIONS = Container (Debug = False,
Trace = False,
Timing = None,
t0 = None,
Depth = None,
Stack = None,
DefaultCalendar = 'Gregorian')
OPTIONS = copy.deepcopy (DEFAULT_OPTIONS)

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 reset_options():
return set_options (DEFAULT_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
#

## ==========================================================================

def GetMonthsLengths (year, Calendar=None) :
Expand Down
Loading

0 comments on commit 4b0a5c3

Please sign in to comment.