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

netCDF4 now stores strings as char arrays #38

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tomplot/data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd
import warnings
from netCDF4 import chartostring
from .cubed_sphere import lonlat_to_alphabeta

__all__ = ["extract_gusto_field", "extract_gusto_coords",
Expand Down Expand Up @@ -55,7 +56,10 @@ def extract_gusto_coords(dataset, field_name, units=None):
# Checks on units argument and set default for this domain
# ------------------------------------------------------------------------ #
# Work out which units to return the coords in, based on domain metadata
domain = dataset.variables['domain_type'][:]
try:
domain = str(chartostring(dataset.variables['domain_type'][:][0]))
except:
domain = dataset.variables['domain_type'][:]
if domain == 'spherical_shell':
assert units in [None, 'deg', 'rad'], 'extract_gusto_coords: for a ' \
+ f'spherical shell domain units must be "deg" or "rad" not {units}'
Expand Down