Coder Social home page Coder Social logo

pcse's People

Contributors

abegomez avatar ajwdewit avatar cclauss avatar fanquake avatar ivan-o avatar jiang2019code avatar julienmalard avatar marekpetrik avatar sbhoek avatar sytbru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcse's Issues

CarbonBalanceError

When running a simulation, we get the follwing error: CarbonBalanceError: Carbon un-balance in crop model at day 2007-04-13. This results when running a nutrient-limited crop growth model, LINTUL3. Do you know where the error might come from?

"apply_npk" signal invaild while sent to Wofost80_NWLP_FD_beta model

When "apply_npk" signal is sent, the content of nitrogen, phosphorus and potassium in Wofost80_NWLP_FD_beta model will not change.This problem seems to be related to the RateVariables class.

I modified the code as below, and the problem seems to be solved.
` def _on_APPLY_NPK(self, N_amount=None, P_amount=None, K_amount=None, N_recovery=None,
P_recovery=None, K_recovery=None):

    r = self.rates
    r.unlock()
    r.FERT_N_SUPPLY = N_amount * N_recovery
    r.FERT_P_SUPPLY = P_amount * P_recovery
    r.FERT_K_SUPPLY = K_amount * K_recovery
    r.RNAVAIL += r.FERT_N_SUPPLY
    r.RPAVAIL += r.FERT_P_SUPPLY
    r.RKAVAIL += r.FERT_K_SUPPLY
    r.lock()

`

easy way to display the meaning of output variables

A lot of different abbreviations are used to refer to outputs of crop models.
I see LAIMAX, RD, TAGP, TWLV, TWRT, TWSO, TWST in summary output
and DVS, LAI, TAGP, TWSO, TWLV, TWST, TWRT, TRA, RD, SM, WWLOW in the output.
For me, I cannot figure what all of these mean.

Improving WeatherDataProvider using interpolation

I think NASA is missing data for some dates, and when running WOFOST if there's a missing datapoint in the weather data, it fails with the following error:
WeatherDataProviderError: No weather data for 2017-08-21.
It would be helpful to have some error handling or completing the gaps in the data using some sort of interpolation.

set_variable(variablename, newvalue) is invalid

I want to update the state variable "TWSO" according to my observational data.
To achieve my goal, I wrote a brief function in class WOFOST_Storgan_Dynamics(SimulationObject) :

def _set_variable_TWSO(self, nTWSO):
states = self.states
oTWSO = states.TWSO
states.TWSO = nTWSO
increments = {"TWSO": states.TWSO - oTWSO}
return increments

In my own pcse projection, I used the following code to update "TWSO":

increasement = model.set_variable("TWSO", my_observation)

The code was processed successfully without no errors. But when I checked the final results, I found that the value wasn't updated at all! Is there anything I missed? I really need your help.

Manage missing days on NASA Power API calls

Hello and thanks for your work,
I wonder if there is a way to manage missing days on NASA Power API calls,
What seems the most straightforward is to perform a linear interpolation on the exported dataframe using Pandas such as

df = pd.DataFrame(weather.export()).set_index("DAY")
df=df.asfreq('D').interpolate()

However i don't see how to import back this dataframe as a weather object, and the needed csv format for the csv import helper needs quite a lot of reformatting. Is there an easy workaround for this ?
Thanks !
J.

Can't load weather data correctly using Excel

I'm trying to load my weather data into Wofost72_WLP_FD.
The ExcelWeatherDataProvider can read the data and show the description like follows:

image

It shows that:
"Data available for 2007-01-01 - 2008-12-31
Number of missing days: 0"

However, when I run the Wofost72_WLP_FD, it occurs that "No weather data for 2017-01-01.".
image

At first I thought it was because of the format of data in Excel, then I made it as same as the format of nl1.xlsx of official but didn't make it. The format of part of data is below:
image

How can I make it work?Thanks for help!

Can't input value 0 in sunshine value

when I load weather file in excel format, and set HasSunshine=True, pcse5.5.5 can't support the value of sunshine =0. So I wonder if this setting is reasonable, the code is in the file pcse\fileinput\excelweatherdataprovider.py line 173, if 0 < value < 24:

There may be some error in chapter 4.1.4 of doc

The example of an aromanagement definition file:
Original text
...
envents_table:

  • 2000-05-25: {amount: 3.0, efficiency=0.7}
    ...
    This kind of setting didn't work on Wofost72_WLP_FD

Revised text?
...
envents_table:

  • 2000-05-25: {amount: 3.0, efficiency: 0.7}
    ...

Applying fertilizer seems to have no impact on growth of a crop in Wofost80_NWLP_FD_beta

Dear all,

