Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master generic netcdf #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ opendaTestReports/
**/build-test
**/MANIFEST.MF
**/tests/*.log
**/*_temp_build/
**/castor_temp_src/
OpenDATimings_*.txt
Binary file modified core/java/resources/openDA/core_castor.jar
Binary file not shown.
Binary file modified core/java/resources/openDA/core_castor_schemas.zip
Binary file not shown.
Binary file modified core/java/resources/openDA/core_castor_src.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.openda.exchange;

import org.openda.exchange.dataobjects.GenericNetcdfDataObject;
import org.openda.interfaces.IExchangeItem;

public class GenericNetcdfArrayExchangeItem extends ExchangeItem implements IExchangeItem {

private final GenericNetcdfDataObject genericNetcdfDataObject;

public GenericNetcdfArrayExchangeItem(String exchangeItemId, GenericNetcdfDataObject genericNetcdfDataObject){
super(exchangeItemId);
this.genericNetcdfDataObject = genericNetcdfDataObject;
}

@Override
public ValueType getValuesType() {
throw new RuntimeException("org.openda.exchange.GenericNetcdfArrayExchangeItem.getValuesType not implemented yet");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Override
public Class getValueType() {
throw new RuntimeException("org.openda.exchange.GenericNetcdfArrayExchangeItem.getValueType not implemented yet");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Override
public Object getValues() {
throw new RuntimeException("org.openda.exchange.GenericNetcdfArrayExchangeItem.getValues not implemented yet");
}

@Override
public double[] getValuesAsDoubles() {
return this.genericNetcdfDataObject.getArrayExchangeItemValues(this.getId());
}

@Override
public void axpyOnValues(double alpha, double[] axpyValues) {
double[] values = getValuesAsDoubles();
for (int i = 0; i < values.length; i++) {
if (Double.isNaN(values[i])) {
System.out.println("OrgVal Nan at " + i);
}
values[i] += alpha * axpyValues[i];
if (Double.isNaN(values[i])) {
System.out.println("ModVal Nan at " + i);
}
}
setValuesAsDoubles(values);
}

@Override
public void multiplyValues(double[] multiplicationFactors) {
throw new RuntimeException("org.openda.exchange.GenericNetcdfArrayExchangeItem.multiplyValues not implemented yet");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Override
public void setValues(Object values) {
throw new RuntimeException("org.openda.exchange.GenericNetcdfArrayExchangeItem.setValues not implemented yet");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Override
public void setValuesAsDoubles(double[] values) {
this.genericNetcdfDataObject.setArrayExchangeItemValues(this.getId(), values);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.openda.exchange.dataobjects;

import org.openda.utils.DimensionIndex;

import java.util.HashMap;

public class GenericNetcdfArrayConfig {
private final String exchangeitemId;
private final String netcdf_variable_name;
private final HashMap<String, DimensionIndex> netcdf_dimension_var;

public GenericNetcdfArrayConfig(String id, String variable_name, HashMap<String, DimensionIndex> dimensions) {
exchangeitemId = id;
netcdf_variable_name = variable_name;
netcdf_dimension_var = dimensions;
}

public String getExchangeitemId(){
return exchangeitemId;
}

public String getNetcdfVariableName(){
return netcdf_variable_name;
}

public String[] getNetcdfDimensionVariables(){
return netcdf_dimension_var.keySet().toArray(new String[0]);
}

public DimensionIndex getDimensionIndex(String dimension_variable_id){
return netcdf_dimension_var.get(dimension_variable_id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openda.exchange.dataobjects;

import java.util.ArrayList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import java.util.HashMap;

public class GenericNetcdfConfig {

// ArrayList<GenericNetcdfTSConfig> tsConfigs = new ArrayList<>();
// ArrayList<GenericNetcdfArrayConfig> arrayConfigs = new ArrayList<>();

HashMap<String, GenericNetcdfTSConfig> tsConfigs = new HashMap<>();
HashMap<String, GenericNetcdfArrayConfig> arrayConfigs = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.openda.exchange.dataobjects;

import org.openda.core.io.castorgenerated.*;
import org.openda.utils.DimensionIndex;
import org.openda.utils.io.CastorUtils;

import java.io.File;
import java.util.HashMap;

public class GenericNetcdfConfigReader {

private GenericNetcdfConfig genericNetcdfConfig;

public GenericNetcdfConfigReader(File genericNetcdfConfigFile) {
TNC_dataObjectConfig tncDataObjectConfig = (TNC_dataObjectConfig) CastorUtils.parse(genericNetcdfConfigFile, TNC_dataObjectConfig.class);
genericNetcdfConfig = parseGenericNetcdfConfig(genericNetcdfConfigFile, tncDataObjectConfig);
}

public GenericNetcdfConfig getGenericNetcdfConfig() {
return genericNetcdfConfig;
}

public static GenericNetcdfConfig parseGenericNetcdfConfig(File genericNetcdfConfigFile, TNC_dataObjectConfig tncDataObjectConfig) {

GenericNetcdfConfig netcdfConfig = new GenericNetcdfConfig();

org.openda.core.io.castorgenerated.TNC_arrayExchangeItem[] arrayExchangeItemsXML = tncDataObjectConfig.getArrayExchangeItem();
for (org.openda.core.io.castorgenerated.TNC_arrayExchangeItem arrayExchangeItemXML: arrayExchangeItemsXML) {
String id = arrayExchangeItemXML.getId().getContent();
String variable_name = arrayExchangeItemXML.getValues().getSelection().getVariable()[0].getName(); // only 1 variable is possible for array exchange item
int nDimension = arrayExchangeItemXML.getValues().getSelection().getVariable()[0].getDimensionCount();
HashMap<String, DimensionIndex> dimensions = new HashMap<>();
if (nDimension>0){
dimensions = new HashMap<>();
for (int i=0; i<nDimension; i++){
String dimension_name = arrayExchangeItemXML.getValues().getSelection().getVariable()[0].getDimension(i).getName();
String dimension_index_string = arrayExchangeItemXML.getValues().getSelection().getVariable()[0].getDimension(i).getIndex();
DimensionIndex dimension_index = new DimensionIndex(dimension_index_string,0); //TODO: check if it is okay to assume that dimensionBase is always 0
dimensions.put(dimension_name,dimension_index);
}
}
GenericNetcdfArrayConfig arrayConfig = new GenericNetcdfArrayConfig(id,variable_name,dimensions);
netcdfConfig.arrayConfigs.put(id,arrayConfig);
}

TNC_timeSeriesExchangeItem[] timeseriesExchangeItemsXML = tncDataObjectConfig.getTimeSeriesExchangeItem();
for (TNC_timeSeriesExchangeItem timeseriesExchangeItemXML: timeseriesExchangeItemsXML) {
TNC_id tnc_id = timeseriesExchangeItemXML.getId();
String template = tnc_id.getTemplate();
String id = null;
if (template == null) {
id = timeseriesExchangeItemXML.getId().getContent();
}
GenericNetcdfTSConfig tsConfig = new GenericNetcdfTSConfig(id,template,timeseriesExchangeItemXML);
if (id==null){
netcdfConfig.tsConfigs.put(template,tsConfig);
} else {
netcdfConfig.tsConfigs.put(id, tsConfig);
}
}

return netcdfConfig;
}
}
Loading