Skip to content
Open
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "ilamb"
version = "2.7.2"
description = "ILAMB environment dependencies"
requires-python = ">=3.9"
dependencies = [
"numpy",
"pandas",
"matplotlib",
"cartopy",
"netCDF4",
"cf-units",
"sympy",
"mpi4py",
"scipy",
"cftime",
"tqdm",
"pyarrow",
"PyYAML",
"requests"
]
dynamic = ["classifiers", "readme", "keywords"]

[project.optional-dependencies]
dev = [
"pytest",
"black",
"flake8"
]



[tool.setuptools]
packages = ["ILAMB"]
package-dir = {"" = "src"}

19 changes: 14 additions & 5 deletions src/ILAMB/ConfCO2.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,20 @@ def emulatedModelResult(self, m, obs):
ilev = 1

# Get the model result
mod = m.extractTimeSeries(
emulated_flux,
initial_time=obs.time_bnds[0, 0] - float(Ninf) / 12 * 365 + 29.0,
final_time=obs.time_bnds[-1, 1],
)

try:
mod = m.extractTimeSeries(
emulated_flux,
initial_time=obs.time_bnds[0, 0] - float(Ninf) / 12 * 365 + 29.0,
final_time=obs.time_bnds[-1, 1],
)
except:
emulated_flux = "nbp"
mod = m.extractTimeSeries(
emulated_flux,
initial_time=obs.time_bnds[0, 0] - float(Ninf) / 12 * 365 + 29.0,
final_time=obs.time_bnds[-1, 1],
)

# What if I don't have Ninf leadtime?
tf = min(obs.time_bnds[-1, 1], mod.time_bnds[-1, 1])
Expand Down
31 changes: 19 additions & 12 deletions src/ILAMB/ConfGSNF.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ def stageData(self, m):
the model."""
model_flux = self.keywords.get("model_flux", "nee")
obs = Variable(filename=self.source, variable_name=self.variable)
mod = (
m.extractTimeSeries(
model_flux,
expression=model_flux,
initial_time=(2000 - 1850) * 365, # earlier so CMIP5 will be included
final_time=(2017 - 1850) * 365,
)
.trim(lat=[20, 90])
.integrateInSpace()
.annualCycle()
.convert(obs.unit)
)

for mf in model_flux.split(','):
try:
mod = (
m.extractTimeSeries(
mf,
expression=mf,
initial_time=(2000 - 1850) * 365, # earlier so CMIP5 will be included
final_time=(2017 - 1850) * 365,
)
.trim(lat=[20, 90])
.integrateInSpace()
.annualCycle()
.convert(obs.unit)
)
break
except:
continue
raise il.VarNotInModel()
# just a hack to make sure the cycles are on the same time frame
obs.time = mod.time
obs.time_bnds = mod.time_bnds
Expand Down
24 changes: 16 additions & 8 deletions src/ILAMB/ModelResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,22 @@ def extractTimeSeries(
# variable from a given expression
if len(V) == 0:
if expression is not None:
v = self.derivedVariable(
variable,
expression,
lats=lats,
lons=lons,
initial_time=initial_time,
final_time=final_time,
)

expressions = expression.split(',')
for express in expressions:
try:
v = self.derivedVariable(
variable,
express,
lats=lats,
lons=lons,
initial_time=initial_time,
final_time=final_time,
)
return v
except:
continue
raise il.VarNotInModel()
else:
tstr = ""
if tmin < tmax:
Expand Down
1 change: 1 addition & 0 deletions src/ILAMB/Variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def __init__(self, **keywords):

# Add handling for some units which cf_units does not support
unit = unit.replace("psu", "1e-3")
unit = unit.replace("proportion", "1")

if not np.ma.isMaskedArray(data):
data = np.ma.masked_array(data)
Expand Down
2 changes: 1 addition & 1 deletion src/ILAMB/ilamblib.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def FromNetCDF4(
data_name = [
name
for name in var.dimensions
if name.lower() in ["data", "lndgrid", "gridcell"]
if name.lower() in ["data", "lndgrid", "gridcell", "site"]
]
missed = [
name
Expand Down
Loading