def pmodelenv(values): """Fixture to create PModelEnvironments with scalar and array inputs """ sc = pmodel.PModelEnvironment(tc=values['tc_sc'], vpd=values['vpd_sc'], co2=values['co2_sc'], patm=values['patm_sc']) ar = pmodel.PModelEnvironment(tc=values['tc_ar'], vpd=values['vpd_ar'], co2=values['co2_ar'], patm=values['patm_ar']) return {'sc': sc, 'ar': ar}
def dataset(): """Fixture to load test inputs from file from data folder in package root """ test_dir = os.path.dirname(os.path.abspath(__file__)) data_file_path = os.path.normpath( os.path.join(test_dir, os.pardir, os.pardir, 'data', 'pmodel_inputs.nc')) dataset = netCDF4.Dataset(data_file_path) # TODO - masked arrays should be handled (it is basically the same as # NA values in the R implementation) but for current validation # this is just going to convert them to filled arrays dataset.set_auto_mask(False) # Extract the six variables for all months temp = dataset['temp'][:] co2 = dataset['CO2'][:] # Note - spatially constant but mapped. elev = dataset['elevation'][:] # Note - temporally constant but repeated vpd = dataset['VPD'][:] fapar = dataset['fAPAR'][:] ppfd = dataset['ppfd'][:] dataset.close() # Convert elevation to atmospheric pressure patm = pmodel.calc_patm(elev) # Calculate p model environment env = pmodel.PModelEnvironment(tc=temp, vpd=vpd, co2=co2, patm=patm) return env, fapar, ppfd
def test_pmodelenvironment_dewpoint(): with pytest.raises(ValueError): ret = pmodel.PModelEnvironment(tc=np.array([-15, 5, 10, 15, 20]), vpd=-1, co2=400, patm=101325)
def test_pmodelenvironment_toocold(): with pytest.raises(ValueError): ret = pmodel.PModelEnvironment(tc=np.array([-35, 5, 10, 15, 20]), vpd=1000, co2=400, patm=101325)
def test_pmodelenvironment_constraint(): with pytest.warns(UserWarning): ret = pmodel.PModelEnvironment(tc=np.array([-15, 5, 10, 15, 20]), vpd=100000, co2=400, patm=101325)
def test_pmodelenvironment(values, variables): ret = pmodel.PModelEnvironment(tc=values[variables['tc']], patm=values[variables['patm']], vpd=values[variables['vpd']], co2=values[variables['co2']]) assert np.allclose(ret.gammastar, values[variables['gammastar']]) assert np.allclose(ret.ns_star, values[variables['ns_star']]) assert np.allclose(ret.kmm, values[variables['kmm']]) assert np.allclose(ret.ca, values[variables['ca']])