Skip to content

Commit

Permalink
add tests for gportal gcom normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Oct 4, 2021
1 parent 368d4e3 commit 10b808c
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 122 deletions.
143 changes: 143 additions & 0 deletions tests/normalizers/test_gportal_gcom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"""Tests for the GPortal GCOM-W normalizer"""
import unittest
from collections import OrderedDict
from datetime import datetime
from dateutil.tz import tzutc

import metanorm.normalizers as normalizers
from .data import DATASET_PARAMETERS
from metanorm.errors import MetadataNormalizationError


class GPortalGCOMAMSR2L3MetadataNormalizerTestCase(unittest.TestCase):
"""Tests for the GPortal GCOM-W ftp normalizer"""
def setUp(self):
self.normalizer = normalizers.geospaas.GPortalGCOMAMSR2L3MetadataNormalizer()

def test_check(self):
"""Test the checking condition"""
self.assertTrue(self.normalizer.check({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2017/12/'
'GW1AM2_20171201_01D_EQOA_L3SGSSTLB3300300.h5'
}))
self.assertTrue(self.normalizer.check({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2018/07/'
'GW1AM2_20180703_01D_EQOA_L3SGSSTHB3300300.h5'
}))

self.assertFalse(self.normalizer.check({}))
self.assertFalse(self.normalizer.check({'url': 'ftp://foo/bar'}))

def test_entry_title(self):
"""entry_title from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(self.normalizer.get_entry_title({}), 'AMSR2-L3 Sea Surface Temperature')

def test_entry_id(self):
"""entry_id from GPortalGCOMAMSR2L3MetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/'
'GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(self.normalizer.get_entry_id(attributes),
'GW1AM2_201207031905_134D_L2SGSSTLB3300300')

def test_entry_id_error(self):
"""a MetadataNormalizationError must be raised when an entry_id cannot be found"""
# wrong file format
with self.assertRaises(MetadataNormalizationError):
self.normalizer.get_entry_id({'url': 'ftp://foo/bar.txt'})
# no url attribute
with self.assertRaises(MetadataNormalizationError):
self.normalizer.get_entry_id({})

def test_summary(self):
"""summary from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(
self.normalizer.get_summary({}),
'Description: GCOM-W AMSR2 data;Processing level: 3')

def test_time_coverage_start_day(self):
"""Test getting time_coverage_start from a day file"""
self.assertEqual(
self.normalizer.get_time_coverage_start({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/'
'GW1AM2_20120702_01D_EQOD_L3SGSSTLB3300300.h5'}),
datetime(year=2012, month=7, day=2, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_start_month(self):
"""Test getting time_coverage_start from a month file"""
self.assertEqual(
self.normalizer.get_time_coverage_start({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2013/07/'
'GW1AM2_20130700_01M_EQMA_L3SGSSTLB3300300.h5'}),
datetime(year=2013, month=7, day=1, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_start_missing_attribute(self):
"""An exception must be raised if the attribute is missing"""
with self.assertRaises(MetadataNormalizationError):
self.normalizer.get_time_coverage_start({})

def test_time_coverage_end_day(self):
"""Test getting time_coverage_end from a day file"""
self.assertEqual(
self.normalizer.get_time_coverage_end({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2015/04/'
'GW1AM2_20150401_01D_EQOD_L3SGSSTLB3300300.h5'}),
datetime(year=2015, month=4, day=2, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_end_month(self):
"""Test getting time_coverage_end from a month file"""
self.assertEqual(
self.normalizer.get_time_coverage_end({
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2015/04/'
'GW1AM2_20150400_01M_EQMD_L3SGSSTLB3300300.h5'}),
datetime(year=2015, month=5, day=1, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_end_missing_attribute(self):
"""An exception must be raised if the attribute is missing"""
with self.assertRaises(MetadataNormalizationError):
self.normalizer.get_time_coverage_end({})

def test_platform(self):
"""platform from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(
self.normalizer.get_platform({}),
OrderedDict([('Category', 'Earth Observation Satellites'),
('Series_Entity', ''),
('Short_Name', 'GCOM-W1'),
('Long_Name', 'Global Change Observation Mission 1st-Water')]))