I am trying to use PSCE to look at the effects of fertilizer on the growth of a crop in a specific crop rotation. To do this I used the [Notebook #7] (https://github.com/ajwdewit/pcse_notebooks/blob/master/07%20Running%20crop%20rotations.ipynb) and changed a few things:

  • Changed WOFOST72 to Wofost80_NWLP_FD_beta accessing the package from the develop branch (to solve the 'DVS' error)
  • Set the parameters that were missing in the provided data (RKUPTAKEMAX, RNUPTAKEMAX, RPUPTAKEMAX, NAVAILI, PAVAILI, KAVAILI).

Then, I added the fertilization to the agromanagement as follows:

agro_yaml_fert = """
AgroManagement:
- 2004-08-01:
    CropCalendar:
        crop_name: wheat
        variety_name: Winter_wheat_101
        crop_start_date: 2004-09-15
        crop_start_type: sowing
        crop_end_date:
        crop_end_type: maturity
        max_duration: 300
    TimedEvents: null
    StateEvents: 
    -   event_signal: apply_npk
        event_state: DVS
        zero_condition: rising
        name: DVS-based N/P/K application table
        comment: all fertilizer amounts in kg/ha
        events_table:
        - 0.3: {N_amount : 1, P_amount: 3, K_amount: 4}
        - 0.6: {N_amount: 11, P_amount: 13, K_amount: 14}
        - 1.12: {N_amount: 21, P_amount: 23, K_amount: 24}
- 2005-09-01:
    CropCalendar: null
    TimedEvents: null
    StateEvents: null
- 2006-03-01:
    CropCalendar:
        crop_name: sugarbeet
        variety_name: Sugarbeet_601
        crop_start_date: 2006-04-15
        crop_start_type: sowing
        crop_end_date:
        crop_end_type: maturity
        max_duration: 200
    TimedEvents:
    -   event_signal: apply_n
        name: Nitrogen application table
        comment: All nitrogen amounts in g N m-2
        events_table:
        - 2006-04-10: {amount: 10, recovery: 0.7}
        - 2006-05-05: {amount: 5, recovery: 0.7}
    StateEvents: null
"""

However, the outcome does not seem to change. Am I doing something wrong here or is the model simply not able yet to take fertilization into account? I have attached my notebook. Moreover, I have tried different values for the missing parameters, but that does not seem to solve the issue either.

Thanks in advance,

Tessa
WOFOST 8.0 implementation and comparison.zip

Providing DTEMP

pcse.engine checks whether DTEMP is provided and if not, makes an approximation:
if not hasattr(drv, "DTEMP"):
drv.add_variable("DTEMP", (drv.TEMP + drv.TMAX)/2., "Celcius")

However, DTEMP is not listed as an optional parameter in pcse.weather. Therefore, I cannot store it in a WeatherDataContainer to use in a simulation.

I think this is as simple as adding DTEMP to the list of optional parameters in pcse.weather.
I am new to Git, but I'm happy to make that change once I understand how pull requests work.

Cheers
Sam

Need for Angstrom factors even if HasSunshine=False

I provide IRRAD values derived from ERA5 SiS Agmet daily solar_radiation_flux and (therefore) set HasSunshine=False, also because I do not know the Angstrom factors for my particular area (so I filled in dummies, because they are still required). However, pcse still checks these factors, so they must obey the validity range. The check should depend on HasSunshine.
(I use CSVWeatherDataProvider)

Minor nuisance.

TypeError: __init__() takes 4 positional arguments but 6 were given

I have followed your documentation "Running PCSE/WOFOST with custom input data"
but I am facing the issue (TypeError: init() takes 4 positional arguments but 6 were given) during the implementation of your code

from pcse.models import Wofost71_WLP_FD
wofsim = Wofost71_WLP_FD(sitedata, timerdata, soildata, cropdata, wdp)


TypeError Traceback (most recent call last)
in
----> 1 wofsim = Wofost71_WLP_FD(sitedata, timerdata, soildata, cropdata, wdp)

TypeError: init() takes 4 positional arguments but 6 were given

Can you help me ASAP

Problem about documentation.

Hello Folks,

Apparently, there is a problem about the description of irrigation signal in the documentation. In the documentation, the irrigation should be defined in this way.

Version: 1.0
AgroManagement:

  • 1999-09-01:
    CropCalendar:
    crop_id: winter-wheat
    crop_start_date: 1999-10-01
    crop_start_type: sowing
    crop_end_date: 2000-08-05
    crop_end_type: harvest
    max_duration: 330
    TimedEvents:
    • event_signal: irrigate
      name: Timed irrigation events
      comment: All irrigation amounts in cm
      events_table:
    • 2000-05-01: {irrigation_amount: 2, efficiency: 0.7}
    • 2000-06-21: {irrigation_amount: 5, efficiency: 0.7}
    • 2000-07-18: {irrigation_amount: 3, efficiency: 0.7}
      StateEvents:

However,

The callback function to treat the irrigation signal is this.

def _on_IRRIGATE(self, amount, efficiency): self._RIRR = amount * efficiency

Observe that the name of the irrigation_amount parameter is amount not irrigation_amount as described in the documentation.

then I get this error

TypeError: _on_IRRIGATE() takes exactly 3 arguments (2 given) Uncaught exception. Entering post mortem debugging

when using the Wofost71_WLP_FD model and had to change the agromanager to

Version: 1.0
AgroManagement:

  • 1999-09-01:
    CropCalendar:
    crop_id: winter-wheat
    crop_start_date: 1999-10-01
    crop_start_type: sowing
    crop_end_date: 2000-08-05
    crop_end_type: harvest
    max_duration: 330
    TimedEvents:
    • event_signal: irrigate
      name: Timed irrigation events
      comment: All irrigation amounts in cm
      events_table:
    • 2000-05-01: {amount: 2, efficiency: 0.7}
    • 2000-06-21: {amount: 5, efficiency: 0.7}
    • 2000-07-18: {amount: 3, efficiency: 0.7}
      StateEvents:

To get the desired result.

Thanks

Document input and output variables

Input and output variables (and ones that can or cannot be obtained or modified through get_variable and set_variable) would be a lot easier to manage if they were listed in the documentation for all modules.

I would be happy to contribute to an eventual pull request, if there is interest in this proposal.

Thank you,
Julien Malard

Apply NPK and Irrigation during simmulation

Dear colleagues, thank you for developing and supporting the model!:heart:
🙋 I'm trying to figure out how models work and would like to know if I can add irrigation or fertilization during simulations?

As I understand it, we usually define all events in agromanagement and after loading the model, we can't add new irrigation or fertilization.

💡 My idea is simple: I want to go day by day, and sometimes water based on data about the state of the soil and plants

from dataproviders import parameters, agromanagement, weather
wofost = Wofost71_WLP_FD(parameters, weather, agromanagement)
#run model for a few days
wofost.run(days=100)

#observe model variables, for example Soil Moisture
wofost.get_output()[-1]

# I tried this function to add new irrigation (I think its wrong idea)
wofost._send_signal(signal=signals.irrigate, amount=10, efficiency=0.7)

Thank you for any help! 🙏

Sensitivity analysis

Hi,
I'm not sure this counts as an issue, but I wanted to confirm if this approach/results are valid.

I have run a sensitivity analysis on the Wofost72_WLP_FD model using the SAlib python implementation of the Sobol variance decomposition technique. I’ve run something similar over APSIMx previously.

I did this for block sizes 100, 200, 300, 500 and 1000 equating to between 5400 and 54,000 model simulations. I ran the analysis for end season production (‘TWSO’ or yield) as well as in season plant characteristics (LAI and SM on 5 dates). I want to use this analysis both for identifying parameters to calibrate/fix as well as for use in a modelling application. I’ll write the analysis up for journal publication eventually (and include yourself as co-author if you’re interested), however, right now I just would like a sanity check as to whether these results are reasonable.

Attached are plots showing the main and total effects (left hand axes) and interaction effects (right hand axes) for each parameter for each block size. I’m a little surprised by the results, however, the general pattern is consistent across the block sizes and the confidence intervals (not shown) reduce as expected over increased simulation runs (highest is 0.1). I’m particularly interested in why Specific Pod Area (SPA) is so influential for yield. I thought this was used as ancillary photosynthetic assimilate production alongside LAI?

The parameter ranges and the associated site description and weather files used to run these simulations are also attached.

WOFOST72_Sobol_plots.zip
Parameter_and_forcings.zip

Let me know what you think, are these sensitivity indices reasonable?

Best,
Ian

Unexpected behavior of "maturity" in agromanagement class

This is either a bug/missing feature, or a documentation issue, or neither.

The class AgroManagementSingleCrop in agromanagement.py takes the parameter CROP_END_TYPE:

"""
    CROP_END_TYPE    String representing end type: 'harvest'|       STi     -
                     'maturity'|'earliest'
"""

I would expect that choosing CROP_END_TYPE = "maturity" would terminate the simulation once the crop is mature. However, as far as I can tell the simulation never terminates in this case .

input data arguments for WOFOST could be made extensible

Just a thought, maybe parameterprovider, weatherdataprovider, agromanagement is an exhaustive list of input data. Maybe not. Having a data structure which can be easily extended like a dictionary as the argument would be easy to extend.

Say:
input_data = {
'crop_params' : parameterprovider,
'meteo' : weatherdataprovider,
'agro' : agromanagement,
...
}

Similar for ParameterProvider
ParameterProvider(soildata=soil, cropdata=crop, sitedata=site)

TypeError - Wofost80_NWLP_FD_beta

Hi,

First of all, a huge thank you for the excellent documentation and example notebooks. I've used a bunch of different crop models and this is by far the most logically organised intro and layout I've seen. And the choice of using Python was enlightened, though I'm probably biased on this point.

Onto the issue ... I'm testing out WOFOST and have run into an error. I'd like to use this in nutrient and water limited scenarios so I've been trying out Wofost80 (although I realise this is a beta). I first encountered a KeyError: 'DVS' from the original pip installed version, which I fixed by installing the 'develop' branch, however, now I'm getting a TypeError.

My code amended from your User Guide is below and the (jury rigged) files are attached.

Wofost80_test.zip

as per PCSE User Guide on using 'custom input data'

import pcse
from pcse.fileinput import CABOFileReader,YAMLAgroManagementReader
from pcse.util import WOFOST80SiteDataProvider
from pcse.base import ParameterProvider
from pcse.db import NASAPowerWeatherDataProvider
from pcse.models import Wofost80_NWLP_FD_beta

data_dir = r'~\Documents\PCSE_test_data'

crop params - modified from sugarbeet example with wheat params

cropfile = os.path.join(data_dir, 'wheat_manualUpdate.crop')
cropdataTest = CABOFileReader(cropfile)
#print(cropdata)

soil - params unchanged from ec3

soilfile = os.path.join(data_dir, 'Trangie.soil')
soildataTest = CABOFileReader(soilfile)

site data - defaults with CO2 update

CO2 concentration from http://www.bom.gov.au/state-of-the-climate/greenhouse-gas-levels.shtml#:~:text=The%20annual%20average%20CO2,of%20278%20ppm%20in%201750.

sitedataTest = WOFOST80SiteDataProvider(WAV=90, CO2=400)

pack parameters together

parametersTest = ParameterProvider(cropdata=cropdataTest, soildata=soildataTest, sitedata=sitedataTest)

agromanagement - updated for 2022

agromanagement_file = os.path.join(data_dir, 'wheat_manualUpdate_calendar.agro')
agromanagementTest = YAMLAgroManagementReader(agromanagement_file)

weather

wdp = NASAPowerWeatherDataProvider(latitude=-32, longitude=148)

test single run

wofsim = Wofost80_NWLP_FD_beta(parametersTest, wdp, agromanagementTest)
wofsim.run_till_terminate()

And the error was:

TypeError Traceback (most recent call last)
Input In [7], in <cell line: 36>()
34 # test single run
35 wofsim = Wofost80_NWLP_FD_beta(parametersTest, wdp, agromanagementTest)
---> 36 wofsim.run_till_terminate()
37 output = wofsim.get_output()
38 output

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:228, in Engine.run_till_terminate(self)
225 """Runs the system until a terminate signal is sent."""
227 while self.flag_terminate is False:
--> 228 self._run()

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:202, in Engine._run(self)
199 self.day, delt = self.timer()
201 # State integration
--> 202 self.integrate(self.day, delt)
204 # Driving variables
205 self.drv = self._get_driving_variables(self.day)

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:185, in Engine.integrate(self, day, delt)
182 self.crop.integrate(day, delt)
184 if self.soil is not None:
--> 185 self.soil.integrate(day, delt)
187 # Set all rate variables to zero
188 if settings.ZEROFY:

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\soil\soil_wrappers.py:86, in SoilModuleWrapper_NPK_WLP_FD.integrate(self, day, delt)
84 def integrate(self, day, delt=1.0):
85 self.WaterbalanceFD.integrate(day, delt)
---> 86 self.NPK_Soil_Dynamics.integrate(day, delt)

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\decorators.py:39, in descript.make_bound..wrapper(*args, **kwargs)
37 if attr is not None:
38 attr.unlock()
---> 39 ret = self.f(instance, *args, **kwargs)
40 attr = getattr(instance, self.lockattr)
41 if attr is not None:

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\soil\npk_soil_dynamics.py:247, in NPK_Soil_Dynamics.integrate(self, day, delt)
244 states.KSOIL += rates.RKSOIL * delt
246 # total (soil + fertilizer) NPK amount in soil
--> 247 states.NAVAIL += rates.RNAVAIL * delt
248 states.PAVAIL += rates.RPAVAIL * delt
249 states.KAVAIL += rates.RKAVAIL * delt

TypeError: unsupported operand type(s) for +=: 'NoneType' and 'float'

Any advice? I'll give the Wofost72 a try model but am very interested in simulating the nutrient poor and moisture deficient soils of most Australian cropping regions so the newer model is better for me.

Thanks
Ian

I have an error raised while using CSVWeatherDataProvider

The error shows "KeyError: 'Country' ",I think the error is caused by head of my csv file,and here is the head:

## Daily weather observations
Weather data for:
Country:China
Station:miss_value=8days
Description:['NASA/POWER SRB/FLASHFlux/MERRA2/GEOS 5.12.4 (FP-IT) 0.5 x 0.5 Degree Daily Averaged Data']
Source:Meteorology and Air Quality Group, Wageningen University
Contact:Peter Uithol
Missing values:-999
Longitude	Latitude	Elevation	AngstromA	AngstromB	HasSunshine
112.21	34.4	445.32	0.117233588	0.614910625	FALSE
Observed data

Could you think out a solution,please?

In one wofost model, the'apply_npk' event and the 'irrigate' event do not work.

I'm trying to modify agromanagement file for wofost model and change apply_npk values and irrigation like this:

agro = '''
- 1988-01-01:
    CropCalendar:
        crop_name: wheat
        variety_name: winter-wheat
        crop_start_date: 1988-01-01
        crop_start_type: emergence
        crop_end_date:
        crop_end_type: maturity
        max_duration: 300
    TimedEvents:
    -   event_signal: irrigate
        name: Irrigation application table
        comment: All irrigation amounts in cm
        events_table:
        - 1988-03-05: {amount: 10, efficiency: 0.7}
        - 1988-03-20: {amount: 10, efficiency: 0.7}
        - 1988-04-01: {amount: 10, efficiency: 0.7}
        - 1988-04-10: {amount: 10, efficiency: 0.7}
        - 1988-05-10: {amount: 10, efficiency: 0.7}
    -   event_signal: apply_npk
        name:  Timed N/P/K application table
        comment: All fertilizer amounts in kg/ha
        events_table:
        - 1988-04-29: {N_amount: 0., P_amount: 40., K_amount: 20., N_recovery: 0.7, P_recovery: 0.7, K_recovery: 0.7}
        - 1988-06-16: {N_amount: 0., P_amount: 10., K_amount: 20., N_recovery: 0.7, P_recovery: 0.7, K_recovery: 0.7}
    StateEvents: null
'''
agro = yaml.safe_load(agro)

Wofost71_WLP_FD doesn't respond to apply_NPK events. (only respond to irrigate events)

Howerver, when i use wofost = Engine(params, weather, agro, config="Wofost71_NPK.conf"), it doesn't respond to irrigate events, but respond to apply_NPK events

Wofost71_PP model doesn't react to both events.

my question is, is there a wofost model that responds to both events? Or is it not implemented yet? Or is it a bug?

'IRRAD' outside allowed range

We are importing weather data with the CSVWeatherDataProvider for a site in Kenya. When running the simulation, we get the following error though: Value (459694000.0) for meteo variable 'IRRAD' outside allowed range (0.0, 40000000.0).

Based on this documentation we assume that the data we have to input is in kJ/m^2/day. Wofost then seems to convert internally from kJ to J.

So it seems that Wofost has a maximum limit of 40,000,000 J/m^2/day. In the tropics, the average radiation is 432,000,000 J/m^2/day which is ten times the upper limit of the Wofost71_WLP_FD model.

Is it possible to increase the limit, or does that have effects on other model components?
Or does the problem lie somewhere else?

VariableKiosk doesn't allow serialisation

Hello :)

The issue

I'm attempting to run multiple instances of PCSE models in parallel with the pathos library (an extension of the multiprocessing library) . In each process I initialise a model, pass in some data, and run the model to completion, eventually returning the model object with associated terminal stats, etc. However, I think I'm running into issues with the unpickling of the model objects when attempting to retrieve them from the processing pool.

As far as I can tell, the cause of the problem is the following:

When attempting to unpickle VariableKiosk, we encounter RuntimeError: See set_variable() for setting a variable. - Presumably the intention here is to only allow modification of the VariableKiosk object through the set_variable method, rather than allowing users to directly access VariableKiosk as a dict. However, when a VariableKiosk object is being deserialised, presumably its reconstruction is performed by accessing as a dictionary (since VariableKiosk inherits directly from dict), and we see the above error.

The proposed fix

My fix to this so far has been to modify the VariableKiosk class as follows:

  • Modify __getstate__ to raise an AttributeError rather than a KeyError. This stops the (de)serialisation from raising the error MaybeEncodingError: Error sending result: [...]. Reason: 'KeyError('__getstate__'):
    def __getattr__(self, item):
        """Allow use of attribute notation (eg "kiosk.LAI") on published rates or states.
        """
        try:
            return dict.__getitem__(self, item)
        except KeyError:
            raise AttributeError
  • Add the following magic methods that are used to deconstruct and reconstruct the object for serialisation using the set_variable method as opposed to simply setting attributes as one would on a normal dict (these could probably do with a little tidying):
    def __reduce__(self):
       return (VariableKiosk, (), self.__getstate__())

    def __getstate__(self):
        published_state_values = {param_name: self[param_name]
                for param_name in self.published_states if self.get(param_name, 'N/A') is not 'N/A'}
        published_rate_values = {param_name: self[param_name]
                for param_name in self.published_rates if self.get(param_name, 'N/A') is not 'N/A'}
        return (self.registered_states, self.registered_rates, self.published_states,
                self.published_rates, published_state_values, published_rate_values)

    def __setstate__(self, state):
        (registered_states, registered_rates, published_states,
         published_rates, published_state_values, published_rate_values) = state

        for varname, oid in registered_states.items():
            if varname not in published_states:
                self.register_variable(oid, varname, 'S')
        for varname, oid in registered_rates.items():
            if varname not in published_rates:
                self.register_variable(oid, varname, 'R')
        for varname, oid in published_states.items():
            self.register_variable(oid, varname, 'S', publish=True)
        for varname, oid in published_rates.items():
            self.register_variable(oid, varname, 'R', publish=True)

        for varname, value in published_rate_values.items():
            oid = self.published_rates[varname]
            self.set_variable(oid, varname, value)
        for varname, value in published_state_values.items():
            oid = self.published_states[varname]
            self.set_variable(oid, varname, value)

