Skip to content

Commit

Permalink
Speed up process custom data (#1465)
Browse files Browse the repository at this point in the history
* Speed up process custom data

* Fix
  • Loading branch information
fmaussion committed Sep 7, 2022
1 parent 782ad04 commit e12a230
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions oggm/core/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def process_custom_climate_data(gdir, y0=None, y1=None,
fpath = cfg.PATHS['climate_file']
nc_ts = salem.GeoNetcdf(fpath)

# Avoid reading all data
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RuntimeWarning)
nc_ts.set_subset(((gdir.cenlon, gdir.cenlat),
(gdir.cenlon, gdir.cenlat)),
margin=2) # 2 is to be sure - also on small files

# set temporal subset for the ts data (hydro years)
sm = cfg.PARAMS['hydro_month_' + gdir.hemisphere]
em = sm - 1 if (sm > 1) else 12
Expand All @@ -107,8 +114,8 @@ def process_custom_climate_data(gdir, y0=None, y1=None,
'millimeter']

# geoloc
lon = nc_ts._nc.variables['lon'][:]
lat = nc_ts._nc.variables['lat'][:]
lon = nc_ts.get_vardata('lon')
lat = nc_ts.get_vardata('lat')

ilon = np.argmin(np.abs(lon - gdir.cenlon))
ilat = np.argmin(np.abs(lat - gdir.cenlat))
Expand Down

0 comments on commit e12a230

Please sign in to comment.