Search in sources :

Example 41 with Index

use of com.google.datastore.admin.v1.Index in project java-firestore by googleapis.

the class FirestoreAdminClientTest method getIndexTest.

@Test
public void getIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    mockFirestoreAdmin.addResponse(expectedResponse);
    IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
    Index actualResponse = client.getIndex(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : IndexName(com.google.firestore.admin.v1.IndexName) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.firestore.admin.v1.GetIndexRequest) Index(com.google.firestore.admin.v1.Index) Test(org.junit.Test)

Example 42 with Index

use of com.google.datastore.admin.v1.Index in project java-firestore by googleapis.

the class FirestoreAdminClientTest method createIndexTest.

@Test
public void createIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockFirestoreAdmin.addResponse(resultOperation);
    CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
    Index index = Index.newBuilder().build();
    Index actualResponse = client.createIndexAsync(parent, index).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(index, actualRequest.getIndex());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1.Index) Operation(com.google.longrunning.Operation) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) CreateIndexRequest(com.google.firestore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Example 43 with Index

use of com.google.datastore.admin.v1.Index in project s1tbx by senbox-org.

the class NetCDFUtils method createMapInfoX.

public static MapInfoX createMapInfoX(final Variable lonVar, final Variable latVar, final int sceneRasterWidth, final int sceneRasterHeight) throws IOException {
    float pixelX;
    float pixelY;
    float easting;
    float northing;
    float pixelSizeX;
    float pixelSizeY;
    final NcAttributeMap lonAttrMap = NcAttributeMap.create(lonVar);
    final Number lonValidMin = lonAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
    final Number lonStep = lonAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
    final NcAttributeMap latAttrMap = NcAttributeMap.create(latVar);
    final Number latValidMin = latAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
    final Number latStep = latAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
    boolean yFlipped;
    if (lonValidMin != null && lonStep != null && latValidMin != null && latStep != null) {
        // COARDS convention uses 'valid_min' and 'step' attributes
        pixelX = 0.5f;
        pixelY = (sceneRasterHeight - 1.0f) + 0.5f;
        easting = lonValidMin.floatValue();
        northing = latValidMin.floatValue();
        pixelSizeX = lonStep.floatValue();
        pixelSizeY = latStep.floatValue();
        // must flip
        // todo - check
        yFlipped = true;
    } else {
        // CF convention
        final Array lonData = lonVar.read();
        final Array latData = latVar.read();
        final Index i0 = lonData.getIndex().set(0);
        final Index i1 = lonData.getIndex().set(1);
        pixelSizeX = lonData.getFloat(i1) - lonData.getFloat(i0);
        easting = lonData.getFloat(i0);
        final int latSize = (int) latVar.getSize();
        final Index j0 = latData.getIndex().set(0);
        final Index j1 = latData.getIndex().set(1);
        pixelSizeY = latData.getFloat(j1) - latData.getFloat(j0);
        pixelX = 0.5f;
        pixelY = 0.5f;
        // this should be the 'normal' case
        if (pixelSizeY < 0) {
            pixelSizeY *= -1;
            yFlipped = false;
            northing = latData.getFloat(latData.getIndex().set(0));
        } else {
            yFlipped = true;
            northing = latData.getFloat(latData.getIndex().set(latSize - 1));
        }
    }
    if (pixelSizeX <= 0 || pixelSizeY <= 0) {
        return null;
    }
    final MapProjection projection = MapProjectionRegistry.getProjection(IdentityTransformDescriptor.NAME);
    final MapInfo mapInfo = new MapInfo(projection, pixelX, pixelY, easting, northing, pixelSizeX, pixelSizeY, Datum.WGS_84);
    mapInfo.setSceneWidth(sceneRasterWidth);
    mapInfo.setSceneHeight(sceneRasterHeight);
    return new MapInfoX(mapInfo, yFlipped);
}
Also used : Array(ucar.ma2.Array) MapProjection(org.esa.snap.core.dataop.maptransf.MapProjection) MapInfo(org.esa.snap.core.dataop.maptransf.MapInfo) Index(ucar.ma2.Index)

Example 44 with Index

use of com.google.datastore.admin.v1.Index in project SOS by 52North.

the class AbstractNetcdfEncoder method encodeSensorDataToNetcdf.

protected void encodeSensorDataToNetcdf(File netcdfFile, AbstractSensorDataset sensorDataset, Version version) throws EncodingException, IOException {
    String sensor = sensorDataset.getSensorIdentifier();
    sensorDataset.getSensor().setSensorDescription(getProcedureDescription(sensor, sensorDataset.getProcedureDescription()));
    NetcdfFileWriter writer = getNetcdfFileWriter(netcdfFile, version);
    // set fill on, doesn't seem to have any effect though
    writer.setFill(true);
    Map<Variable, Array> variableArrayMap = Maps.newHashMap();
    int numTimes = sensorDataset.getTimes().size();
    // FIXME shouldn't assume that all subsensors are heights (or rename
    // subsensors if they are)
    int numHeightDepth = sensorDataset.getSubSensors().size() > 0 ? sensorDataset.getSubSensors().size() : 1;
    // global attributes
    addGlobaleAttributes(writer, sensorDataset);
    // add appropriate dims for feature type
    List<Dimension> timeDims = Lists.newArrayList();
    List<Dimension> latLngDims = Lists.newArrayList();
    List<Dimension> latDims = Lists.newArrayList();
    List<Dimension> lngDims = Lists.newArrayList();
    List<Dimension> zDims = Lists.newArrayList();
    List<Dimension> obsPropDims = Lists.newArrayList();
    // REQUIRED for NetCDF-3
    // add Dimensions
    // dTime = writer.addDimension(null, CFStandardNames.TIME.getName(),
    // numTimes);
    Dimension dTime = writer.addUnlimitedDimension(getVariableDimensionCaseName(CFStandardNames.TIME.getName()));
    dTime.setLength(numTimes);
    timeDims.add(dTime);
    if (!(sensorDataset instanceof StaticLocationDataset)) {
        zDims.add(dTime);
    }
    obsPropDims.add(dTime);
    // set up lat/lng dimensions
    // FIXME do not set time dimension for static location dataset
    // if ((sensorDataset instanceof StaticLocationDataset)) {
    // latLngDims.add(dTime);
    // }
    // set up z dimensions
    String dimensionName;
    if (useHeight()) {
        dimensionName = getVariableDimensionCaseName(CFStandardNames.HEIGHT.getName());
    } else {
        dimensionName = getVariableDimensionCaseName(CFStandardNames.DEPTH.getName());
    }
    // profile/timeSeriesProfile
    Dimension dZ = writer.addDimension(null, dimensionName, numHeightDepth);
    if (!(sensorDataset instanceof StaticLocationDataset)) {
        // trajectory
        zDims.add(dTime);
    }
    zDims.add(dZ);
    obsPropDims.add(dZ);
    variableArrayMap.putAll(getNetcdfProfileSpecificVariablesArrays(writer, sensorDataset));
    // time var
    Variable vTime = addVariableTime(writer, timeDims);
    if (numTimes > 1 && writer.getVersion().isNetdf4format()) {
        vTime.addAttribute(new Attribute(CDM.CHUNK_SIZES, getNetcdfHelper().getChunkSizeTime()));
    }
    ArrayDouble timeArray = new ArrayDouble(getDimShapes(timeDims));
    initArrayWithFillValue(timeArray, getNetcdfHelper().getFillValue());
    Array latArray = getLatitudeArray(sensorDataset);
    Array lonArray = getLongitudeArray(sensorDataset);
    // add lat/long dimensions
    long latSize = 1;
    if (latArray != null) {
        latSize = latArray.getSize();
    }
    Dimension dLat = writer.addDimension(null, getVariableDimensionCaseName(CFStandardNames.LATITUDE.getName()), (int) latSize);
    latDims.add(dLat);
    long lonSize = 1;
    if (lonArray != null) {
        lonSize = lonArray.getSize();
    }
    Dimension dLon = writer.addDimension(null, getVariableDimensionCaseName(CFStandardNames.LONGITUDE.getName()), (int) lonSize);
    lngDims.add(dLon);
    // lat/lon var
    Variable vLat;
    Variable vLon;
    if (latLngDims.size() > 0) {
        vLat = addVariableLatitude(writer, latLngDims);
        vLon = addVariableLongitude(writer, latLngDims);
    } else {
        vLat = addVariableLatitude(writer, latDims);
        vLon = addVariableLongitude(writer, lngDims);
    }
    // height/depth var
    Variable vHeightDepth;
    if (useHeight()) {
        vHeightDepth = addVariableHeight(writer, zDims);
    } else {
        vHeightDepth = addVariableDepth(writer, zDims);
    }
    String coordinateString = Joiner.on(' ').join(Lists.newArrayList(vTime.getFullName(), vLat.getFullName(), vLon.getFullName(), vHeightDepth.getFullName()));
    Map<OmObservableProperty, Variable> obsPropVarMap = Maps.newHashMap();
    Map<Variable, Array> varDataArrayMap = Maps.newHashMap();
    for (OmObservableProperty obsProp : sensorDataset.getPhenomena()) {
        // obs prop var
        Variable vObsProp = addVariableForObservedProperty(writer, obsProp, obsPropDims, coordinateString);
        obsPropVarMap.put(obsProp, vObsProp);
        // init obs prop data array
        Array obsPropArray = getArray(obsPropDims);
        initArrayWithFillValue(obsPropArray, getNetcdfHelper().getFillValue());
        varDataArrayMap.put(vObsProp, obsPropArray);
    }
    // populate heights array for profile
    Array heightDephtArray = null;
    if (zDims.size() == 1 && hasDimension(zDims, dZ) && !sensorDataset.getSubSensors().isEmpty()) {
        heightDephtArray = initHeightDephtArray(zDims);
        Double consistentBinHeight = populateHeightDepthArray(sensorDataset, heightDephtArray, vHeightDepth);
        String verticalResolution = null;
        if (consistentBinHeight == null) {
            verticalResolution = ACDDConstants.POINT;
        } else if (consistentBinHeight != getNetcdfHelper().getFillValue()) {
            verticalResolution = consistentBinHeight + " " + CFConstants.UNITS_METERS + " " + ACDDConstants.BINNED;
        }
        if (verticalResolution != null) {
            writer.addGroupAttribute(null, new Attribute(ACDDConstants.GEOSPATIAL_VERTICAL_RESOLUTION, verticalResolution));
        }
    }
    // iterate through sensorDataset, set values
    int timeCounter = 0;
    for (Time time : sensorDataset.getTimes()) {
        // set time value
        Index timeIndex = timeArray.getIndex();
        int timeIndexCounter = 0;
        // }
        if (hasDimension(timeDims, dTime)) {
            timeIndex.setDim(timeIndexCounter++, timeCounter++);
        }
        timeArray.set(timeIndex, getTimeValue(time));
        // data values
        Map<OmObservableProperty, Map<SubSensor, Value<?>>> obsPropMap = sensorDataset.getDataValues().get(time);
        for (Entry<OmObservableProperty, Map<SubSensor, Value<?>>> entry : obsPropMap.entrySet()) {
            OmObservableProperty obsProp = entry.getKey();
            Variable variable = obsPropVarMap.get(obsProp);
            Array array = varDataArrayMap.get(variable);
            for (Entry<SubSensor, Value<?>> subSensorEntry : obsPropMap.get(obsProp).entrySet()) {
                SubSensor subSensor = subSensorEntry.getKey();
                Value<?> value = subSensorEntry.getValue();
                Object valObj = value.getValue();
                if (!(valObj instanceof Number)) {
                    throw new EncodingException("Value class %s not supported", valObj.getClass().getCanonicalName());
                }
                Index index = array.getIndex();
                int obsPropDimCounter = 0;
                for (Dimension dim : obsPropDims) {
                    // } else if (dim.equals(dTime)){
                    if (dim.equals(dTime)) {
                        // time index dim
                        index.setDim(obsPropDimCounter++, timeCounter - 1);
                    } else if (dim.equals(dZ) && dim.getLength() > 1) {
                        // height/depth index dim
                        index.setDim(obsPropDimCounter++, sensorDataset.getSubSensors().indexOf(subSensor));
                    }
                }
                if (array instanceof ArrayFloat) {
                    ((ArrayFloat) array).set(index, ((Number) valObj).floatValue());
                } else {
                    ((ArrayDouble) array).set(index, ((Number) valObj).doubleValue());
                }
            }
        }
    }
    // create the empty netCDF with dims/vars/attributes defined
    variableArrayMap.put(vTime, timeArray);
    if (latArray != null) {
        variableArrayMap.put(vLat, latArray);
    }
    if (lonArray != null) {
        variableArrayMap.put(vLon, lonArray);
    }
    if (heightDephtArray != null) {
        variableArrayMap.put(vHeightDepth, heightDephtArray);
    }
    variableArrayMap.putAll(varDataArrayMap);
    // create the empty netCDF with dims/vars/attributes defined
    writeToFile(writer, variableArrayMap);
    writer.close();
}
Also used : Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) EncodingException(org.n52.svalbard.encode.exception.EncodingException) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) Index(ucar.ma2.Index) ArrayFloat(ucar.ma2.ArrayFloat) ArrayDouble(ucar.ma2.ArrayDouble) ProfileSubSensor(org.n52.sos.netcdf.data.subsensor.ProfileSubSensor) SubSensor(org.n52.sos.netcdf.data.subsensor.SubSensor) BinProfileSubSensor(org.n52.sos.netcdf.data.subsensor.BinProfileSubSensor) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) Dimension(ucar.nc2.Dimension) ArrayDouble(ucar.ma2.ArrayDouble) NetcdfFileWriter(ucar.nc2.NetcdfFileWriter) Array(ucar.ma2.Array) StaticLocationDataset(org.n52.sos.netcdf.data.dataset.StaticLocationDataset) Value(org.n52.shetland.ogc.om.values.Value) Map(java.util.Map)

Example 45 with Index

use of com.google.datastore.admin.v1.Index in project SOS by 52North.

the class AbstractNetcdfEncoder method getLongitudeArray.

protected Array getLongitudeArray(AbstractSensorDataset sensorDataset) throws EncodingException {
    if (sensorDataset instanceof StaticLocationDataset) {
        StaticLocationDataset locationDataset = (StaticLocationDataset) sensorDataset;
        if (locationDataset.getLat() != null) {
            Array array = getArray();
            initArrayWithFillValue(array, getNetcdfHelper().getFillValue());
            Index index = array.getIndex();
            index.set(0);
            array.setDouble(index, locationDataset.getLat());
        }
    } else {
        // TODO support varying lat
        throw new EncodingException("Varying longs are not yet supported.");
    }
    return null;
}
Also used : Array(ucar.ma2.Array) StaticLocationDataset(org.n52.sos.netcdf.data.dataset.StaticLocationDataset) EncodingException(org.n52.svalbard.encode.exception.EncodingException) Index(ucar.ma2.Index)

Aggregations

Index (ucar.ma2.Index)30 Array (ucar.ma2.Array)20 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)12 Attribute (ucar.nc2.Attribute)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 WritableRaster (java.awt.image.WritableRaster)10 IOException (java.io.IOException)10 ArrayFloat (ucar.ma2.ArrayFloat)10 Index (com.google.firestore.admin.v1.Index)9 Dimension (ucar.nc2.Dimension)9 NetcdfFileWriteable (ucar.nc2.NetcdfFileWriteable)8 Variable (ucar.nc2.Variable)8 ArrayDouble (ucar.ma2.ArrayDouble)7 NetcdfFile (ucar.nc2.NetcdfFile)7 SampleModel (java.awt.image.SampleModel)5 Index (com.google.datastore.admin.v1.Index)4 Operation (com.google.longrunning.Operation)4 File (java.io.File)4 List (java.util.List)4