Does this seem like a reasonable diagnosis of the problem here, and does the proposed fix respect the design intentions of VariableKiosk? If so, I would be happy to tidy up the code and contribute to fix the issue.

Many thanks,
Lukas

"set_variable" function invalid for wofost8 version models

When I was following the "pcse_notebooks-master" to test the data assimilation algorithm using the wofost8 crop model, I found that the "set_variable" function was invalid for it. Further tests show that all crop models of wofost8 version have this problem.

NASAPowerWeatherProvider key error 'header'

weatherdata = NASAPowerWeatherDataProvider(longitude=5, latitude=52)
print(weatherdata)
produces:

KeyError Traceback (most recent call last)
in
----> 1 weatherdata = NASAPowerWeatherDataProvider(longitude=5, latitude=52)
2 print(weatherdata)

~\AppData\Local\Continuum\anaconda3\envs\py3_pcse\lib\site-packages\pcse\db\nasapower.py in init(self, latitude, longitude, force_update, ETmodel)
96 self.logger.debug(msg)
97 # No cache file, we really have to get the data from the NASA server
---> 98 self._get_and_process_NASAPower(self.latitude, self.longitude)
99 return
100

~\AppData\Local\Continuum\anaconda3\envs\py3_pcse\lib\site-packages\pcse\db\nasapower.py in _get_and_process_NASAPower(self, latitude, longitude)
139
140 # Store the informational header then parse variables
--> 141 self.description = [powerdata["header"]["title"]]
142 self.elevation = float(powerdata["features"][0]["geometry"]["coordinates"][2])
143 df_power = self._process_POWER_records(powerdata)

KeyError: 'header'

Python 3 issue

Hello everyone,

I am trying to install the PCSE in a python 3 virtual environment but I have no success. I am using python 3.5.2

image

Apparently, you should import _pickle instead cPickle when the environment is python 3.

Thank you all

possibilities to define a time frame

Dear @ajwdewit
wonder if it is possible to define a start and end date for retrieving NASA power climate data. The current NASAPowerWeatherDataProvider seems only accept coordinates and download all available data from the portal.

def __init__(self, latitude, longitude, force_update=False, ETmodel="PM"):

thank you

Bug in YAMLCropDataProvider.pkl

Dear Allard,

When I use the WOFOST_crop_parameters-master, the YAMLCropDataProvider will use the .pkl cache first if there is YAMLCropDataProvider.pkl in the folder and raise an exception as follows:

image

The exception doesn't affect the program, but sometimes annoys me if I use multiprocessing to run PCSE like this:

image

I've tried to delete the YAMLCropDataProvider.pkl, but it works only once and then raises the exception as usual

My PCSE version is 5.5.3, hpping you can fix this issue.Thanks a lot!

Incorrect parameters for start_wofost

After running wofost_object = pcse.start_wofost(grid=31031, crop=1, year=2000, mode='wlp') on the latest develop version I get the following error:

