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

Gtm/time series at grid cell #21

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

guilhermeltm
Copy link
Collaborator

@guilhermeltm guilhermeltm commented Apr 2, 2024

Script to plot time series for a list of variables at a particular point (lon,lat,vertlevel) and time period from MPAS raw output files.

Usage (optional input arguments may be given, see code):
python3 mpas_time_series_at_point.py --dir /path/to/data
--stream history --lat -2.12 --lon -59.00 --vertlevel 0 --t0 '2021-01-01 00:00:00' --tf '2021-01-02 18:00:00'
--dt 10800 --var swdnb,swupb

TODO: utils.py should contain generally useful functions for postprocessing. Therefore, it should live under MPAS-BR/post_proc/py/.

@guilhermeltm guilhermeltm requested a review from favba April 2, 2024 21:11
@guilhermeltm guilhermeltm marked this pull request as ready for review April 2, 2024 21:11
@favba
Copy link
Collaborator

favba commented Apr 8, 2024

Hi @guilhermeltm ,
Why don't you try moving the utils.py file to post_proc/py and just create a symlink to it in the post_proc/py/time_series_compare directory? Then, in there, you just need to do ln -s ../utils.py ./.
From what I read git preserves symbolic links, so this should work.
Then we'll have only one version of utils.py that can be used in your other PR as well. (You'd need to cd into post_proc/py/interactive_postprocessing and do ln -s ../utils.py ./ there as well.

@favba
Copy link
Collaborator

favba commented Jun 12, 2024

I got a similar error to the one I described in the other PR:

python3 mpas_time_series_at_point.py --dir ~/Work/IME/Local/history_files/ --stream diag --lat -2.12 --lon -59.00 --vertlevel 0 --t0 '2021
-01-01 00:00:00' --tf '2021-01-02 18:00:00' --dt 10800 --var swdnb,swupb
Traceback (most recent call last):
  File "/home/felipealves/.miniforge3/envs/mpas-tools/lib/python3.12/site-packages/xarray/core/dataset.py", line 1408, in _copy_listed
    variables[name] = self._variables[name]
                      ~~~~~~~~~~~~~~~^^^^^^
KeyError: 'latVertex'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/felipealves/Work/IME/Compartilhado/Code/MPAS/gtmPR2/post_proc/py/time_series_compare/mpas_time_series_at_point.py", line 64, in <module>
    cat_file = concat_mpas_output(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/felipealves/Work/IME/Compartilhado/Code/MPAS/gtmPR2/post_proc/py/time_series_compare/utils.py", line 109, in concat_mpas_output
    cat_file = xr.open_dataset(f'{data_dir}/{filename1}', engine='netcdf4')[vars_list]
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/felipealves/.miniforge3/envs/mpas-tools/lib/python3.12/site-packages/xarray/core/dataset.py", line 1546, in __getitem__
    return self._copy_listed(key)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/felipealves/.miniforge3/envs/mpas-tools/lib/python3.12/site-packages/xarray/core/dataset.py", line 1410, in _copy_listed
    ref_name, var_name, var = _get_virtual_variable(
                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/felipealves/.miniforge3/envs/mpas-tools/lib/python3.12/site-packages/xarray/core/dataset.py", line 214, in _get_virtual_variable
    raise KeyError(key)
KeyError: 'latVertex'

as the NC files do not have a latVertex field.
Couldn't you use a try block to try reading those and then just error if we actually try to use this field. It seems we don't really need latVertex field in order to plot fields at the cells...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants