GeoStat-Framework / PyKrige

Kriging Toolkit for Python
https://pykrige.readthedocs.io
BSD 3-Clause "New" or "Revised" License
740 stars 186 forks source link

AttributeError: 'UniversalKriging' object has no attribute 'external_Z_array' #235

Closed cerodell closed 1 year ago

cerodell commented 1 year ago

Hello! I am trying to krig with external drift. I am using the following setup.

startTime = datetime.now()
krig_uk_dem =UniversalKriging(
    x=df["Easting"],   ## x location of aq monitors in lambert conformal
    y=df["Northing"], ## y location of aq monitors in lambert conformal
    z=df["PM2.5"],     ## measured PM 2.5 concentrations at locations
    drift_terms=['external_Z','specified'],
    external_drift=dem_ds.data.values[0,:,:].T, ## 2d array of dem used for external drift
    external_drift_x=gridx,  ## x coordinates of 2d dem data file in lambert conformal
    external_drift_y=gridy,  ## y coordinates of 2d dem data file in lambert conformal
    specified_drift=df["dem"]       ## elevation of aq monitors 
)
print(f"UK build time {datetime.now() - startTime}")

I thought this was the correct way to set up to krig with external drift, but I received the following error.

AttributeError: 'UniversalKriging' object has no attribute 'external_Z_array'

Im currently using pykrig version 1.6.1

I'm not sure what I'm doing wrong. Any help is greatly appreciated :)

PS I also posted this here but thought I should open a new issue. https://github.com/GeoStat-Framework/PyKrige/issues/155#issue-623903614

cerodell commented 1 year ago

I found the source of the issue. On line 419 in uk.py self.external_Z_drift = np.array(external_drift.T) is incorrectly defined. it should be self. external_Z_array = np.array(external_drift.T) and it works.

Or I just need to transpose my external_drift array prior.

MuellerSeb commented 1 year ago

Hi there! Thanks for this bug report. It will be fixed in the next release.

Cheers, Sebastian