Skip to content
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

Update mov run #994

Merged
merged 18 commits into from
Nov 30, 2023
Merged

Update mov run #994

merged 18 commits into from
Nov 30, 2023

Conversation

lee1043
Copy link
Contributor

@lee1043 lee1043 commented Nov 2, 2023

No description provided.

@lee1043 lee1043 self-assigned this Nov 23, 2023
@lee1043 lee1043 marked this pull request as ready for review November 28, 2023 21:46
@lee1043 lee1043 added the minor label Nov 28, 2023
@lee1043 lee1043 added this to the v3.1.2 milestone Nov 28, 2023
@lee1043
Copy link
Contributor Author

lee1043 commented Nov 28, 2023

@acordonez would you be able to help verifying this PR won't break the MoV demo?

@acordonez
Copy link
Collaborator

@lee1043 I'm getting a segmentation fault when I run the first example. This looks like the issue I saw with my changes in the variability_across_timescales driver, where importing shapely after importing cdat libraries causes a segmentation fault. I can get the driver to run normally if I put an "import shapely" statement at the top of variability_modes_driver.py, but the pre-commit hooks don't like that. If you have a better fix I can also use that in variability_across_timescales.

Here's the full text:

Fatal Python error: Segmentation fault

Current thread 0x00007f66ad834740 (most recent call first):
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/predicates.py", line 69 in has_z
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/decorators.py", line 77 in wrapped
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/geometry/base.py", line 607 in has_z
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/geometry/base.py", line 206 in coords
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/geometry/linestring.py", line 119 in xy
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/patch.py", line 54 in geos_to_path
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 1542 in _boundary
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 583 in __clear
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 596 in clear
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 683 in __init__
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 416 in __init__
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/figure.py", line 768 in add_subplot
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/pyplot.py", line 1122 in axes
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/pcmdi_metrics/variability_mode/lib/plot_map.py", line 203 in plot_map_cartopy
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/pcmdi_metrics/variability_mode/lib/plot_map.py", line 104 in plot_map
  File "/home/ordonez4/miniconda3/envs/pmp_dev/bin/variability_modes_driver.py", line 446 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, cdtime._cdtime, lazy_object_proxy.cext, cdms2.Cdunif, regrid2._regrid, regrid2._scrip, cdms2._bindex, yaml._yaml, cytoolz.utils, cytoolz.itertoolz, cytoolz.functoolz, cytoolz.dicttoolz, cytoolz.recipes, psutil._psutil_linux, psutil._psutil_posix, markupsafe._speedups, tornado.speedups, msgpack._cmsgpack, lz4._version, lz4.block._block, genutil.array_indexing, genutil.udunits_wrap, _brotli, shapely.lib, shapely._geos, shapely._geometry_helpers, pyarrow.lib, pyarrow._hdfsio, pandas._libs.tslibs.np_datetime, pandas._libs.tslibs.dtypes, pandas._libs.tslibs.base, pandas._libs.tslibs.nattype, pandas._libs.tslibs.timezones, pandas._libs.tslibs.ccalendar, pandas._libs.tslibs.fields, pandas._libs.tslibs.timedeltas, pandas._libs.tslibs.tzconversion, pandas._libs.tslibs.timestamps, pandas._libs.properties, pandas._libs.tslibs.offsets, pandas._libs.tslibs.strptime, pandas._libs.tslibs.parsing, pandas._libs.tslibs.conversion, pandas._libs.tslibs.period, pandas._libs.tslibs.vectorized, pandas._libs.ops_dispatch, pandas._libs.missing, pandas._libs.hashtable, pandas._libs.algos, pandas._libs.interval, pandas._libs.lib, pandas._libs.ops, pyarrow._compute, pandas._libs.arrays, pandas._libs.tslib, pandas._libs.sparse, pandas._libs.indexing, pandas._libs.index, pandas._libs.internals, pandas._libs.join, pandas._libs.writers, pandas._libs.window.aggregations, pandas._libs.window.indexers, pandas._libs.reshape, pandas._libs.groupby, pandas._libs.json, pandas._libs.parsers, pandas._libs.testing, cftime._cftime, scipy._lib._ccallback_c, numba.core.typeconv._typeconv, numba._helperlib, numba._dynfunc, numba._dispatcher, numba.core.runtime._nrt_python, numba.np.ufunc._internal, numba.experimental.jitclass._box, scipy.sparse._sparsetools, _csparsetools, scipy.sparse._csparsetools, scipy.sparse.linalg._isolve._iterative, scipy.linalg._fblas, scipy.linalg._flapack, scipy.linalg.cython_lapack, scipy.linalg._cythonized_array_utils, scipy.linalg._solve_toeplitz, scipy.linalg._decomp_lu_cython, scipy.linalg._matfuncs_sqrtm_triu, scipy.linalg.cython_blas, scipy.linalg._matfuncs_expm, scipy.linalg._decomp_update, scipy.linalg._flinalg, scipy.sparse.linalg._dsolve._superlu, scipy.sparse.linalg._eigen.arpack._arpack, scipy.sparse.csgraph._tools, scipy.sparse.csgraph._shortest_path, scipy.sparse.csgraph._traversal, scipy.sparse.csgraph._min_spanning_tree, scipy.sparse.csgraph._flow, scipy.sparse.csgraph._matching, scipy.sparse.csgraph._reordering, scipy._lib._uarray._uarray, scipy.special._ufuncs_cxx, scipy.special._ufuncs, scipy.special._specfun, scipy.special._comb, scipy.special._ellip_harm_2, scipy.fftpack.convolve, lxml._elementpath, lxml.etree, numpy.linalg.lapack_lite, lz4.frame._frame, pyproj._compat, pyproj._datadir, pyproj._network, pyproj._geod, pyproj.list, pyproj._crs, pyproj.database, pyproj._transformer, pyproj._sync, cartopy.trace, fiona._err, fiona._env, fiona.crs, fiona._geometry, fiona.schema, fiona.ogrext, matplotlib._c_internal_utils, PIL._imaging, matplotlib._path, kiwisolver._cext, matplotlib._image (total: 145)

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 29, 2023

