Skip to content

Commit

Permalink
Merge pull request #178 from stoiver/master
Browse files Browse the repository at this point in the history
bug when using log and ipython
  • Loading branch information
stoiver committed Feb 12, 2019
2 parents 00976ec + de4d9df commit 2a5de47
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 123 deletions.
116 changes: 50 additions & 66 deletions anuga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
Also, it isolates the user from "under-the-hood" refactorings.
"""

#-----------------------------------------------------
# -----------------------------------------------------
# Make selected classes available directly
#-----------------------------------------------------
# -----------------------------------------------------


__version__ = '2.0.2'
Expand Down Expand Up @@ -50,22 +50,22 @@
your python interpreter from there."""
raise ImportError(msg)

#---------------------------------
# ---------------------------------
# NetCDF changes stdout to terminal\
# Causes trouble when using jupyter
#---------------------------------
# ---------------------------------
import sys
_stdout = sys.stdout

#---------------------------------
# ---------------------------------
# Setup the nose tester from numpy
#---------------------------------
# ---------------------------------
from numpy.testing import Tester
test = Tester().test

#--------------------------------
# --------------------------------
# Important basic classes
#--------------------------------
# --------------------------------
from anuga.shallow_water.shallow_water_domain import Domain
from anuga.abstract_2d_finite_volumes.quantity import Quantity
from anuga.abstract_2d_finite_volumes.region import Region
Expand All @@ -77,9 +77,10 @@

from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
#------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# Miscellaneous
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
from anuga.abstract_2d_finite_volumes.util import file_function, \
sww2timeseries, sww2csv_gauges, \
csv2timeseries_graphs
Expand Down Expand Up @@ -121,9 +122,9 @@

from anuga.utilities.parse_time import parse_time

#----------------------------
# ----------------------------
# Parallel api
#----------------------------
# ----------------------------
## from anuga_parallel.parallel_api import distribute
## from anuga_parallel.parallel_api import myid, numprocs, get_processor_name
## from anuga_parallel.parallel_api import send, receive
Expand All @@ -143,16 +144,14 @@
from anuga.parallel.parallel_api import sequential_distribute_dump
from anuga.parallel.parallel_api import sequential_distribute_load


#-----------------------------
# -----------------------------
# Checkpointing
#-----------------------------
# -----------------------------
from anuga.shallow_water.checkpoint import load_checkpoint_file


#-----------------------------
# -----------------------------
# SwW Standard Boundaries
#-----------------------------
# -----------------------------
from anuga.shallow_water.boundaries import File_boundary
from anuga.shallow_water.boundaries import Reflective_boundary
from anuga.shallow_water.boundaries import Field_boundary
Expand All @@ -169,10 +168,9 @@
from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
Compute_fluxes_boundary


#-----------------------------
# -----------------------------
# General Boundaries
#-----------------------------
# -----------------------------
from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
import Dirichlet_boundary
from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
Expand All @@ -182,25 +180,20 @@
from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
import Transmissive_boundary



#-----------------------------
# -----------------------------
# Shallow Water Tsunamis
#-----------------------------
# -----------------------------
from anuga.tsunami_source.smf import slide_tsunami, slump_tsunami



#-----------------------------
# -----------------------------
# Forcing
# These are old, should use operators
#-----------------------------
# -----------------------------
from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress


#-----------------------------
# -----------------------------
# File conversion utilities
#-----------------------------
# -----------------------------
from anuga.file_conversion.file_conversion import sww2obj
from anuga.file_conversion.file_conversion import timefile2netcdf
from anuga.file_conversion.file_conversion import tsh2sww
Expand All @@ -216,9 +209,9 @@
from anuga.file_conversion.dem2dem import dem2dem
from anuga.file_conversion.sww2array import sww2array

#-----------------------------
# -----------------------------
# Parsing arguments
#-----------------------------
# -----------------------------
from anuga.utilities.argparsing import create_standard_parser
from anuga.utilities.argparsing import parse_standard_args

Expand All @@ -231,30 +224,29 @@ def get_args():
parser = create_standard_parser()
return parser.parse_args()


#-----------------------------
# -----------------------------
# Running Script
#-----------------------------
# -----------------------------
from anuga.utilities.run_anuga_script import run_script as run_anuga_script

#---------------------------
# ---------------------------
# Simulation and Excel mesh_interface
#---------------------------
# ---------------------------
from anuga.simulation.simulation import Simulation

#-----------------------------
# -----------------------------
# Mesh API
#-----------------------------
# -----------------------------
from anuga.pmesh.mesh_interface import create_mesh_from_regions

#-----------------------------
# -----------------------------
# SWW file access
#-----------------------------
# -----------------------------
from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section

