diff --git a/sources/xsf.generator/XSFModel.json b/sources/xsf.generator/XSFModel.json index 0ade2252cbd824522b699d49bfaaa9e494ee1258..7a4ba40ceddb249dbdef364e5a727fd60cdea6e7 100644 --- a/sources/xsf.generator/XSFModel.json +++ b/sources/xsf.generator/XSFModel.json @@ -5457,9 +5457,9 @@ ] }, { - "name": "rx_beam_rotation_alpha", + "name": "rx_beam_rotation_phi", "obligation": "M", - "comment": "The extrinsic z-x-z clockwise rotation about the _z_-axis of the platform coordinate system needed to give the beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise rotation about the _x_-axis of the platform coordinate system needed to give the receive beam coordinate system.", "dims": [ "ping_time", "beam" @@ -5468,7 +5468,7 @@ "attributes": [ { "name": "long_name", - "value": "angular rotation about the _z_ axis" + "value": "receive beam angular rotation about the _x_ axis" }, { "name": "units", @@ -5482,9 +5482,9 @@ ] }, { - "name": "rx_beam_rotation_beta", + "name": "rx_beam_rotation_theta", "obligation": "M", - "comment": "The extrinsic z-x-z clockwise rotation about the _x_-axis of the platform coordinate system needed to give the beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise rotation about the _y_-axis of the platform coordinate system needed to give the receive beam coordinate system.", "dims": [ "ping_time", "beam" @@ -5493,7 +5493,7 @@ "attributes": [ { "name": "long_name", - "value": "angular rotation about the _x_ axis" + "value": "receive beam angular rotation about the _y_ axis" }, { "name": "units", @@ -5501,15 +5501,15 @@ }, { "name": "valid_range", - "value": "-180.0f, 180.0f", + "value": "-90.0f, 90.0f", "type": "float" } ] }, { - "name": "rx_beam_rotation_gamma", + "name": "rx_beam_rotation_psi", "obligation": "M", - "comment": "The extrinsic z-x-z clockwise rotation about the _z_-axis of the platform coordinate system needed to give the beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise about the _z_-axis of the platform coordinate system needed to give the receive beam coordinate system.", "dims": [ "ping_time", "beam" @@ -5518,7 +5518,7 @@ "attributes": [ { "name": "long_name", - "value": "angular rotation about the _z_ axis" + "value": "receive beam angular rotation about the _z_ axis" }, { "name": "units", @@ -5531,85 +5531,11 @@ } ] }, + { - "name": "beam_direction_x", - "obligation": "M", - "comment": "The _x_-axis coordinate of a unit vector in the beam direction for each beam and ping in the FACS coordinate system (ie relative to the vertical)", - "dims": [ - "ping_time", - "beam" - ], - "type": "float", - "attributes": [ - { - "name": "long_name", - "value": "_x_-component of the vector that gives the pointing direction of the beam, in sonar beam coordinate system" - }, - { - "name": "crs", - "value": "FACS" - }, - { - "name": "valid_range", - "value": "-1.0f, 1.0f", - "type": "float" - } - ] - }, - { - "name": "beam_direction_y", - "obligation": "M", - "comment": "The _y_-axis coordinate of a unit vector in the beam direction for each beam and ping, in the FACS coordinate system (ie relative to the vertical)", - "dims": [ - "ping_time", - "beam" - ], - "type": "float", - "attributes": [ - { - "name": "long_name", - "value": "_y_-component of the vector that gives the pointing direction of the beam, in the FACS coordinate system (ie relative to the vertical)" - }, - { - "name": "valid_range", - "value": "-1.0f, 1.0f", - "type": "float" - }, - { - "name": "crs", - "value": "FACS" - } - ] - }, - { - "name": "beam_direction_z", - "obligation": "M", - "comment": "The _z_-axis coordinate of a unit vector in the beam direction for each beam and ping, in the FACS coordinate system (ie relative to the vertical)", - "dims": [ - "ping_time", - "beam" - ], - "type": "float", - "attributes": [ - { - "name": "long_name", - "value": "_z_-component of the vector that gives the pointing direction of the beam, in the FACS coordinate system (ie relative to the vertical)" - }, - { - "name": "valid_range", - "value": "-1.0f, 1.0f", - "type": "float" - }, - { - "name": "crs", - "value": "FACS" - } - ] - }, - { - "name": "tx_beam_direction_x", + "name": "tx_beam_rotation_phi", "obligation": "M", - "comment": "The _x_-axis coordinate of a unit vector in the beam direction for each tx_beam and ping, as per the sonar beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise rotation about the _x_-axis of the platform coordinate system needed to give the transmit beam coordinate system.", "dims": [ "ping_time", "tx_beam" @@ -5618,23 +5544,23 @@ "attributes": [ { "name": "long_name", - "value": "_x_-component of the vector that gives the pointing direction of the tx_beam, in sonar beam coordinate system" + "value": "transmit beam angular rotation about the _x_ axis" }, { "name": "units", - "value": "1" + "value": "arc_degree" }, { "name": "valid_range", - "value": "-1.0f, 1.0f", + "value": "-180.0f, 180.0f", "type": "float" } ] }, { - "name": "tx_beam_direction_y", + "name": "tx_beam_rotation_theta", "obligation": "M", - "comment": "The _y_-axis coordinate of a unit vector in the tx_beam direction for each beam and ping, as per the sonar beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise about the _y_-axis of the platform coordinate system needed to give the transmit beam coordinate system.", "dims": [ "ping_time", "tx_beam" @@ -5643,23 +5569,23 @@ "attributes": [ { "name": "long_name", - "value": "_y_-component of the vector that gives the pointing direction of the tx_beam, in sonar beam coordinate system" + "value": "transmit beam angular rotation about the _y_ axis" }, { "name": "units", - "value": "1" + "value": "arc_degree" }, { "name": "valid_range", - "value": "-1.0f, 1.0f", + "value": "-180.0f, 180.0f", "type": "float" } ] }, { - "name": "tx_beam_direction_z", + "name": "tx_beam_rotation_psi", "obligation": "M", - "comment": "The _z_-axis coordinate of a unit vector in the tx_beam direction for each beam and ping, as per the sonar beam coordinate system.", + "comment": "The intrinsic _z_–_y_’–_x_” clockwise about the _z_-axis of the platform coordinate system needed to give the transmit beam coordinate system.", "dims": [ "ping_time", "tx_beam" @@ -5668,15 +5594,15 @@ "attributes": [ { "name": "long_name", - "value": "_z_-component of the vector that gives the pointing direction of the tx_beam, in sonar beam coordinate system" + "value": "transmit beam angular rotation about the _z_ axis" }, { "name": "units", - "value": "1" + "value": "arc_degree" }, { "name": "valid_range", - "value": "-1.0f, 1.0f", + "value": "-180.0f, 180.0f", "type": "float" } ] @@ -6391,7 +6317,7 @@ { "name": "platform_vertical_offset", "obligation": "M", - "comment": "Distance from the platform reference point to the water line (distance are positives downwards). For ships and similar, this is called heave, but the concept applies equally well to underwater vehicle depth.", + "comment": "Distance from the platform reference point to the water line (distance are positives downwards). For ships and similar, this is called heave and is added to the dynamic draught at the time of the ping but the concept applies equally well to underwater vehicle depth.", "dims": [ "ping_time" ], @@ -6437,7 +6363,7 @@ { "name": "waterline_to_chart_datum", "obligation": "O", - "comment": "Vertical translation vector at the time of the ping matching the distance from the water line to the chart data reference (typically Lowest Astronomical Tide or Mean Sea Level). This variable is the vector obtains by adding the tide, the dynamic draught at the time of the ping and allow to position samples in an absolute referential.", + "comment": "Vertical translation vector at the time of the ping matching the distance from the water line to the chart data reference (typically Lowest Astronomical Tide or Mean Sea Level). This variable is the vector that contains the tide and allows for the positioning of samples in an absolute reference system.", "dims": [ "ping_time" ], @@ -6478,7 +6404,9 @@ }, { "name": "valid_min", - "value": "0" + "value": "0", + "type": "short" + } ] } @@ -8484,6 +8412,25 @@ "ping_time" ], "type": "float", + "comment": "Projector beam steering angle horizontal from 7000 datagram", + "attributes": [ + { + "name": "units", + "value": "degree" + } + + ], + "fileTypes": [ + "s7k" + ] + }, + { + "name": "projector_beam_steering_angle_vertical", + "dims": [ + "ping_time" + ], + "type": "float", + "comment": "Projector beam steering angle vertical from 7000 datagram", "attributes": [ { "name": "units", @@ -9010,6 +8957,44 @@ "s7k" ] }, + { + "name": "raw_rx_beam_pointing_angle", + "dims": [ + "ping_time", + "beam" + ], + "type": "float", + "attributes": [ + { + "name": "unit", + "value": "degree" + } + ], + "fileTypes": [ + "all","kmall" + ], + "comment": "The receiver beam pointing angle as given by the constructor. Match BeamPointingAngle of Water column datagram for all files and BeamPointAngReVertical_deg for kmall files " + + }, + { + "name": "raw_tx_beam_tilt_angle", + "dims": [ + "ping_time", + "tx_beam" + ], + "type": "float", + "attributes": [ + { + "name": "unit", + "value": "degree" + } + ], + "fileTypes": [ + "all","kmall" + ], + "comment": "The receiver tx beam tilt angle as given by the constructor. Match TiltAngleReTx_deg of kmall WCD datagrams and Water column" + + }, { "name": "beam_horizontal_direction_angle", "dims": [ diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/DataTypeConverter.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/DataTypeConverter.java index bb516417ff76e4a35b3ac43cbecb80916c455904..370af18becaa16228b2c3ad0c1c6e343673a1e1b 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/DataTypeConverter.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/DataTypeConverter.java @@ -6,18 +6,27 @@ import java.util.List; public class DataTypeConverter { private static HashMap vlen_specific_types=new HashMap<>(); - public static DataType get(String value) throws Exception + public static String getName(String value) throws Exception { switch(value.toUpperCase()) { - case "BOOLEAN": - return DataType.BOOLEAN; - //on triche un peu et map les types enum sur des bytes case "TRANSDUCER_TYPE_T": case "DETECTION_TYPE_T": case "TRANSMIT_T": case "BEAM_STABILISATION_T": case "BEAM_T": + return "getEnum(\""+value+"\").getValue()"; + default: + return "DataType."+get(value).name(); + } + } + + public static DataType get(String value) throws Exception + { + switch(value.toUpperCase()) + { + case "BOOLEAN": + return DataType.BOOLEAN; case "BYTE": return DataType.BYTE; case "CHAR": @@ -46,8 +55,6 @@ public class DataTypeConverter { return DataType.STRING; default: } - - throw new Exception("Unknown netcdf type " + value); } /** @@ -58,6 +65,11 @@ public class DataTypeConverter { return vlen_specific_types.containsKey(name); } + public static boolean is_enum(String name) + { + return name.endsWith("_t"); + } + /** * declare a specific type * @param name the name of the type diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/NetcdfLayerDeclarer.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/NetcdfLayerDeclarer.java index f8680f8368e935c7e4951cfc1c2a4c188823ead4..319959616cd4917dbe476af7cde403a1f388e9a0 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/NetcdfLayerDeclarer.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/NetcdfLayerDeclarer.java @@ -15,6 +15,8 @@ public class NetcdfLayerDeclarer { else { String type=expandedlayerType.isEmpty() ? basetype:expandedlayerType; + if(DataTypeConverter.is_enum(type)) + return getClassicLayerClass(dim, DataType.BYTE); return getClassicLayerClass(dim, DataTypeConverter.get(type)); } diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCAttributeAdapter.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCAttributeAdapter.java index 6a0aa2e7df3fd06238b206c8f3afb87618b68c3f..343a582f9781de5a1c45af2e83ad0921ec879f46 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCAttributeAdapter.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCAttributeAdapter.java @@ -5,7 +5,19 @@ import java.util.List; import java.util.function.Function; public class SCAttributeAdapter { + public static List getSourceDeclaration(Attribute attribute) { + return Arrays.asList( + String.format("\tpublic static final String %s=\"%s\";", "ATT_"+attribute.name.toUpperCase(),attribute.name)); + } + public static List getSourceCode(Group group, Attribute attribute) { + if(attribute.getType()==null) + { + //treat as String + return Arrays.asList(String.format("addAttribute(\"%s\", \"%s\");","ATT_"+attribute.name.toUpperCase(), attribute.value == null ? "":attribute.value.replace("+",""))); + } + return Arrays.asList(String.format("addAttribute(\"%s\", %s);","ATT_"+attribute.name.toUpperCase(), formatAttribute(attribute,attribute.getType()))); + } public static List getSourceCode(Variable variable, Attribute attribute) { if(attribute.getName().compareTo("_FillValue")==0){ diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCGroupAdapter.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCGroupAdapter.java index 1e2470a91436719d73b554ee09f08fc74b2a47f3..abbd30ae81fe083f5a883544a74d79a5778405d4 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCGroupAdapter.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCGroupAdapter.java @@ -68,6 +68,7 @@ public class SCGroupAdapter { classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.DataType;"); classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCException;"); classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCGroup;"); + classToImportSet.add("import fr.ifremer.globe.netcdf.util.Pair;"); if (!group.variables.isEmpty()) classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCVariable;"); @@ -86,6 +87,14 @@ public class SCGroupAdapter { if (group.getGroupCategory() == GroupCategory.eStandard) sourceCode.add(String.format("\n\tpublic static final String GROUP_NAME = \"%s\";", group.name)); + // group attribute declaration + if(group.attributes.size()>0) + { + sourceCode.add("\n\t/**group attributes names declaration*/"); + } + group.attributes.forEach(v -> sourceCode.addAll(SCAttributeAdapter.getSourceDeclaration(v))); + + // Dimension name code generation if (!group.dims.isEmpty()) { sourceCode.add("\n\t/**dimensions names declaration*/"); @@ -145,7 +154,7 @@ public class SCGroupAdapter { if (!group.attributes.isEmpty()) { sourceCode.add("\n\t\t/** Group attributes **/"); group.attributes.forEach( - att -> SCAttributeAdapter.getSourceCode(att, s -> s).forEach(src -> sourceCode.add("\t\t" + src))); + att -> SCAttributeAdapter.getSourceCode(group,att).forEach(src -> sourceCode.add("\t\t" + src))); } // Variables declaration @@ -331,7 +340,7 @@ public class SCGroupAdapter { } dictionary+="}"; sourceCode.add(String.format("%s%s%s", localIdent, pythonIndent,dictionary)); - sourceCode.add(String.format("%s%stype_e = nc.createEnumType(np.uint8, '%s', enum_dict)", localIdent, pythonIndent,name)); + sourceCode.add(String.format("%s%stype_e = group.createEnumType(np.uint8, '%s', enum_dict)", localIdent, pythonIndent,name)); sourceCode.add(String.format("%s%stypes['%s'] = type_e", localIdent, pythonIndent,name)); }else if (type.getName().contains("*")) { @@ -421,17 +430,23 @@ public class SCGroupAdapter { String datatype=""; String comment=""; + boolean has_fill_value=true; + String fill_value="np.nan"; + has_fill_value=false; //set to false by default switch(v.getType()) { + case "string": case "String": datatype="str"; break; case "float": datatype="np.float32"; + has_fill_value=true; break; case "double": datatype="np.float64"; + has_fill_value=true; break; case "int": datatype="np.int"; @@ -462,22 +477,37 @@ public class SCGroupAdapter { break; default: datatype="types['"+v.getType()+"']"; + has_fill_value=false; // comment="#";//unsupported for now } + for(Attribute att: v.attributes) + { + if (att.getName()== "_FillValue" ) + { + has_fill_value=true; + fill_value=att.getValue(); + if(fill_value.contains("NaN")) + fill_value="np.nan"; + } + } String dimensions=""; if(v.dims.isEmpty()) { - dimensions="None"; + dimensions=""; }else { dimensions="\""+String.join("\", \"", v.dims)+"\""; } - String fill_value="np.nan"; + sourceCode.add("\n"+localIdent +comment+ String.format("def create_%s(self, group: nc.Dataset):",v.name.toLowerCase())); sourceCode.add(localIdent +comment+ pythonIndent+ String.format("\"\"\"create variable %s\"\"\"",v.name.toLowerCase())); - sourceCode.add(localIdent +comment+ pythonIndent + String.format("v = group.createVariable(varname=\"%s\", datatype=%s, dimensions=(%s), fill_value=%s)",v.name,datatype,dimensions,fill_value)); + if(has_fill_value) + sourceCode.add(localIdent +comment+ pythonIndent + String.format("v = group.createVariable(varname=\"%s\", datatype=%s, dimensions=(%s), fill_value=%s)",v.name,datatype,dimensions,fill_value)); + else + sourceCode.add(localIdent +comment+ pythonIndent + String.format("v = group.createVariable(varname=\"%s\", datatype=%s, dimensions=(%s))",v.name,datatype,dimensions)); + for(Attribute att: v.attributes) { if (att.getName()!= "_FillValue") diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCTypeAdapter.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCTypeAdapter.java index 2e047199e68e4c5012f6341e8e94f7b566414f62..f4790c21aaa7402ddf4b218b820921b7cbe0718a 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCTypeAdapter.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCTypeAdapter.java @@ -14,11 +14,52 @@ public class SCTypeAdapter { DataType type; type = DataTypeConverter.getVlenDataType(name); return Arrays.asList(String.format("\t\tthis.addType(\"%s\",%d); //vlen for type %s",name,type.getNc_type(),type)); + } else if (name.contains("enum")) + { + return parseEnum(name); } + return Arrays.asList(String.format("\t\t// %s", name)); } catch (Exception e) { throw new RuntimeException(e); } } + private static List parseEnum(String name) { + if(name.startsWith("byte enum")) + { + name=name.replace("\u00A0", " "); + String a=name.replace("byte enum", ""); + a=a.trim(); + String spaced[]=a.split("\\{"); + String enum_name=spaced[0].trim(); + String values=spaced[1].replace("}","").trim(); + String value_list[]=values.split(","); + StringBuilder builder=new StringBuilder(); + builder.append("\t\tthis.addEnumByte(\""); + builder.append(enum_name); + builder.append("\",Arrays.asList("); + boolean first=true; + for(String v: value_list) + { + String tup[]=v.split("="); + String enum_value_name=tup[0].replace("\'","").replace(";","").trim(); + String enum_value=tup[1].replace("\'","").replace(";","").trim(); + if(!first) + builder.append(","); + builder.append("new Pair((byte)"); + builder.append(enum_value); + builder.append(",\""); + builder.append(enum_value_name); + builder.append("\")"); + first=false; + } + builder.append("));"); + return Arrays.asList(builder.toString()); + } + else + throw new RuntimeException("Not Supported enum type"); + + } + } diff --git a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCVariableAdapter.java b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCVariableAdapter.java index c4d0814406f4c7eadffe29f74cafe776221563a6..2b8b80439db5db0323774332b518f3e531e0278c 100644 --- a/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCVariableAdapter.java +++ b/sources/xsf.generator/src/main/java/fr/ifremer/fr/xsf/generator/model/SCVariableAdapter.java @@ -68,7 +68,7 @@ public class SCVariableAdapter { } else { // variable declaration - codeLines.add(String.format("\t\t%s = addVariable(%s, DataType.%s, %s);", variable.name, variable.name.toUpperCase(),DataTypeConverter.get(variable.type).name(), + codeLines.add(String.format("\t\t%s = addVariable(%s, %s, %s);", variable.name, variable.name.toUpperCase(),DataTypeConverter.getName(variable.type), dimString)); }