Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gaellafond committed Jul 14, 2021
0 parents commit 6068310
Show file tree
Hide file tree
Showing 20 changed files with 2,122 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Workflow executed on "push" events.
name: push

on: push

jobs:

# Run tests in Maven.
test:
runs-on: ubuntu-latest

container:
image: maven:3-jdk-8-slim

steps:

# Retrieve the code from Github.
# Use branch "v2" of the "checkout" plugin
- uses: actions/checkout@v2

- name: Install dependencies
run: |
apt-get update
apt-get install -y libnetcdf-c++4
- name: Execute tests with Maven.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B --settings settings.xml clean test
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Workflow executed on "release" events.
name: release

on:
release:
types: [published]

jobs:

# Deploy to Github Packages.
deploy:
name: Deploy to Github Packages

runs-on: ubuntu-latest

container:
image: maven:3-jdk-8-slim

steps:

# Retrieve the code from Github.
- uses: actions/checkout@v2

- name: Install dependencies
run: |
apt-get update
apt-get install -y libnetcdf-c++4
- name: Publish to GitHub Packages.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B -e --settings settings.xml deploy
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# IntelliJ files
.idea/
*.iml
# OpenJDK bug: https://bugs.openjdk.java.net/browse/JDK-8214300
.attach_pid*

# Maven files
target/
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Australian Institute of Marine Science

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
This project can be used to generate very small NetCDF files, which can be included in projects to run unit tests.

## Tools

NetCDF files can be viewed using different tools. The most convenient ones are:
- [Panoply](https://www.giss.nasa.gov/tools/panoply/)
- [Dive](http://software.cmar.csiro.au/www/en/software/dive.html)

**NOTE**: As of writing this documentation, CMAR have ceased to support the download link for **Dive**.
If you really want to use this tool, you can still find it on the
[Web Archive](https://web.archive.org/web/20170314023923/http://software.cmar.csiro.au/www/en/software/dive.html).

## NetCDF variable naming conventions

If you want to create your own NetCDF file, you may be interested in the following resources.

- [NetCDF naming convention for `long-name` and `standard-name`](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/ch02s03.html)
- [Table of common NetCDF `standard-name`](https://cfconventions.org/Data/cf-standard-names/77/build/cf-standard-name-table.html)

Some metadata information is hidden in unrelated attributes. Just have a look at the EDAL library source code
to see how `standard_name` and `long_name` can be used to infer metadata on the component variables of a vector variable.

Package: uk.ac.rdg.resc.edal.dataset.cdm
Class: CdmDatasetFactory
Source code:
```
private IdComponentEastNorth determineVectorIdAndComponent(String stdName) {
if (stdName.contains("eastward_")) {
return new IdComponentEastNorth(stdName.replaceFirst("eastward_", ""), true, true);
} else if (stdName.contains("northward_")) {
return new IdComponentEastNorth(stdName.replaceFirst("northward_", ""), false, true);
} else if (stdName.matches("u-.*component")) {
return new IdComponentEastNorth(stdName.replaceFirst("u-(.*)component", "$1"), true,
false);
} else if (stdName.matches("v-.*component")) {
return new IdComponentEastNorth(stdName.replaceFirst("v-(.*)component", "$1"), false,
false);
} else if (stdName.matches(".*x_.*velocity")) {
return new IdComponentEastNorth(stdName.replaceFirst("(.*)x_(.*velocity)", "$1$2"),
true, false);
} else if (stdName.matches(".*y_.*velocity")) {
return new IdComponentEastNorth(stdName.replaceFirst("(.*)y_(.*velocity)", "$1$2"),
false, false);
}
return null;
}
```
19 changes: 19 additions & 0 deletions maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<!-- Used by Maven (GitHub server) to resolve AIMS-KS dependencies when running tests or building the package -->
<server>
<id>github_aimsks</id>
<username>USERNAME</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
<!-- Used by Maven (GitHub server) to resolve Open-AIMS dependencies when running tests or building the package -->
<server>
<id>github_openaims</id>
<username>USERNAME</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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>

<groupId>au.gov.aims</groupId>
<artifactId>netcdf-generator</artifactId>
<version>0.2</version>
<packaging>jar</packaging>
<description>This project was created to produce very small NetCDF files,
to be used in unit tests of projects like NcAnimate,
without increasing the project size considerably.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<netcdfVersion>5.0.0-alpha3</netcdfVersion>
</properties>

<repositories>
<repository>
<id>github_openaims</id>
<name>GitHub Open-AIMS repo</name>
<url>https://maven.pkg.github.com/open-AIMS/*</url>
</repository>

<!-- AIMS ks maven mirror repository on GitHub -->
<repository>
<id>aims-ks.mvn-repo</id>
<name>AIMS Knowledge System MVN Repo</name>
<url>https://raw.githubusercontent.com/aims-ks/mvn-repo/master/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>cdm</artifactId>
<version>${netcdfVersion}</version>
</dependency>

<dependency>
<groupId>edu.ucar</groupId>
<artifactId>netcdf4</artifactId>
<version>${netcdfVersion}</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<!-- Used for JUnit tests - Not included in the war -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub AIMS-KS Apache Maven Packages</name>
<url>https://maven.pkg.github.com/open-aims/netcdf-generator</url>
</repository>
</distributionManagement>
</project>
19 changes: 19 additions & 0 deletions settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<!-- Used to deploy the package to GitHub -->
<server>
<id>github</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
<!-- Used by GitHub server to resolve AIMS-KS dependencies when running tests or building the package -->
<server>
<id>github_aimsks</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
53 changes: 53 additions & 0 deletions src/main/java/au/gov/aims/netcdf/DownloadManagerGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) Australian Institute of Marine Science, 2021.
* @author Gael Lafond <g.lafond@aims.gov.au>
*/
package au.gov.aims.netcdf;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import java.io.File;

/*
* Class used to generate small NetCDF files used with DownloadManager tests
*/

public class DownloadManagerGenerator {
private static final DateTimeZone TIMEZONE_BRISBANE = DateTimeZone.forID("Australia/Brisbane");

public static void main(String ... args) throws Exception {
Generator netCDFGenerator = new Generator();

// For the DownloadManager
NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2018, 10, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2018, 10, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2018-10.nc"), false);

NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2018, 11, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2018, 11, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2018-11.nc"), false);

NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2018, 12, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2018, 12, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2018-12.nc"), false);

NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2018, 12, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2018, 12, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2018-12_modified.nc"), false, 1000);

NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2019, 1, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2019, 1, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2019-01.nc"), false);

NcAnimateGenerator.generateGbr4v2(netCDFGenerator,
new DateTime(2019, 2, 1, 0, 0, TIMEZONE_BRISBANE),
new DateTime(2019, 2, 2, 0, 0, TIMEZONE_BRISBANE),
new File("/tmp/gbr4_simple_2019-02.nc"), false);
}
}
Loading

0 comments on commit 6068310

Please sign in to comment.