Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions DAmonitor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def load_inv_bkg_ana(files):
return datasets


def query_dataset(dataset):
def query_dataset(dataset, meta_exclude=None):
if dataset.groups:
for grp in dataset.groups:
print(grp)
Expand All @@ -107,7 +107,8 @@ def query_dataset(dataset):
print(text + text2.rstrip(","))
else:
for var in dataset.groups[grp].variables:
text += f"{var}, "
if meta_exclude is None or meta_exclude not in var:
text += f"{var}, "
print(text.rstrip(","))
else:
text = ""
Expand All @@ -116,12 +117,13 @@ def query_dataset(dataset):
print(text.rstrip(","))


def query_data(data):
def query_data(data, meta_exclude=None):
text = ""
if data.data:
data = data.data
for var in data:
text += f"{var}, "
if meta_exclude is None or meta_exclude not in var:
text += f"{var}, "
print(text.rstrip(","))


Expand Down
4 changes: 2 additions & 2 deletions DAmonitor/obs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .ioda import ioda
from .obsSpace import obsSpace
from .fit_rate import fit_rate

__all__ = [
'ioda',
'obsSpace',
'fit_rate',
]
25 changes: 15 additions & 10 deletions DAmonitor/obs/ioda.py → DAmonitor/obs/obsSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def __getattr__(self, name):
raise AttributeError(f"No variable '{name}_{self.varname}' found.") from e


class ioda:
class obsSpace:
def __init__(self, filepath):
"""
Initialize an IODA object and load the NetCDF file.
Initialize an obsSpace object and load the NetCDF file.

Parameters:
- filepath (str): Path to the NetCDF file.
Expand All @@ -39,8 +39,8 @@ def __init__(self, filepath):
#
self._get_metadata()

# Remove groups, provide direct access to varaibles, such as ioda.t, ioda.q, ioda.u, ioda.v, etc
for var in ["airTemperature", "windEastward", "windNorthward", "specificHumidity"]:
# Remove groups, provide direct access to varaibles, such as obsSpace.t, obsSpace.q, obsSpace.u, obsSpace.v, etc
for var in ["airTemperature", "windEastward", "windNorthward", "specificHumidity", "brightnessTemperature"]:
self._get_data_by_varname(var)

def get_valid_subset(data, item, condition={"EffectiveQC2": 0}):
Expand All @@ -64,8 +64,9 @@ def _get_data_by_varname(self, varname):
for grp in dataset.groups:
if dataset.groups[grp].groups:
for nestgrp in dataset.groups[grp].groups: # DiagnosticFlags
data[nestgrp] = dataset.groups[grp].groups[nestgrp].variables[varname][:]
only_has_metadata = False
if varname in dataset.groups[grp].groups[nestgrp].variables:
data[nestgrp] = dataset.groups[grp].groups[nestgrp].variables[varname][:]
only_has_metadata = False
else:
if grp == "MetaData":
for var in dataset.groups['MetaData'].variables:
Expand All @@ -74,7 +75,7 @@ def _get_data_by_varname(self, varname):
elif grp == "ObsError" and varname == "specificHumidity":
data["ObsError"] = dataset.groups["ObsError"].variables["relativeHumidity"][:]
only_has_metadata = False
elif varname == "brightnessTemperature" and (grp == "ObsValue" or grp == "ObsValueAdj"):
elif varname == "brightnessTemperature" and (grp == "ObsValue" or grp == "ObsValueAdj") and "brightnessTemperature" in dataset.groups[grp].variables:
data[grp] = dataset.groups[grp].variables["radiance"][:]
only_has_metadata = False
elif varname in dataset.groups[grp].variables:
Expand All @@ -92,9 +93,11 @@ def _get_data_by_varname(self, varname):
self.v = _ObsDF(data)
elif varname == "specificHumidity":
self.q = _ObsDF(data)
elif varname == "brightnessTemperature":
self.bt = _ObsDF(data)

def __getitem__(self, key):
# Enable ioda["t"]
# Enable obsSpace["t"]
if key in ["t", "airTemperature"]:
return self.t
elif key in ["u", "windEastward"]:
Expand All @@ -103,11 +106,13 @@ def __getitem__(self, key):
return self.u
elif key in ["q", "specificHumidity"]:
return self.q
elif key in ["bt", "brightnessTemperature"]:
return self.bt
raise KeyError(f"Key '{key}' not found.")

def __getattr__(self, name):
# Enable myioda.t (only called if attribute not found normally)
# Enable obsSpace.t
try:
return self.__getitem__(name)
except KeyError:
raise AttributeError(f"'ioda' object has no attribute or variable '{name}'")
raise AttributeError(f"'obsSpace' object has no attribute or variable '{name}'")
1 change: 1 addition & 0 deletions DAmonitor/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import geopandas as gp

pyDAmonitor_ROOT = os.getenv("pyDAmonitor_ROOT")

# common border lines
coast_lines = gf.coastline(projection=ccrs.PlateCarree(), line_width=1, scale="50m")
state_lines = gf.states(projection=ccrs.PlateCarree(), line_width=1, line_color='gray', scale="50m")
Expand Down
5 changes: 4 additions & 1 deletion docs/_toc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of contents
# Learn more at https://jupyterbook.org/customize/toc.html
# **** Be sure to remove the trailing .ipynb or .md ****

format: jb-book
root: intro
Expand All @@ -10,7 +11,9 @@ parts:
- file: example
- file: markdown-notebooks

- caption: demo
- caption: DA monitor
chapters:
- file: notebook_docs/mpas_plotting
title: mpas-jedi plotting
- file: notebook_docs/obs_exploring
title: obs exploring
33 changes: 24 additions & 9 deletions docs/build_book.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ doc_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
#### add new notebooks to the notebooks array
declare -A notebooks
notebooks["mpas_plotting.ipynb"]="mpas_plotting.ipynb"
notebooks["obs_exploring.ipynb"]="obs_exploring.ipynb"


### users usually do not need to make changes below this line
### ========================================================================
doc_repo=$1
if [[ -z "${doc_repo}" ]]; then
echo "Usage: build_book.sh <doc_repo>"
exit 1
fi

set -x
### always start from a clean notebook_docs/ directory
rm -rf ${doc_dir}/notebook_docs
Expand All @@ -28,10 +23,30 @@ done
jupyter-book clean ${doc_dir}
jupyter-book build ${doc_dir}

### push book to doc_repo
### push book to book_repo
# save the origin URL and restore after ghp-import, which has to use the origin remote
save_origin=$(git remote get-url origin)

git remote set-url origin ${doc_repo}
ghp-import -n -p -f ${doc_dir}/_build/html
# get the remote url for current branch and set it as book_repo
remote=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} | cut -d'/' -f1)
book_repo=$(git remote get-url ${remote})
#book_repo= # use this line to overwrite the automatically-detected book_repo

if [[ "${book_repo}" == *"NOAA-GSL/pyDAmonitor" ]] \
|| [[ "${book_repo}" == *"pyDAmonitor/pyDAmonitor" ]]; then
echo "ERROR: current branch tracks the authoritative repository:"
echo " ${book_repo}"
echo "users can ONLY push books to their own forks"
exit 1
fi

# change origin, ghp-import and then restore origin
git remote set-url origin ${book_repo}
ghp-import -n -p -f ${doc_dir}/_build/html
git remote set-url origin ${save_origin}

### print out helper information
set +x
account=$(echo "${book_repo}" | awk -F'[:/]' '{print $(NF-1)}')
echo -e "\nVisit https://${account}.github.io/pyDAmonitor to check the results"
echo " (Github action may take a few minutes to render the updated pages)"
6 changes: 1 addition & 5 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ MarkDown files can be used to add additional documentation.
# Table of Contents

- [mpas_plotting Notebook](notebook_docs/mpas_plotting)
- place holder
- place holder
- place holder
- place holder
- place holder
- [obs exploring](notebook_docs/obs_exploring)
- place holder
- place holder
- place holder
Expand Down
125 changes: 0 additions & 125 deletions funcs/base.py

This file was deleted.

40 changes: 0 additions & 40 deletions funcs/colormap.py

This file was deleted.

Loading