Skip to content

Commit

Permalink
OSF release 1.0.20-osf from origin 1.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaud Degueurce committed Mar 7, 2019
1 parent 3f36b0a commit b7e5728
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 309 deletions.
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>eu.serco.xmf.drb</groupId>
<artifactId>dhus-addon-sentinel-3</artifactId>
<packaging>jar</packaging>
<version>1.0.9-osf</version>
<version>1.0.20-osf</version>

<name>DHuS - Sentinel-3 addon</name>

Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>fr.gael.drb</groupId>
<artifactId>drbx-image</artifactId>
<version>1.7</version>
<version>1.9</version>
<exclusions>
<exclusion>
<artifactId>ehcache-core</artifactId>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>fr.gael.drb</groupId>
<artifactId>drbx-impl-netcdf</artifactId>
<version>1.0.10</version>
<version>1.0.24</version>
</dependency>

<dependency>
Expand All @@ -64,8 +64,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<encoding>ISO-8859-1</encoding>
<compilerArgs>
<arg>-Xlint:all,-options,-path</arg>
Expand Down Expand Up @@ -151,5 +151,4 @@
<url>https://github.com/SentinelDataHub/dhus-sentinel-3</url>
</scm>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import fr.gael.drb.query.Query;
import fr.gael.drb.value.Float;
import fr.gael.drb.value.Short;
import fr.gael.drb.value.UnsignedByte;
import fr.gael.drb.value.Value;
import fr.gael.drbx.image.DrbCollectionImage;
import fr.gael.drbx.image.DrbImage;
Expand Down Expand Up @@ -95,17 +96,43 @@ public static PixelCorrection extractPixelCorrection (
return extractPixelCorrection (node, name, variableName);
}

public static PixelCorrection extractPixelCorrectionUByte (
DrbCollectionImage sources, String name, String variableName)
{
DrbImage image = sources.getChildren().iterator().next();
DrbNode node = ((DrbNode)(image.getItemSource()));

return extractPixelCorrectionUByte (node, name, variableName);
}

public static PixelCorrection extractPixelCorrection (
DrbNode product_node, String name)
{
return extractPixelCorrection(product_node, name, name);
}

public static PixelCorrection extractPixelCorrection (
DrbNode product_node, String name, String variableName)
public static PixelCorrection extractPixelCorrection(DrbNode product_node, String name, String variableName)
{
String path = "*[name()='" + name + ".nc']/root/variables/*[name()='" + variableName + "']/attributes/";
return _extractPixelCorrection(product_node, path);
}

public static PixelCorrection extractMatchingPixelCorrection(DrbCollectionImage sources, String docName, String nodeName)
{
DrbImage image = sources.getChildren().iterator().next();
DrbNode node = ((DrbNode)(image.getItemSource()));

return extractMatchingPixelCorrection(node, docName, nodeName);
}

public static PixelCorrection extractMatchingPixelCorrection(DrbNode product_node, String docName, String nodeName)
{
String path = "*[fn:matches(name(), '" + docName + "')]/root/variables/*[fn:matches(name(), '" + nodeName + "')]/attributes/";
return _extractPixelCorrection(product_node, path);
}

private static PixelCorrection _extractPixelCorrection(DrbNode product_node, String path)
{
String path = "*[name()='" + name + ".nc']/root/variables/*[name()='" +
variableName + "']/attributes/";
try
{
Query query_pixel_scale = new Query(path + "scale_factor");
Expand Down Expand Up @@ -156,6 +183,61 @@ public static PixelCorrection extractPixelCorrection (
return null;
}

public static PixelCorrection extractPixelCorrectionUByte (
DrbNode product_node, String name, String variableName)
{
String path = "*[name()='" + name + ".nc']/root/variables/*[name()='" +
variableName + "']/attributes/";
try
{
Query query_pixel_scale = new Query(path + "scale_factor");
Query query_pixel_offset = new Query(path + "add_offset");
Query query_nodata = new Query(path + "_FillValue");

Value vscale = null;
try
{
vscale = query_pixel_scale.evaluate(product_node).getItem(0).
getValue().convertTo(Value.FLOAT_ID);
}
catch (Exception e)
{
vscale = new Float(1);
}
Value voffset =null;
try
{
voffset = query_pixel_offset.evaluate(product_node).getItem(0).
getValue().convertTo(Value.FLOAT_ID);
}
catch (Exception e)
{
voffset = new Float(0);
}
Value vnodata=null;
try
{
vnodata = query_nodata.evaluate(product_node).getItem(0).
getValue().convertTo(Value.UNSIGNED_BYTE_ID);
}
catch (Exception e)
{
vnodata = new UnsignedByte(0);
}

float scale = ((Float)vscale).floatValue();
float offset = ((Float)voffset).floatValue();
short nodata = ((UnsignedByte)vnodata).shortValue();

return new PixelCorrection(scale, offset, nodata);
}
catch (Exception e)
{
LOGGER.error("Pixel correction extraction failure.", e);
}
return null;
}

/**
* Pixel correction contains elements to apply a correction to a pixel.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,31 @@ public RenderedImage create(ParameterBlock param, RenderingHints renderingHints)
if(pc == null)
throw new IllegalArgumentException("Pixel corrections can't be null");

for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
if (raw.getData().getSample(j, i, 0) != pc.nodata )
lst[j][i] = raw.getData().getSample(j, i, 0) * pc.scale + pc.offset;


BufferedImage out = new BufferedImage(lst.length, lst[0].length, BufferedImage.TYPE_3BYTE_BGR);
TreeMap<Float, Color> colorMap = Common.loadColormap("lst.cpd",
273,
263,
321);

for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
{
if (raw.getData().getSample(j, i, 0) != pc.nodata)
out.setRGB(j, i, Common.colorMap((float) lst[j][i], colorMap).getRGB());
{
Color t = Common.colorMap((float) raw.getData().getSample(j, i, 0) * pc.scale + pc.offset, colorMap);
out.getRaster().setPixel(j, i, new int[]{t.getRed(), t.getGreen(), t.getBlue()});
}
else if (isUnfilled(flags[i][j]))
out.setRGB(j, i, new Color(0, 0, 0).getRGB());
out.getRaster().setPixel(j, i, new int[]{0, 0, 0});
else if (isSnowIce(flags[i][j]))
out.setRGB(j, i, new Color(185, 253, 255).getRGB());
out.getRaster().setPixel(j, i, new int[]{185, 253, 255});
else if (isWater(flags[i][j]))
out.setRGB(j, i, new Color(52, 58, 144).getRGB());
out.getRaster().setPixel(j, i, new int[]{0, 0, 0});
else if (lstUnderflow(exceptions[i][j]))
out.setRGB(j, i, new Color(0, 0, 171).getRGB());
out.getRaster().setPixel(j, i, new int[]{0, 0, 171});
else if (lstOverflow(exceptions[i][j]))
out.setRGB(j, i, new Color(170, 0, 0).getRGB());
else if (isCloud(flags[i][j]))
out.setRGB(j, i, new Color(255, 255, 255).getRGB());
out.getRaster().setPixel(j, i, new int[]{170, 0, 0});
else
out.setRGB(j, i, Color.WHITE.getRGB());
out.getRaster().setPixel(j, i, new int[]{255, 255, 255});

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class QuicklookVgpDescriptor extends OperationDescriptorImpl

public QuicklookVgpDescriptor()
{
super(resources, supportedModes, 4, paramNames, paramClasses,
super(resources, supportedModes, 1, paramNames, paramClasses,
null, null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package fr.gael.drb.cortex.topic.sentinel3.jai.operator;

import fr.gael.drb.DrbNode;
import fr.gael.drb.DrbSequence;
import fr.gael.drb.query.Query;
import fr.gael.drb.value.Integer;
import fr.gael.drb.value.Value;
import fr.gael.drb.value.ValueArray;
import fr.gael.drbx.image.DrbCollectionImage;
import fr.gael.drbx.image.DrbImage;
import org.apache.log4j.Logger;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;
import java.awt.image.renderable.RenderedImageFactory;
import java.util.TreeMap;

/**
* Created by fmarino on 31/05/2017.
*/
public class QuicklookVgpRIF implements RenderedImageFactory
{
private static final Logger LOGGER = Logger.getLogger(QuicklookVgpRIF.class);

/**
* This operator could be called by chunks of images.
* it uses the following composition
Expand All @@ -26,44 +37,105 @@ public class QuicklookVgpRIF implements RenderedImageFactory
@Override
public RenderedImage create(ParameterBlock param, RenderingHints hints)
{
DrbImage b3 = (DrbImage)param.getSource(0);
DrbImage b2 = (DrbImage)param.getSource(1);
DrbImage b0 = (DrbImage)param.getSource(2);
DrbImage mir = (DrbImage)param.getSource(3);

Common.PixelCorrection[]pc=(Common.PixelCorrection[])param.getObjectParameter(0);
Common.PixelCorrection mirc = pc[3];
Common.PixelCorrection b0c = pc[2];
Common.PixelCorrection b2c = pc[1];
Common.PixelCorrection b3c = pc[0];

if(mirc == null || b0c == null || b2c == null || b3c == null)
throw new IllegalArgumentException("Pixel corrections can't be null");
Common.PixelCorrection pc = ((Common.PixelCorrection[])param.getObjectParameter(0))[0];


short[][] flags = (short[][]) param.getObjectParameter(1);

RenderedImage raw = (RenderedImage) param.getSource(0);


int width = raw.getData().getWidth();
int height = raw.getData().getHeight();

int width = b0.getData().getWidth();
int height = b0.getData().getHeight();
double[][] ndvi = new double[width][height];

BufferedImage out = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
// sanity checks on input data
if(pc == null)
{
throw new IllegalArgumentException("Pixel corrections can't be null");
}

for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
if (b0.getData().getSample(j, i, 0) != b0c.nodata &&
b2.getData().getSample(j, i, 0) != b2c.nodata &&
b3.getData().getSample(j, i, 0) != b3c.nodata &&
mir.getData().getSample(j, i, 0) != mirc.nodata)
{
if (raw.getData().getSample(j, i, 0) != pc.nodata )
{
double b0Corrected = b0.getData().getSample(j, i, 0) * b0c.scale + b0c.offset;
double b2Corrected = b2.getData().getSample(j, i, 0) * b2c.scale + b2c.offset;
double b3Corrected = b3.getData().getSample(j, i, 0) * b3c.scale + b3c.offset;
double MIRCorrected = mir.getData().getSample(j, i, 0) * mirc.scale + mirc.offset;
Color pixel = new Color(
(int) (MIRCorrected*255),
(int) (0.5*255*(b2Corrected + b3Corrected)),
(int) ((b0Corrected + 0.1*MIRCorrected)*255)
);
out.setRGB(j, i, pixel.getRGB());
ndvi[j][i] = raw.getData().getSample(j, i, 0) * pc.scale + pc.offset;
}
}
}

BufferedImage out = new BufferedImage(ndvi.length, ndvi[0].length, BufferedImage.TYPE_3BYTE_BGR);
TreeMap<Float, Color> colorMap = Common.loadColormap("syn_ndvi_normalized.cpd", -0.548, 0.412);

for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (isLand(flags[i][j]) && raw.getData().getSample(j, i, 0) != pc.nodata)
{
out.setRGB(j, i, Common.colorMap((float) (ndvi[j][i]), colorMap).getRGB());
}
else if(!isLand(flags[i][j]))
{
out.getRaster().setPixel(j, i, new int[]{0, 0, 0});
}
else
{
out.getRaster().setPixel(j, i, new int[]{255, 255, 255});
}
}
}
return out;
}

private boolean isLand(short mask)
{
return (mask & 8) > 0;
}

public static short[][] extractFlags(DrbCollectionImage sources)
{
try
{
DrbImage image = sources.getChildren().iterator().next();
DrbNode node = ((DrbNode) (image.getItemSource()));

Query query_rows_number = new Query(
"sm.nc/root/dimensions/latitude");
Query query_cols_number = new Query(
"sm.nc/root/dimensions/longitude");
Query query_data = new Query(
"sm.nc/root/dataset/SM/latitude/longitude");

Value vrows = query_rows_number.evaluate(node).getItem(0).getValue().
convertTo(Value.INTEGER_ID);
Value vcols = query_cols_number.evaluate(node).getItem(0).getValue().
convertTo(Value.INTEGER_ID);

int rows = ((Integer) vrows).intValue();
int cols = ((Integer) vcols).intValue();

DrbSequence sequence = query_data.evaluate(node);
short[][] ds = new short[rows][cols];
for (int index_rows = 0; index_rows < sequence.getLength(); index_rows++)
{
DrbNode row_node = (DrbNode) sequence.getItem(index_rows);
ValueArray values = (ValueArray) row_node.getValue();
for (int index_cols = 0; index_cols < values.getLength(); index_cols++)
{
ds[index_rows][index_cols] =
((fr.gael.drb.value.UnsignedByte) values.getElement(index_cols).getValue()).shortValue();
}
}
return ds;
}
catch (Exception e)
{
LOGGER.error("flags extraction failure.", e);
return null;
}
}
}
Loading

0 comments on commit b7e5728

Please sign in to comment.