C:\Users\gausie\Anaconda\lib\site-packages\pcse-5.0.0-py2.7.egg\pcse\start_wofost.pyc in start_wofost(grid, crop, year, mode, dsn)
     71         wofsim = Wofost71_PP(parvalues, meteof)
     72     elif mode == 'wlp':
---> 73         wofsim = Wofost71_WLP_FD(parvalues, meteof)
     74     else:
     75         msg = "Unrecognized mode keyword: '%s' should be one of 'pp'|'wlp'" % mode

TypeError: __init__() takes exactly 6 arguments (3 given)

Seems that there's a mismatch in number of args in that file

FAO_WRSI_WaterLimited error

Hi

I am trying to run the FAO_WRSI model but I keep getting the following error below. What am I doing wrong. When I run the WOFOST model, there is no problem.
My code for the model call and the error are below.

agromanagement = yaml.load(agro.format(year=year, year2=year2))
wofsim = FAO_WRSI_WaterLimited(parameters, wdp, agromanagement)
wofsim.run_till_terminate()
df_results = pd.DataFrame(wofsim.get_output())

pcse error

Compatibility issue with python 3.10

I recently updated my python to 3.10 and after installing pcse with pip install pcse couldn't import.

The error is: "cannot import name 'Iterable' from 'collections'"

I looked up for the error up and found (link to SO post) Iterable from collections was deprecated and that one should use collections.abc.

Does it make sense?

Cheers,

Including the effect of changes in atmospheric CO2 concentration

Hello, I'm trying to use PCSE/WOFOST to simulate climate change impacts on potatoes and include the effect of changes in atmospheric CO2 concentration on assimilation and transpiration.

To do this, instead of changing AMAXTB, EFFTB, and transpiration-related parameters in input files, I made changes in "pcse\crop\wofost.py" as below and set CO2 values using WOFOST71SiteDataProvider:

From :
from .assimilation import WOFOST_Assimilation as Assimilation
from .evapotranspiration import Evapotranspiration

To :
from .assimilation import WOFOST_Assimilation2 as Assimilation
from .evapotranspiration import EvapotranspirationCO2 as Evapotranspiration

Is it the right way? Or are there any other ways to include the CO2 effect?

Thank you in advance!

regards,

Yean-Uk

