[Thread Prev][Thread Next][Index]

[ferret_users] Python externat function with several arguments with different shapes.



Hello everybody,

I'm trying to build a python external function (PyEF). It should build an histogram from a list of classes. So the input arguments will be a Ferret array, and a list of classes. With a call like :

histo(  SIICECOV[L=1,K=1])         , XSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
or
histo( XSEQUENCE(SIICECOV[L=1,K=1]), XSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
or
histo( XSEQUENCE(SIICECOV[L=1,K=1]), YSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )

But it always fails. For instance :

> STAT histo( XSEQUENCE(SIICECOV[L=1,K=1]), XSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
 **ERROR: inconsistent sizes of data regions: X axis
          XSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) has 5 points (I=1:5)
          expression has 9216 points (I=0001:9216)
STAT histo( XSEQUENCE(SIICECOV[L=1,K=1]), XSEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
Command file, command group, or REPEAT execution aborted


or 

> STAT histo( XSEQUENCE(SIICECOV[L=1,K=1]), XYEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
 **ERROR: command syntax: XYEQUENCE({0., 0.1, 0.2, 1.0, 2.0})
          unknown function "XYEQUENCE"
STAT histo( XSEQUENCE(SIICECOV[L=1,K=1]), XYEQUENCE({0., 0.1, 0.2, 1.0, 2.0}) )
Command file, command group, or REPEAT execution aborted




Before performing any computation, I cannot find a way to write an external function that accept two arguments with different shapes. Any hint or exemple ?

Thanks,

Olivier

The python function :

Example Ferret external function written in Python
'''
import numpy
import pyferret

def ferret_init(id):
    '''Creates and returns the initialization dictionary for this PyEF'''
    initdict = { "numargs" : 2, "descript": "Test function",
                 "argnames": ("A", "Histogram boundaries"),
                     }
    return initdict

def ferret_compute(id, result, result_bad_flag, inputs, input_bad_flags):
    ''' Essai d'histogramme
    ARG1 is the array. 
    ARG2 is the list of class boundaries
    '''

    badmask = ( numpy.fabs(inputs[pyferret.ARG1] - input_bad_flags[pyferret.ARG1]) < 1.0E-5 )
    goodmask = numpy.logical_not(badmask)

    result[badmask]  = input_bad_flags[pyferret.ARG1]
    result[goodmask] = inputs[pyferret.ARG1][goodmask]

— 
Olivier Marti  - LSCE Bât 714 p. 1049
Tel : +33 1 69 08 77 27
mailto:olivier.marti@xxxxxxxxxxxx


Attachment: smime.p7s
Description: S/MIME cryptographic signature


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement