mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
add meteoinfo-jython module
This commit is contained in:
parent
fd628959f3
commit
03863054b3
33
meteoinfo-jython/pom.xml
Normal file
33
meteoinfo-jython/pom.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.meteothink</groupId>
|
||||
<artifactId>MeteoInfo</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>meteoinfo-jython</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>meteoinfo-ndarray</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.python</groupId>
|
||||
<artifactId>jython-standalone</artifactId>
|
||||
<version>2.7.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,67 @@
|
||||
package org.meteoinfo.jython;
|
||||
|
||||
import org.meteoinfo.ndarray.Array;
|
||||
import org.meteoinfo.ndarray.Complex;
|
||||
import org.meteoinfo.ndarray.DataType;
|
||||
import org.meteoinfo.ndarray.IndexIterator;
|
||||
import org.python.core.PyComplex;
|
||||
import org.python.core.PyObject;
|
||||
import org.python.modules.time.PyTimeTuple;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
public class JythonUtil {
|
||||
|
||||
/**
|
||||
* Convert PyComplex value to ArrayComplex
|
||||
* @param data PyComplex value
|
||||
* @return ArrayComplex
|
||||
*/
|
||||
public static Array toComplexArray(PyComplex data) {
|
||||
Array a = Array.factory(DataType.COMPLEX, new int[]{1});
|
||||
Complex d = new Complex(data.real, data.imag);
|
||||
a.setComplex(0, d);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PyComplex list to ArrayComplex
|
||||
* @param data PyComplex list
|
||||
* @return ArrayComplex
|
||||
*/
|
||||
public static Array toComplexArray(List<Object> data) {
|
||||
if (data.get(0) instanceof List) {
|
||||
int ndim = data.size();
|
||||
int len = ((List) data.get(0)).size();
|
||||
Array a = Array.factory(DataType.COMPLEX, new int[]{ndim, len});
|
||||
PyComplex pd;
|
||||
for (int i = 0; i < ndim; i++) {
|
||||
List<Object> d = (List) data.get(i);
|
||||
for (int j = 0; j < len; j++) {
|
||||
if (d.get(j) instanceof PyComplex) {
|
||||
pd = (PyComplex) d.get(j);
|
||||
a.setComplex(i * len + j, new Complex(pd.real, pd.imag));
|
||||
} else {
|
||||
a.setComplex(i * len + j, new Complex((double) d.get(j), 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
} else {
|
||||
Array a = Array.factory(DataType.COMPLEX, new int[]{data.size()});
|
||||
PyComplex pd;
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (data.get(i) instanceof PyComplex) {
|
||||
pd = (PyComplex) data.get(i);
|
||||
a.setComplex(i, new Complex(pd.real, pd.imag));
|
||||
} else {
|
||||
a.setComplex(i, new Complex((double) data.get(i), 0));
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user