Skip to content

Instantly share code, notes, and snippets.

@samoylovfp
Created October 5, 2020 14:43
Show Gist options
  • Save samoylovfp/ba1df8ef41f27c44ddeed9f2d4076fc9 to your computer and use it in GitHub Desktop.
Save samoylovfp/ba1df8ef41f27c44ddeed9f2d4076fc9 to your computer and use it in GitHub Desktop.
set -e
echo "===== Generating a file with missing_value = NaN =====\n\n"
cat <<EOF > replicate.py
from netCDF4 import Dataset
import numpy as np
with Dataset("/srv/with_nan.nc", "w", format="NETCDF4") as d:
data_dim = d.createDimension("d", None)
data_var = d.createVariable("d", "f4", ("d",))
data_var.missing_value = float("nan")
data_var.some_random_attribute = float("nan")
data_var[:] = np.array([1.0, 2.0, float("nan")])
EOF
docker run -tv $PWD:/srv python:3 bash -c 'pip install netcdf4==1.5.4; python /srv/replicate.py'
echo "\n\n===== Here's the generated missing_value: ====="
ncdump -h with_nan.nc | grep -E "missing_value|some_random_attribute"
echo "\n\n"
docker run -d --rm --name hyrax_with_none -p 8088:8080 -v $PWD:/usr/share/hyrax opendap/hyrax
stop_hyrax() {
docker kill hyrax_with_none
}
trap stop_hyrax EXIT
sleep 5
wget localhost:8088/opendap/with_nan.nc.nc4\? -O downloaded_from_hyrax.nc.nc4
echo "\n\n===== Here's missing_value after processed by opendap ====="
ncdump -h downloaded_from_hyrax.nc.nc4 | grep -E "missing_value|some_random_attribute"
echo "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment