Skip to content

112 memory leak #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion globsim/interpolate/GenericInterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tomlkit
import warnings
import logging
import resource

from datetime import datetime, timedelta
from os import path, makedirs, listdir
Expand All @@ -13,6 +14,14 @@
from globsim.boundingbox import stations_bbox, netcdf_bbox, BoundingBox

logger = logging.getLogger('globsim.interpolate')
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('globsim_interpolate.log')
fh.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)

logger.addHandler(fh)
Comment on lines +17 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to put this here.

e.g. globsim interpolate -v or globsim interpolate -v 10 (for logging.DEBUG)

e.g. globsim interpolate -L log.txt


try:
import ESMF
Expand Down Expand Up @@ -124,6 +133,7 @@ def interp2D(self, ncfile_in: str, ncf_in, points, tmask_chunk: "np.ndarray",
variables=variables, date=date)
"""
logger.debug(f"Starting 2d interpolation for chunks {np.min(np.where(tmask_chunk == True))} to {np.max(np.where(tmask_chunk == True))} of {len(tmask_chunk)} ")
logger.debug(f"Current memory usage: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss} kB")

# is it a file with pressure levels?
pl = 'level' in ncf_in.dimensions.keys()
Expand Down Expand Up @@ -262,7 +272,8 @@ def regrid(sfield: "ESMF.Field", dfield: "ESMF.Field") -> "ESMF.Field":
logger.debug("Regridding complete")

sfield.destroy() # free memory

logger.debug(f"Memory usage after freeing memory: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
#fh.emit()
return dfield

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions globsim/interpolate/MERRAinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from datetime import datetime
from os import path, makedirs
import resource

from globsim.common_utils import str_encode, variables_skip
from globsim.interpolate.GenericInterpolate import GenericInterpolate
Expand Down Expand Up @@ -216,6 +217,12 @@ def MERRA2station(self, ncfile_in, ncfile_out, points,
ncf_in.close()
ncf_out.close()

try:
dfield.destroy()
logger.debug(f"Cleared dfield, memory usage: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
except:
print("Could not clear dfield in Merra2station function.")

def levels2elevation(self, ncfile_in, ncfile_out):
"""
Linear 1D interpolation of pressure level data available for individual
Expand Down