Skip to content

Commit

Permalink
Small changes to make it easy to add a single-point latitude axis to …
Browse files Browse the repository at this point in the history
…domain, and use this to implement seasonal insolation in a single-column model. Version number incremented to 0.2.10
  • Loading branch information
brian-rose committed Apr 22, 2015
1 parent 752f0f5 commit 2874c8a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion climlab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.2.9'
__version__ = '0.2.10'

# This list defines all the modules that will be loaded if a user invokes
# from climLab import *
Expand Down
5 changes: 3 additions & 2 deletions climlab/domain/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ def __init__(self, axis_type='abstract', num_points=10, points=None, bounds=None
# if points and/or bounds are supplied, make sure they are increasing
if points is not None:
try:
points = np.sort(np.array(points, dtype=float))
# using np.atleast_1d() ensures that we can use a single point
points = np.sort(np.atleast_1d(np.array(points, dtype=float)))
except:
raise ValueError('points must be array_like.')
if bounds is not None:
try:
bounds = np.sort(np.array(bounds, dtype=float))
bounds = np.sort(np.atleast_1d(np.array(bounds, dtype=float)))
except:
raise ValueError('bounds must be array_like.')

Expand Down
26 changes: 13 additions & 13 deletions climlab/process/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def __str__(self):
for varname in self.state.keys():
str1 += ' {0}: {1} \n'.format(varname, self.domains[varname].shape)
str1 += 'The subprocess tree: \n'
str1 += walk.process_tree(self)
str1 += walk.process_tree(self)
return str1

def __init__(self, state=None, domains=None, subprocess=None,
lat=None, lev=None, num_lat=None, num_levels=None,
diagnostics=None, **kwargs):
Expand All @@ -85,15 +85,15 @@ def __init__(self, state=None, domains=None, subprocess=None,
def add_subprocesses(self, procdict):
'''Add a dictionary of subproceses to this process.
procdict is dictionary with process names as keys.
Can also pass a single process, which will be called \'default\'
'''
if isinstance(procdict, Process):
self.add_subprocess('default', procdict)
else:
for name, proc in procdict.iteritems():
self.add_subprocess(name, proc)

def add_subprocess(self, name, proc):
'''Add a single subprocess to this process.
name: name of the subprocess (str)
Expand All @@ -102,16 +102,16 @@ def add_subprocess(self, name, proc):
self.subprocess.update({name: proc})
self.has_process_type_list = False
else:
raise ValueError('subprocess must be Process object')
raise ValueError('subprocess must be Process object')

def remove_subprocess(self, name):
'''Remove a single subprocess from this process.
name: name of the subprocess (str)'''
self.subprocess.pop(name, None)
self.has_process_type_list = False

def set_state(self, name, value):
if isinstance(value, Field):
if isinstance(value, Field):
# populate domains dictionary with domains from state variables
self.domains.update({name: value.domain})
else:
Expand All @@ -128,7 +128,7 @@ def set_state(self, name, value):
# set the state dictionary
self.state[name] = value
setattr(self, name, value)

def _guess_state_domains(self):
for name, value in self.state.iteritems():
for domname, dom in self.domains.iteritems():
Expand All @@ -149,6 +149,7 @@ def lat(self):
return thislat
except:
raise ValueError('Can\'t resolve a lat axis.')

@property
def lat_bounds(self):
try:
Expand Down Expand Up @@ -226,14 +227,14 @@ def depth_bounds(self):
return thisdepth
except:
raise ValueError('Can\'t resolve a depth axis.')


def process_like(proc):
'''Return a new process identical to the given process.
The creation date is updated.'''
newproc = copy.deepcopy(proc)
newproc.creation_date = time.strftime("%a, %d %b %Y %H:%M:%S %z",
time.localtime())
time.localtime())
return newproc


Expand All @@ -253,4 +254,3 @@ def get_axes(process_or_domain):
return axes
else:
raise TypeError('dom must be a domain or dictionary of domains.')

2 changes: 1 addition & 1 deletion climlab/radiation/insolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ def _get_current_insolation(self):
# make sure that the diagnostic has the correct field dimensions.
dom = self.domains['default']
time_index = self.time['day_of_year_index'] # THIS ONLY WORKS IF self IS THE MASTER PROCESS
insolation = insolation_array[:, time_index]
insolation = insolation_array[..., time_index]
self.diagnostics['insolation'] = Field(insolation, domain=dom)

0 comments on commit 2874c8a

Please sign in to comment.