def test_instrument(self):
"""instrument from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(
self.normalizer.get_instrument({}),
OrderedDict([('Category', 'Earth Remote Sensing Instruments'),
('Class', 'Passive Remote Sensing'),
('Type', 'Spectrometers/Radiometers'),
('Subtype', 'Imaging Spectrometers/Radiometers'),
('Short_Name', 'AMSR2'),
('Long_Name', 'Advanced Microwave Scanning Radiometer 2')]))

def test_location_geometry(self):
"""geometry from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(
self.normalizer.get_location_geometry({}),
'POLYGON((-180 -90, -180 90, 180 90, 180 -90, -180 -90))')

def test_provider(self):
"""provider from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(
self.normalizer.get_provider({}),
OrderedDict([('Bucket_Level0', 'GOVERNMENT AGENCIES-NON-US'),
('Bucket_Level1', 'JAPAN'),
('Bucket_Level2', ''),
('Bucket_Level3', ''),
('Short_Name', 'JP/JAXA/EOC'),
('Long_Name', 'Earth Observation Center, Japan Aerospace Exploration '
'Agency, Japan'),
('Data_Center_URL', 'http://www.eorc.jaxa.jp/en/index.html')]))

def test_dataset_parameters(self):
"""dataset_parameters from GPortalGCOMAMSR2L3MetadataNormalizer """
self.assertEqual(self.normalizer.get_dataset_parameters({}), [
DATASET_PARAMETERS['sea_surface_temperature']
])
122 changes: 0 additions & 122 deletions tests/normalizers/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,6 @@ def test_time_coverage_start_ceda(self):
{'url': 'ftp://anon-ftp.ceda.ac.uk/neodc/esacci/sst/data/CDR_v2/Climatology/L4/v2.1/D365-ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_CDR2.1-v02.0-fv01.0.nc'}),
datetime(year=1982, month=12, day=31, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_start_jaxa(self):
"""shall return the propert starting time for hardcoded normalizer """
self.assertEqual(
self.normalizer.get_time_coverage_start(
{'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_20120702_01D_EQOD_L3SGSSTLB3300300.h5'}),
datetime(year=2012, month=7, day=2, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_start_jaxa_month_file(self):
"""shall return the propert starting time for hardcoded normalizer """
self.assertEqual(
self.normalizer.get_time_coverage_start(
{'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2013/07/GW1AM2_20130700_01M_EQMA_L3SGSSTLB3300300.h5'}),
datetime(year=2013, month=7, day=1, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_start_phy_001_024(self):
"""shall return the propert starting time for hardcoded normalizer """
self.assertEqual(
Expand Down Expand Up @@ -633,20 +619,6 @@ def test_time_coverage_end_ceda(self):
{'url': 'ftp://anon-ftp.ceda.ac.uk/neodc/esacci/sst/data/CDR_v2/Climatology/L4/v2.1/D365-ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_CDR2.1-v02.0-fv01.0.nc'}),
datetime(year=2010, month=12, day=31, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_end_jaxa_single_day_file(self):
"""shall return the propert end time for hardcoded normalizer """
self.assertEqual(
self.normalizer.get_time_coverage_end(
{'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2015/04/GW1AM2_20150401_01D_EQOD_L3SGSSTLB3300300.h5'}),
datetime(year=2015, month=4, day=2, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_end_jaxa_month_file(self):
"""shall return the propert end time for hardcoded normalizer """
self.assertEqual(
self.normalizer.get_time_coverage_end(
{'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2015/04/GW1AM2_20150400_01M_EQMD_L3SGSSTLB3300300.h5'}),
datetime(year=2015, month=5, day=1, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_time_coverage_end_phy_001_024(self):
"""shall return the propert starting time for hardcoded normalizer """
self.assertEqual(
Expand Down Expand Up @@ -819,20 +791,6 @@ def test_time_coverage_end_ibi_analysis_forecast_phys_005_001_monthly(self):
}),
datetime(year=2019, month=11, day=1, hour=0, minute=0, second=0, tzinfo=tzutc()))

def test_instrument_jaxa(self):
"""instrument from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_instrument(attributes),
OrderedDict([('Category', 'Earth Remote Sensing Instruments'),
('Class', 'Passive Remote Sensing'),
('Type', 'Spectrometers/Radiometers'),
('Subtype', 'Imaging Spectrometers/Radiometers'),
('Short_Name', 'AMSR2'),
('Long_Name', 'Advanced Microwave Scanning Radiometer 2')])
)

