.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_d13C_comp.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_d13C_comp.py: ======================================================= Search the nearest grid point for a given location ======================================================= This example is a combination of ScatterData and GriddedData to search the nearest grid point for a given location. I use CESM model output(You can download them from https://zenodo.org/records/13786013) and LGM d13C data from Peterson et al. 2014 (https://agupubs.onlinelibrary.wiley.com/doi/full/10.1002/2013PA002552) as an example. .. GENERATED FROM PYTHON SOURCE LINES 8-48 .. image-sg:: /auto_examples/images/sphx_glr_plot_d13C_comp_001.png :alt: Model vs Observation :srcset: /auto_examples/images/sphx_glr_plot_d13C_comp_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading CESM_LGM_var_regrid.nc to /home/docs/.cgeniepy/CESM_LGM_var_regrid.nc... Download complete. File LGM_d13c_CLEAN.txt already exists at /home/docs/.cgeniepy/LGM_d13c_CLEAN.txt. Skipping download. | .. code-block:: Python from cgeniepy.table import ScatterData from cgeniepy.array import GriddedData import xarray as xr from cgeniepy.utils import download_zenodo_file record_id = "13786013" filename = "CESM_LGM_var_regrid.nc" local_file_path = download_zenodo_file(record_id, filename) ## read in the data and construct GriddedData object cesm_lgm = xr.load_dataset(local_file_path) cesm_13C = GriddedData(cesm_lgm['CISO_DIC_d13C'], attrs=cesm_lgm['CISO_DIC_d13C'].attrs) cesm_13C_last = cesm_13C.isel(time=-1) ## read in the proxy data and construct ScatterData object filename = "LGM_d13c_CLEAN.txt" local_file_path = download_zenodo_file(record_id, filename) proxy_d13C = ScatterData(local_file_path, delimiter="\t", header=None) proxy_d13C.data.columns = ["Longitude", "Latitude", "Depth", "observational d13C","Event"] proxy_d13C.set_index(["Latitude", "Longitude", "Depth"]) model_data = [] for i in proxy_d13C.data.index: lat, lon, depth = i depth = depth * 100 ## not necessary for cGENIE whose depth is in m pos = (depth, lat, lon) data = cesm_13C_last.search_point(pos, ignore_na=True) model_data.append(data) ## add the model data to the dataframe proxy_d13C.data["CESM_d13C"] = model_data ## plot the comparison ## by default, model data is in the col, and observational col is in the second proxy_d13C.compare("CESM_d13C","observational d13C").plot() .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 34.093 seconds) .. _sphx_glr_download_auto_examples_plot_d13C_comp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_d13C_comp.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_d13C_comp.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_d13C_comp.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_