KeyError: 'DVS' with WOFOST8?

Dear all,

I am learning to use PCSE and WOFOST8. I used the pcse_notebooks. When I replaced the WOFOST7 with WOFOST8 (Wofost80_NWLP_FD_beta, WOFOST80SiteDataProvider) in the #7 notebook, 'Running crop rotations', I got an error:

KeyError: 'DVS'

It seems that, when using WOFOST8, 'DVS' is not registered during the initialization stage. Since 'DVS' is used in the NPK soil module of WOFOST8, it raised this error. Do you have any idea how to deal with it?

Best,
Han

Missing files

The repository seems to only contain a README and a LICENSE file. Is this intended?

yaml safe load

Hi and thanks for the great package!
I have been having a warning for a long time now, even though it doesn't result in any problem in simulations :

#For : \pcse\fileinput\yaml_agro_loader.py:21
YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.

Replacing yaml.load() to yaml.safe_load() might to the trick if I am not mistaken.

NASAPower Error

Hi

Thank you for the great model and detailed tutorial. When going through the tutorial I fail when trying to access NASAPower data although the NASA seems to work properly. There seems to be an issue with the nasapower.py script. That is what I get as error.

wdp = NASAPowerWeatherDataProvider(latitude=10, longitude=10)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Mohgli\Anaconda3\envs\py2_pcse\lib\site-packages\pcse\db\nasapower.py", line 105, in init
self._get_and_process_NASAPower(self.latitude, self.longitude)
File "C:\Users\Mlohgli\Anaconda3\envs\py2_pcse\lib\site-packages\pcse\db\nasapower.py", line 144, in _get_and_process_NASAPower
self.description = self._parse_header(powerdata)
File "C:\Users\Mohgli\Anaconda3\envs\py2_pcse\lib\site-packages\pcse\db\nasapower.py", line 323, in _parse_header
header.append(powerdata[20])
IndexError: list index out of range

Apreciate your help on this. Thanks

Running quick_demo2.py

Hello,

First of all, thank you for providing this great crop model. I am trying to run your demonstration tutorial but failed in the second demo. I adjusted the data_dir properly but this error comes.

[bs:~/Desktop]$ python quickstart_demo2.py
Traceback (most recent call last):
File "quickstart_demo2.py", line 25, in
wdp = NASAPowerWeatherDataProvider(latitude=52, longitude=5)
File "/usr/local/lib/python2.7/site-packages/pcse/db/nasapower.py", line 105, in init
self._get_and_process_NASAPower(self.latitude, self.longitude)
File "/usr/local/lib/python2.7/site-packages/pcse/db/nasapower.py", line 145, in _get_and_process_NASAPower
self.elevation = self._parse_elevation(powerdata)
File "/usr/local/lib/python2.7/site-packages/pcse/db/nasapower.py", line 318, in _parse_elevation
elev = int(line.split(b"=")[-1])
ValueError: invalid literal for int() with base 10: 'n/a\n'

Probably something is wrong with NASAPowerWeatherDataProvider. Just to let you know the pcse.test() method worked properly.

Thank you

apply_npk event does not work

I'm trying to modify agromanagement file for lintul3 model and change apply_npk values like this:
StateEvents:
- event_signal: apply_npk
event_state: DVS
zero_condition: rising
name: DVS-based N/P/K application table
comment: all fertilizer amounts in kg/ha
events_table:
- 0.3: {N_amount : 1, P_amount: 3, K_amount: 4}
- 0.6: {N_amount: 11, P_amount: 13, K_amount: 14}
- 1.12: {N_amount: 21, P_amount: 23, K_amount: 24}
=>
StateEvents:
- event_signal: apply_npk
event_state: DVS
zero_condition: rising
name: DVS-based N/P/K application table
comment: all fertilizer amounts in kg/ha
events_table:
- 0.3: {N_amount : 1, P_amount: 1, K_amount: 1}
- 0.6: {N_amount: 4, P_amount: 4, K_amount: 4}
- 1.12: {N_amount: 10, P_amount: 10, K_amount: 10}

I think WSO should be reduced in this case, but it didn't happen.
Also WSO doesn't changes if we increase N_amount, P_amount and K_amount.

Question is should WSO increase or decrease? Or it is a bug?

ExcelWeatherDataProvider: ValueError: need more than 5 values to unpack

Looking at the example for reading weather data on the develop branch, it keeps throwing this error. Everything else seems to be working fine.

from pcse.fileinput import ExcelWeatherDataProvider
weather = ExcelWeatherDataProvider("/Users/michael/Github/wheatsim/data/nl1.xlsx")
Warning: You are running a PCSE development version:  5.0.0
Traceback (most recent call last):
  File "wheat.py", line 12, in <module>
    weather = ExcelWeatherDataProvider("/Users/michael/Github/wheatsim/data/nl1.xlsx")
  File "/usr/local/lib/python2.7/site-packages/PCSE-5.0.0-py2.7.egg/pcse/fileinput/xlsweatherdataprovider.py", line 88, in __init__
    if not self._load_cache_file(self.fp_xls_fname):  # Cache file cannot be loaded
  File "/usr/local/lib/python2.7/site-packages/PCSE-5.0.0-py2.7.egg/pcse/fileinput/xlsweatherdataprovider.py", line 184, in _load_cache_file
    self._load(cache_filename)
  File "/usr/local/lib/python2.7/site-packages/PCSE-5.0.0-py2.7.egg/pcse/base_classes.py", line 1228, in _load
    (store, self.elevation, self.longitude, self.latitude, self.description, ETModel) = cPickle.load(fp)
