noaa-oar-arl / monetio

The Model and ObservatioN Evaluation Tool I/O package
https://monetio.readthedocs.io
MIT License
17 stars 30 forks source link

Fix RRFS-CMAQ reader memory issue #77

Closed zmoon closed 2 years ago

zmoon commented 2 years ago

Fixes #72 for https://github.com/NOAA-CSL/MELODIES-MONET/issues/94

zmoon commented 2 years ago

Got past that part, but new error:

``` **** Reading CMAQ model output... v7.0.c3 {'files': '/scratch2/NCEPDEV/naqfc/Jianping.Huang/MONET/regional/processed/v7.0.c3/data/v7.0.c3/*dynf*.nc', 'files_pm25': '/scratch2/NCEPDEV/naqfc/Jianping.Huang/MONET/regional/processed/v7.0.c3/data/v7.0.c3/*pm25tot*.nc', 'mod_type': 'rrfs', 'mod_kwargs': {'mech': 'cb6r3_ae6_aq', 'surf_only': True}, 'radius_of_influence': 19500, 'mapping': {'airnow': {'PM25_TOT': 'PM2.5', 'o3': 'OZONE'}}, 'projection': 'None', 'plot_kwargs': {'color': 'purple', 'marker': '^', 'linestyle': '-'}} /scratch2/NCEPDEV/naqfc/Jianping.Huang/MONET/regional/processed/v7.0.c3/data/v7.0.c3/*dynf*.nc **** Reading RRFS-CMAQ model output... Traceback (most recent call last): File "/scratch2/NCEPDEV/naqfc/Zachary.Moon/mm-issue-94/run_melodies_monet.py", line 23, in an.open_models() File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/driver.py", line 519, in open_models m.open_model_files() File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/driver.py", line 335, in open_model_files self.obj = mio.models._rrfs_cmaq_mm.open_mfdataset(self.files,**self.mod_kwargs) File "/home/Zachary.Moon/git/monetio/monetio/models/_rrfs_cmaq_mm.py", line 196, in open_mfdataset dset["alt_msl_m_full"] = _calc_hgt(dset) File "/home/Zachary.Moon/git/monetio/monetio/models/_rrfs_cmaq_mm.py", line 1067, in _calc_hgt z = dz.rolling(z=len(f.z), min_periods=1).sum() File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/rolling.py", line 155, in method return self._numpy_or_bottleneck_reduce( File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/rolling.py", line 589, in _numpy_or_bottleneck_reduce return self.reduce(array_agg_func, keep_attrs=keep_attrs, **kwargs) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/rolling.py", line 472, in reduce windows = self._construct( File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/rolling.py", line 389, in _construct window = obj.variable.rolling_window( File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/variable.py", line 2314, in rolling_window padded = var.pad(pads, mode="constant", constant_values=fill_value) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/xarray/core/variable.py", line 1416, in pad array = np.pad( # type: ignore[call-overload] File "<__array_function__ internals>", line 180, in pad File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/numpy/lib/arraypad.py", line 793, in pad padded, original_area_slice = _pad_simple(array, pad_width) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/numpy/lib/arraypad.py", line 114, in _pad_simple padded = np.empty(new_shape, dtype=array.dtype, order=order) numpy.core._exceptions._ArrayMemoryError: Unable to allocate 120. GiB for an array with shape (168, 127, 974, 1547) and data type float32 ```
zmoon commented 2 years ago

Now we make it to the plotting but the df seems to be empty

``` Traceback (most recent call last): File "/scratch2/NCEPDEV/naqfc/Zachary.Moon/mm-issue-94/run_melodies_monet.py", line 27, in an.plotting() File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/driver.py", line 771, in plotting ax = splots.make_timeseries( File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/plots/surfplots.py", line 344, in make_timeseries ax = df[column].resample(avg_window).mean().plot(ax=ax, legend=True, **plot_dict) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_core.py", line 972, in __call__ return plot_backend.plot(data, kind=kind, **kwargs) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/__init__.py", line 71, in plot plot_obj.generate() File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/core.py", line 329, in generate self._make_plot() File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/core.py", line 1196, in _make_plot if self._is_ts_plot(): File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/core.py", line 1190, in _is_ts_plot return not self.x_compat and self.use_index and self._use_dynamic_x() File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/core.py", line 1193, in _use_dynamic_x return use_dynamic_x(self._get_ax(0), self.data) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/plotting/_matplotlib/timeseries.py", line 237, in use_dynamic_x return Period(x[0], freq).to_timestamp().tz_localize(x.tz) == x[0] File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 5039, in __getitem__ return getitem(key) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py", line 341, in __getitem__ "Union[DatetimeLikeArrayT, DTScalarOrNaT]", super().__getitem__(key) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/pandas/core/arrays/_mixins.py", line 272, in __getitem__ result = self._ndarray[key] IndexError: index 0 is out of bounds for axis 0 with size 0 ```
zmoon commented 2 years ago

Now the first two plots succeeded but new error

``` File "/scratch2/NCEPDEV/naqfc/Zachary.Moon/mm-issue-94/run_melodies_monet.py", line 27, in an.plotting() File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/driver.py", line 961, in plotting splots.make_spatial_bias( File "/home/Zachary.Moon/git/MELODIES-MONET/melodies_monet/plots/surfplots.py", line 334, in make_spatial_bias ax.axes.set_extent(map_kwargs['extent'],crs=ccrs.PlateCarree()) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 904, in set_extent projected = self.projection.project_geometry(domain_in_crs, crs) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/cartopy/crs.py", line 805, in project_geometry return getattr(self, method_name)(geometry, src_crs) File "/home/Zachary.Moon/mambaforge/envs/melodies-monet-dev/lib/python3.9/site-packages/cartopy/crs.py", line 811, in _project_line_string return cartopy.trace.project_linear(geometry, src_crs, self) File "lib/cartopy/trace.pyx", line 628, in cartopy.trace.project_linear File "lib/cartopy/trace.pyx", line 100, in cartopy.trace.geos_from_shapely TypeError: an integer is required ```

Possibly https://github.com/SciTools/cartopy/issues/2067 as my environment was created just a few hours ago

mgrover1 commented 2 years ago

Currently, the only solution is to pin the environment to use shapely version 1.8.2

zmoon commented 2 years ago

Ok. with the above adjustment to my conda env the job completed (thanks @mgrover1 ), max mem 124 GB, run time 16 min.

Was getting Warning: no valid obs found for CONUS messages (I think 12 cases), but the plots look fine.

zmoon commented 2 years ago

@rschwant do you want to take a quick look if you get a chance?

rschwant commented 2 years ago

@zmoon, thanks for fixing this. This looks like it will work well.

zmoon commented 2 years ago

Thanks @rschwant for your help