def test_instrument_ceda(self):
"""instrument from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -915,18 +873,6 @@ def test_instrument_ibi_analysis_forecast_phys_005_001(self):
('Long_Name', 'Computer')])
)

def test_platform_jaxa(self):
"""platform from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_platform(attributes),
OrderedDict([('Category', 'Earth Observation Satellites'),
('Series_Entity', ''),
('Short_Name', 'GCOM-W1'),
('Long_Name', 'Global Change Observation Mission 1st-Water')])
)

def test_platform_ceda(self):
"""platform from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -999,21 +945,6 @@ def test_platform_ibi_analysis_forecast_phys_005_001(self):



def test_provider_jaxa(self):
"""provider from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_provider(attributes),
OrderedDict([('Bucket_Level0', 'GOVERNMENT AGENCIES-NON-US'),
('Bucket_Level1', 'JAPAN'),
('Bucket_Level2', ''),
('Bucket_Level3', ''),
('Short_Name', 'JP/JAXA/EOC'),
('Long_Name', 'Earth Observation Center, Japan Aerospace Exploration Agency, Japan'),
('Data_Center_URL', 'http://www.eorc.jaxa.jp/en/index.html')])
)

def test_provider_ceda(self):
"""provider from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -1103,15 +1034,6 @@ def test_provider_ibi_analysis_forecast_phys_005_001(self):
)


def test_dataset_parameters_jaxa(self):
"""dataset_parameters from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_dataset_parameters(attributes),
[self.DATASET_PARAMETERS['sea_surface_temperature']]
)

def test_dataset_parameters_ceda(self):
"""dataset_parameters from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -1331,13 +1253,6 @@ def test_dataset_parameters_ibi_analysis_forecast_phys_005_001_monthly(self):
self.DATASET_PARAMETERS['sea_water_potential_temperature_at_sea_floor'],
])

def test_entry_title_jaxa(self):
"""entry_title from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_entry_title(attributes), 'AMSR2-L3 Sea Surface Temperature')

def test_entry_title_ceda(self):
"""entry_title from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -1382,13 +1297,6 @@ def test_entry_title_ibi_analysis_forecast_phys_005_001(self):
'Atlantic-Iberian Biscay Irish-Ocean Physics Analysis and Forecast'
)

def test_entry_id_jaxa(self):
"""entry_id from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_entry_id(attributes), 'GW1AM2_201207031905_134D_L2SGSSTLB3300300')

def test_entry_id_ceda(self):
"""entry_id from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -1455,22 +1363,6 @@ def test_entry_id_ibi_analysis_forecast_phys_005_001(self):
'CMEMS_v5r1_IBI_PHY_NRT_PdE_01hav3D_20210815_20210815_R20210816_HC01'
)

def test_geometry_jaxa_the_first_type_of_sst(self):
"""geometry from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_10/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_location_geometry(attributes),
'POLYGON((-180 -90, -180 90, 180 90, 180 -90, -180 -90))')

def test_geometry_jaxa_the_second_type_of_sst(self):
"""geometry from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25/3/2012/07/GW1AM2_201207031905_134D_L2SGSSTLB3300300.h5'}
self.assertEqual(
self.normalizer.get_location_geometry(attributes),
'POLYGON((-180 -90, -180 90, 180 90, 180 -90, -180 -90))')

def test_geometry_phy_001_024(self):
"""geometry from URLMetadataNormalizer """
attributes = {
Expand Down Expand Up @@ -1547,20 +1439,6 @@ def test_for_delivering_none_when_lacking_url_in_raw_attributes(self):
self.assertIsNone(self.normalizer.get_location_geometry({'none-url': 'ftp://test/'}))
self.assertIsNone(self.normalizer.get_entry_id({'none-url': 'ftp://test/'}))

def test_summary_jaxa_l2(self):
"""summary from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L2.SST'}
self.assertEqual(
self.normalizer.get_summary(attributes), 'Processing level: 2')

def test_summary_jaxa_l3(self):
"""summary from URLMetadataNormalizer """
attributes = {
'url': 'ftp://ftp.gportal.jaxa.jp/standard/GCOM-W/GCOM-W.AMSR2/L3.SST_25'}
self.assertEqual(
self.normalizer.get_summary(attributes), 'Processing level: 3')

def test_summary_ceda(self):
"""summary from URLMetadataNormalizer """
attributes = {
Expand Down

0 comments on commit 10b808c

Please sign in to comment.