ValueError: need more than 5 values to unpack

How can I calculate site parameters when using Wofost80_NWLP_FD_beta

As a non-native speaker, I am having difficulty understanding some of the technical terminology and would appreciate your assistance.

My version of WOFOST is 5.5.4, and there are currently no documents available for learning WOFOST80. I am trying to simulate the effects of nitrogen stress on maize growth using this model, but I am having trouble inputting the required parameters. The parameters I am struggling with are NSOILBASE, NSOILBASE_FR, PSOILBASE, PSOILBASE_FR, KSOILBASE, KSOILBASE_FR, NAVAILI, PAVAILI, KAVAILI, BG_N_SUPPLY, BG_P_SUPPLY, and BG_K_SUPPLY.

My experimental data includes measurements of hydrolyzable nitrogen, available phosphorus, available potassium, pH, total nitrogen, soil bulk density, porosity, field water capacity, saturated water content, and the percentages of sand, silt, and clay particles. I would like to know how to calculate the input values for the parameters mentioned above based on this data.

Additionally, I have a few specific questions regarding the parameters. Firstly, I would like to know what NAVAILI refers to. Does it refer to the hydrolyzable nitrogen content at the time of sowing? Secondly, does NSOILBASE refer to the total nitrogen content of the soil minus the hydrolyzable nitrogen content? Lastly, how should I determine the value of NSOILBASE_FR?

NASA POWER API needs updates

https://power.larc.nasa.gov/

The Prediction Of Worldwide Energy Resources (POWER) Project has transitioned hosting environments and released POWER Web Services Portal Version 2 on August 10, 2021. For users of the custom POWER Application Programming Interface (API), there have been substantial improvements in the responsiveness, usability, and standard compliance of the API endpoints. As a reminder, your current API commands will require updates to conform to the some of the new parameter names and formats.

Currently, PCSE raises error below when using NASAPowerWeatherDataProvider

on terminal:
pcse.exceptions.PCSEError: Failed retrieving POWER data, server returned HTTP code: 422 on following URL
on URL:
{"header":"The POWER Legacy API failed to complete your request; please review the errors below and the POWER Docs (https://power.larc.nasa.gov/docs).","messages":["The version one API V2 structure has been deprecated please use the POWER API V2 structure.","The version one API V2 structure has been deprecated please use the POWER API V2 structure.","The version one API V2 structure has been deprecated please use the POWER API V2 structure."]}

I think NASA POWER API needs updates.

weather data from NASA provider error

Dear,

I am using pcse version '5.4.2' from a jupyter lab environment.
I am following the user guide but when I try to read the weather observations with nasa provides I get this error:

PCSEError: Failed retrieving POWER data, server returned HTTP code: 422 on following URL https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?request=execute&identifier=SinglePoint&parameters=ALLSKY_TOA_SW_DWN%2CALLSKY_SFC_SW_DWN%2CT2M%2CT2M_MIN%2CT2M_MAX%2CT2MDEW%2CWS2M%2CPRECTOT&lat=52.0&lon=5.0&startDate=19830701&endDate=20210921&userCommunity=AG&tempAverage=DAILY&outputList=JSON&user=anonymous

In that link the message is: {"header":"The POWER Legacy API failed to complete your request; please review the errors below and the POWER Docs (https://power.larc.nasa.gov/docs).","messages":["The version one API V2 structure has been deprecated please use the POWER API V2 structure.","The version one API V2 structure has been deprecated please use the POWER API V2 structure.","The version one API V2 structure has been deprecated please use the POWER API V2 structure."]}

The API overview from NASA says: Changes from v1 to v2, No longer able to request multiple file types in a single API request, where previously a link was provided in the outputs section of the JSON response. The API now streams the requested file type directly as a response object.

it is possible to fix that?
Any help would be appreciated,
Thanks in advance.
emiliano

Optimal crops rotation

I want to thank you for creating such a wonderful library!
I have a question: Is it possible to calculate a list of optimal crop predecessors using your library?

Best regards, Anton Petrov
Kuban State Agrarian University

bugs using sunshinehours

d[label] = angstrom(d["DAY"], self.latitude, value, self.angstA, self.angstB)
to #L156

This line should be changed to
value = angstrom(d["DAY"], self.latitude, value, self.angstA, self.angstB)/1000

Beacuse when using sunshinehours , d[label] = func(value, sheet) 's result is equal Tto (value * 1000), the result is sunshinehours multiplyed 1000, but not RAD , so I think the code should chenged like above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.