aquacropos / aquacrop

AquaCrop-OSPy: Python implementation of AquaCrop-OS
https://aquacropos.github.io/aquacrop/
Apache License 2.0
102 stars 73 forks source link

time to import package #11

Closed AlexandreCandidoXavier closed 3 years ago

AlexandreCandidoXavier commented 3 years ago

Congratulation for the afford to do the Aquacrop available in Python. I am try to use it and I have two questions:

1) Why it take too long time to import aquacrop:

import time

start = time.time()
import aquacrop
print(time.time() - start)

It is taken ~33 s in my computer. I am using the IDE Pycharm Community, but it is the first time I have this issue.

2) When I run the code:


import matplotlib.pyplot as plt
import time
# from aquacrop.classes import *
# from aquacrop.core import *

start = time.time()
import aquacrop
print(time.time() - start)

filepath = './Weather.txt'

weather_data = aquacrop.prepare_weather(filepath)
weather_data

sandy_loam = aquacrop.SoilClass(soilType='SandyLoam')
wheat = aquacrop.CropClass('Wheat', PlantingDate='09/01')

InitWC = aquacrop.InitWCClass(value=['FC'])
model = aquacrop.AquaCropModel(SimStartTime=f'{1980}/01/01',
                      SimEndTime=f'{2123}/12/30',
                      wdf=weather_data,
                      Soil=sandy_loam,
                      Crop=wheat,
                      InitWC=InitWC)

# initilize model
start = time.time()
model.initialize()
# run model till termination
model.step(till_termination=True)
print(time.time() - start)
model.Outputs.Final.head() # this is not working 

In the Python console, whatever I do in the prompt line (ex: >>> 1+1) it will return the result and some garbage, as bellow:

>>> 1+1
2
Name: SandyLoam
zSoil: 1.6
nComp: 12
nLayer: 1
AdjREW: 1
REW: 7
CalcCN: 0
CN: 46
zRes: -999
EvapZsurf: 0.04
EvapZmin: 0.15
EvapZmax: 0.3
Kex: 1.1
fevap: 4
fWrelExp: 0.4
fwcc: 50
zCN: 0.3
zGerm: 0.3
AdjCN: 1
fshape_cr: 16
zTop: 0.1
Hydrology:        Comp  zBot  zTop  zMid  ...  penetrability  tau  th_fc_Adj   dz
Layer                          ...                                    
1       5.5  0.65  0.55   0.6  ...          100.0  1.0       0.22  1.6
[1 rows x 13 columns]
Profile: <numba.experimental.jitclass.boxing.SoilProfileClass object at 0x7f665dbfb340>

Thanks.

Paloschi commented 3 years ago

Hi Alexandre

Seems that I found the "issue",

look at the file init, you will see that the lib is running an simulation!

WhatsApp Image 2021-08-31 at 15 55 10

That's why the import is taking so long kkk

I guess you can just comment this code and it's done.

Cheers

thomasdkelly commented 3 years ago

Hi as @Paloschi said, the init.py file runs a simulation as the model is loaded in. This discussion outlines the reasons why: https://github.com/thomasdkelly/aquacrop/discussions/8#discussioncomment-938418

Ultimately i though it would be cleaner to have the jit compilation take place as the module is imported rather than when the user runs their first simulation. This avoids them thinking the simulations themselves are slow or the code is broken.

Thanks Tom

AlexandreCandidoXavier commented 3 years ago

Thank you!