Skip to content

Commit

Permalink
Replace CDAT
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed May 14, 2024
1 parent 905b755 commit ea853bd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ def package_files(directory, prefixes, extensions):
python_requires=">=3.6",
packages=find_packages(include=["zppy", "zppy.*"]),
package_data={"": data_files},
entry_points={"console_scripts": ["zppy=zppy.__main__:main"]},
entry_points={
"console_scripts": [
"zppy=zppy.__main__:main",
"zppy_cdscan_replacement=zppy.__main__:zppy_cdscan_replacement",
]
},
)
16 changes: 16 additions & 0 deletions zppy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import importlib
import io
import os
import sys
from typing import List

import pandas
from configobj import ConfigObj
from mache import MachineInfo
from validate import Validator
Expand Down Expand Up @@ -246,3 +248,17 @@ def _validate_config(config):
)
else:
print("Configuration file validation passed.")


def zppy_cdscan_replacement():
output_file = sys.argv[1]
input_files = sys.argv[2:]
if len(input_files) == 1:
files = []
# Convert text file of files to a list of files.
with open(input_files[0]) as f:
for line in f:
files.append(line.strip())
input_files = files
dataframe = pandas.read_table(input_files)
dataframe.to_xml(output_file)
4 changes: 2 additions & 2 deletions zppy/templates/e3sm_diags.bash
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ create_links_ts()
# xml file will cover the whole period from year1 to year2
xml_name=${v}_${begin_year}01_${end_year}12.xml
export CDMS_NO_MPI=true
cdscan -x ${xml_name} -f ${v}_files.txt
zppy_cdscan_replacement ${xml_name} ${v}_files.txt
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo "ERROR (${error_num})" > {{ prefix }}.status
Expand All @@ -129,7 +129,7 @@ create_links_ts_rof()
cd ${ts_rof_dir_destination}
v="RIVER_DISCHARGE_OVER_LAND_LIQ"
xml_name=${v}_${begin_year}01_${end_year}12.xml
cdscan -x ${xml_name} ${ts_rof_dir_source}/${v}_*.nc
zppy_cdscan_replacement ${xml_name} ${ts_rof_dir_source}/${v}_*.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo "ERROR (${error_num})" > {{ prefix }}.status
Expand Down
6 changes: 3 additions & 3 deletions zppy/templates/global_time_series.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use_atm={{ use_atm }}
if [[ ${use_atm,,} == "true" ]]; then
echo 'Create xml files for atm'
cd ${case_dir}/post/atm/glb/ts/monthly/${ts_num_years}yr
cdscan -x glb.xml *.nc
zppy_cdscan_replacement glb.xml *.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (1)' > {{ prefix }}.status
Expand All @@ -54,7 +54,7 @@ use_lnd={{ use_lnd }}
if [[ ${use_lnd,,} == "true" ]]; then
echo 'Create xml files for lnd'
cd ${case_dir}/post/lnd/glb/ts/monthly/${ts_num_years}yr
cdscan -x glb.xml *.nc
zppy_cdscan_replacement -x glb.xml *.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (2)' > {{ prefix }}.status
Expand All @@ -78,7 +78,7 @@ if [[ ${use_ocn,,} == "true" ]]; then
echo 'Create xml for for ocn'
export CDMS_NO_MPI=true
cd ${case_dir}/post/ocn/glb/ts/monthly/${ts_num_years}yr
cdscan -x glb.xml mpaso.glb*.nc
zppy_cdscan_replacement glb.xml mpaso.glb*.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (4)' > {{ prefix }}.status
Expand Down
7 changes: 3 additions & 4 deletions zppy/templates/readTS.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import cdms2
import cdutil
import xcdat


class TS(object):
def __init__(self, filename):

self.filename = filename

self.f = cdms2.open(filename)
self.f = xcdat.open_dataset(filename)

def __del__(self):

Expand Down Expand Up @@ -66,6 +65,6 @@ def globalAnnual(self, var):
units = v.units

# Annual average
v = cdutil.YEAR(v)
v = self.f.temporal.group_average(v, "year")

return v, units

0 comments on commit ea853bd

Please sign in to comment.