#---------------------------
# ---------------------------
# Operators
#---------------------------
# ---------------------------
from anuga.operators.kinematic_viscosity_operator import Kinematic_viscosity_operator

from anuga.operators.rate_operators import Rate_operator
Expand All @@ -274,13 +266,9 @@ def get_args():
from anuga.operators.erosion_operators import Flat_slice_erosion_operator
from anuga.operators.erosion_operators import Flat_fill_slice_erosion_operator




#---------------------------
# ---------------------------
# Structure Operators
#---------------------------

# ---------------------------

if pypar_available:
from anuga.parallel.parallel_operator_factory import Inlet_operator
Expand All @@ -297,15 +285,13 @@ def get_args():

from anuga.structures.internal_boundary_functions import pumping_station_function

#----------------------------
# ----------------------------
# Parallel distribute
#----------------------------

# ----------------------------

#----------------------------
# ----------------------------
#
#Added by Petar Milevski 10/09/2013
#import time, os
# Added by Petar Milevski 10/09/2013

from anuga.utilities.model_tools import get_polygon_from_single_file
from anuga.utilities.model_tools import get_polygons_from_Mid_Mif
Expand All @@ -321,10 +307,9 @@ def get_args():
from anuga.utilities.model_tools import get_WCC_2002_Blockage_factor
from anuga.utilities.model_tools import get_WCC_2016_Blockage_factor


#---------------------------
# ---------------------------
# User Access Functions
#---------------------------
# ---------------------------

from anuga.utilities.system_tools import get_user_name
from anuga.utilities.system_tools import get_host_name
Expand All @@ -333,24 +318,23 @@ def get_args():
from anuga.utilities.system_tools import get_revision_date
from anuga.utilities.mem_time_equation import estimate_time_mem


#-------------------------
# -------------------------
# create domain functions
#-------------------------
# -------------------------
from anuga.extras import create_domain_from_regions
from anuga.extras import create_domain_from_file
from anuga.extras import rectangular_cross_domain


#import logging as log
from anuga.utilities import log
from anuga.utilities import log as log

from anuga.config import g
from anuga.config import velocity_protection

#--------------------------------------
# --------------------------------------
# NetCDF changes stdout to the terminal
# This resets it
#--------------------------------------
# --------------------------------------
reload(sys)
sys.stdout = _stdout
19 changes: 12 additions & 7 deletions anuga/utilities/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def log(msg, level=None):
'''

global _setup, log_logging_level
fname = '' # default to no frame name if it cannot be found
fname = '' # default to no frame name if it cannot be found
lnum = 0

# have we been setup?
Expand Down Expand Up @@ -143,12 +143,17 @@ def log(msg, level=None):
# get caller information - look back for first module != <this module name>
frames = traceback.extract_stack()
frames.reverse()

try:
(_, mod_name) = __name__.rsplit('.', 1)
except ValueError:
mod_name = __name__

for (fpath, lnum, mname, _) in frames:
(fname, _) = os.path.basename(fpath).rsplit('.', 1)
try:
(fname, _) = os.path.basename(fpath).rsplit('.', 1)
except ValueError:
fname = __name__
if fname != mod_name:
break

Expand All @@ -172,7 +177,7 @@ def log_exception_hook(type, value, tb):
msg = '\n' + ''.join(traceback.format_exception(type, value, tb))
critical(msg)


################################################################################
# Shortcut routines to make for simpler user code.
################################################################################
Expand Down Expand Up @@ -220,7 +225,7 @@ def resource_usage(level=logging.INFO):

if sys.platform != 'win32':
_proc_status = '/proc/%d/status' % os.getpid()

def _VmB(VmKey):
'''Get number of virtual bytes used.'''

Expand Down Expand Up @@ -308,7 +313,7 @@ def resource_usage_timing(level=logging.INFO, prefix =""):

if sys.platform != 'win32':
_proc_status = '/proc/%d/status' % os.getpid()

def _VmB(VmKey):
'''Get number of virtual bytes used.'''

Expand Down Expand Up @@ -388,7 +393,7 @@ class MEMORYSTATUSEX(ctypes.Structure):
timingInfo(prefix + 'total_memory, ' + str(memoryStatusEx.ullTotalPhys/_scale['MB']))
timingInfo(prefix + 'free_memory, ' + str(memoryStatusEx.ullAvailPhys/_scale['MB']))


################################################################################
if __name__ == '__main__':
critical('#' * 80)
Expand All @@ -406,7 +411,7 @@ def test_it(num=100):
resource_usage()

import numpy as num

a = num.zeros((1000,1000), num.float)

info('sys.version_info=%s, _new_python=%s'
Expand Down

0 comments on commit 2a5de47

Please sign in to comment.