put an "import shapely" statement at the top of variability_modes_driver.py

@acordonez it is interesting to know this would prevent the error. What about if "import shapely" is added at the top of lib/plot_map.py? Could you please check if this would work? I am studying pre-commit settings to see if there is any way to make it an exception.

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 29, 2023

@acordonez I guess this might be related to the version of shapely, which we couldn't update to the latest because of the limit in the Python version that is tied with the CDAT...

@acordonez
Copy link
Collaborator

put an "import shapely" statement at the top of variability_modes_driver.py

@acordonez it is interesting to know this would prevent the error. What about if "import shapely" is added at the top of lib/plot_map.py? Could you please check if this would work? I am studying pre-commit settings to see if there is any way to make it an exception.

@lee1043 When I saw this problem before, shapely has to be called before any cdat packages in the entire run. So if the driver script imports cdat before shapely, even if shapely is called in another script, it causes the segmentation fault.

@acordonez
Copy link
Collaborator

@acordonez I guess this might be related to the version of shapely, which we couldn't update to the latest because of the limit in the Python version that is tied with the CDAT...

@lee1043 I tried a few different versions of shapely, even old ones, with variability_across_timescales and couldn't find one that would work. It might be something to do with underlying C packages that get called by both shapely and cdat, but I didn't investigate the underlying cause that deeply.

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 29, 2023

@acordonez thank you for the comments, very helpful! I revised the driver script to import shapely at the top and added # noqa tag (indicating "NO-QA", NO Quality Assurance) and adjusted pre-commit setting in .pre-commit-config.yaml to allow pre-commit skipping checks for lines with the tag. Could you please check if this address the segmentation fault issue?

@acordonez
Copy link
Collaborator

@lee1043 The segmentation fault is gone!

I'm getting another error in section 3.2.1 (and seeing a similar error in 3.3.1):

%%bash
variability_modes_driver.py -p basic_mov_param_sst.py --case_id "PDO" --msyear 1900 --meyear 2005

mip: cmip5
exp: historical
fq: mo
realm: atm
EofScaling: False
RmDomainMean: True
LandMask: True
nc_out_obs, plot_obs: True True
nc_out_model, plot_model: True True
CMEC:False
mode: PDO
seasons: ['monthly']
models: ['ACCESS1-0']
number of models: 1
realization:  r1i1p1
parallel: False
demo_output/PDO
demo_output/PDO
demo_output/PDO
Estimate landmask

Traceback (most recent call last):
  File "/home/ordonez4/miniconda3/envs/pmp_dev/bin/variability_modes_driver.py", line 444, in <module>
    plot_map(
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/pcmdi_metrics/variability_mode/lib/plot_map.py", line 103, in plot_map
    plot_map_cartopy(
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/pcmdi_metrics/variability_mode/lib/plot_map.py", line 204, in plot_map_cartopy
    im = ax.contourf(
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 315, in wrapper
    return func(self, *args, **kwargs)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 359, in wrapper
    return func(self, *args, **kwargs)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 1659, in contourf
    bboxes = [col.get_datalim(self.transData)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 1659, in <listcomp>
    bboxes = [col.get_datalim(self.transData)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/collections.py", line 266, in get_datalim
    paths = [transform.transform_path_non_affine(p) for p in paths]
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/collections.py", line 266, in <listcomp>
    paths = [transform.transform_path_non_affine(p) for p in paths]
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/matplotlib/transforms.py", line 2439, in transform_path_non_affine
    return self._a.transform_path_non_affine(path)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 182, in transform_path_non_affine
    geoms = cpatch.path_to_geos(src_path,
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/cartopy/mpl/patch.py", line 180, in path_to_geos
    collection[-1][0].contains(geom.exterior)):
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/geometry/base.py", line 658, in contains
    return _maybe_unpack(shapely.contains(self, other))
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/decorators.py", line 77, in wrapped
    return func(*args, **kwargs)
  File "/home/ordonez4/miniconda3/envs/pmp_dev/lib/python3.10/site-packages/shapely/predicates.py", line 540, in contains
    return lib.contains(a, b, **kwargs)
shapely.errors.GEOSException: TopologyException: side location conflict at 257.5 68.5. This can occur if the input geometry is invalid.
[WARNING] yaksa: 10 leaked handle pool objects

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 30, 2023

@acordonez thank you for checking this. I think the error was caused by combinations of multiple factors -- cdms variable with cartopy, 1e20 being used for fill value that was not appreciated by xarray. I add workarounds and confirmed that demo notebook is working without any issue. Could you please double check if this is true on your end as well?

@acordonez
Copy link
Collaborator

@lee1043 The notebook ran perfectly this time

@acordonez
Copy link
Collaborator

@lee1043 Should I merge this?

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 30, 2023

@acordonez Excellent, thank you for double checking!

@lee1043
Copy link
Contributor Author

lee1043 commented Nov 30, 2023

@lee1043 Should I merge this?

@acordonez let me clean up a few more things and will merge it.

@lee1043 lee1043 merged commit a90ed96 into main Nov 30, 2023
5 checks passed
@lee1043 lee1043 deleted the update_mov_run branch November 30, 2023 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants