Commit 4b1a2352 authored by Elise Potier's avatar Elise Potier
Browse files

options for new CAMS version

parent aaf8938c
"""
Read CAMS products
Option to define pressure coordinate names depending on CAMS version
"""
from .get_domain import get_domain
from .fetch import fetch
from .read import read
......@@ -6,3 +12,13 @@ _name = "CAMS"
_version = "netcdf"
_fullname = "CAMS netcdf files"
input_arguments={
"aibi_name": {
"doc": "to choose ai bi vertical coordinate names"
" instead of hyam and hybm",
"default": False,
"accepted": bool
},
}
......@@ -61,8 +61,12 @@ def get_domain(ref_dir, ref_file, input_dates, target_dir, tracer=None):
latc = np.linspace(lat_min - dy/2., lat_max + dy/2., nlat + 1)
# Read vertical information in domain_file
sigma_a = nc["hyam"].values
sigma_b = nc["hybm"].values
if tracer.aibi_name:
sigma_a = nc["ap"].values
sigma_b = nc["bp"].values
else :
sigma_a = nc["hyam"].values
sigma_b = nc["hybm"].values
nlevs = sigma_a.size
# Initializes domain
......
import datetime
import calendar
import os
import pandas as pd
import numpy as np
......@@ -50,21 +51,25 @@ def read(
opened_file = dd_file
ntimes = ds.dims["time"]
freq = dd[0].days_in_month * 24 / ntimes
#freq = dd[0].days_in_month * 24 / ntimes
freq = (calendar.mdays[dd[0].month] + ( dd[0].month == 2 and calendar.isleap( dd[0].year))) * 24 / ntimes
print("to check with february")
print(dd[0].month)
print(calendar.mdays[dd[0].month] + ( dd[0].month == 2 and calendar.isleap( dd[0].year)))
date_index = int((dd[0] - ddi) / datetime.timedelta(hours=freq))
# bottom of the atmosphere = at the beginning of the table
lat = ds['latitude']
conc = ds[var2extract].values[date_index]
if lat[1] < lat[0]:
if lat[1] < lat[0] and conc.ndim==4:
conc = conc[:, :, ::-1, :]
elif lat[1] < lat[0] and conc.ndim==3:
conc = conc[ :, ::-1, :]
xout.append(conc)
xmod = xr.DataArray(
np.array(xout),
coords={"time": np.array(dates)[:, 0]},
dims=("time", "lev", "lat", "lon"),
)
return xmod
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment