Skip to content

Commit

Permalink
Merge pull request #16 from metno/issue15_simplify
Browse files Browse the repository at this point in the history
Issue15 simplify
  • Loading branch information
mortenwh authored May 4, 2024
2 parents a877b44 + 17e8d10 commit 86fe95f
Show file tree
Hide file tree
Showing 32 changed files with 2,203 additions and 1,289 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
pyTestCov:
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
python-version: [3.8, 3.9, '3.10', '3.11']
runs-on: ubuntu-latest
steps:
- name: Python Setup
Expand All @@ -24,13 +24,12 @@ jobs:
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install gdal-bin libgdal-dev
pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-timeout
pip install pytest-cov
pip install pytest-mock
- name: Run Tests
run: python -m pytest -v -m unittests --cov=sarwind --timeout=120
run: python -m pytest -v --cov=sarwind --timeout=120
- name: Upload to Codecov
uses: codecov/codecov-action@v3
231 changes: 0 additions & 231 deletions broker.py

This file was deleted.

8 changes: 0 additions & 8 deletions config.json

This file was deleted.

6 changes: 5 additions & 1 deletion nansat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ dependencies:
- parallel=20211022=ha770c72_0
- paramiko=2.8.0=pyhd8ed1ab_0
- parmap=1.5.3=pyhd8ed1ab_0
- parso=0.8.2=pyhd8ed1ab_0
- partd=1.2.0=pyhd8ed1ab_0
- pathspec=0.10.3=pyhd8ed1ab_0
- pcre=8.45=h9c3ff4c_0
Expand Down Expand Up @@ -272,3 +271,8 @@ dependencies:
- zipp=3.6.0=pyhd8ed1ab_0
- zlib=1.2.11=h36c2ea0_1013
- zstd=1.4.9=ha95c52a_0
- pip:
- xdg
- pytest
- pytest-cov
- ipdb
Empty file added nansat_mappers/__init__.py
Empty file.
88 changes: 88 additions & 0 deletions nansat_mappers/mapper_sarwind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import netCDF4

import numpy as np

from nansat.exceptions import WrongMapperError
from nansat.vrt import VRT


class Mapper(VRT):

def __init__(self, filename, gdal_dataset, metadata, *args, **kwargs):

try:
ds = netCDF4.Dataset(filename)
except OSError:
raise WrongMapperError
if "title" not in ds.ncattrs():
raise WrongMapperError
else:
if "urface wind" not in ds.title or "NRCS" not in ds.title:
raise WrongMapperError
longitude = ds['longitude'][:].data
latitude = ds['latitude'][:].data
for attr in ds.ncattrs():
content = ds.getncattr(attr)
metadata[attr] = content
super(Mapper, self)._init_from_lonlat(longitude, latitude)

# Get rid of GDAL additions to metadata keys
metadata = VRT._remove_strings_in_metadata_keys(metadata, ['NC_GLOBAL#', 'GDAL_'])
self.dataset.SetMetadata(metadata)
self.band_vrts = {
"wind_direction": VRT.from_array(ds["wind_direction"][:].filled(fill_value=np.nan)),
"look_relative_wind_direction": VRT.from_array(
ds["look_relative_wind_direction"][:].filled(fill_value=np.nan)),
"windspeed": VRT.from_array(ds["windspeed"][:].filled(fill_value=np.nan)),
"model_windspeed": VRT.from_array(ds["model_windspeed"][:].filled(fill_value=np.nan)),
}

metaDict = []

wdir_metadict = {}
for attr in ds["wind_direction"].ncattrs():
wdir_metadict[attr] = ds["wind_direction"].getncattr(attr)
metaDict.append({
'src': {
'SourceFilename': self.band_vrts["wind_direction"].filename,
'SourceBand': 1
},
'dst': wdir_metadict,
})

lookrel_metadict = {}
for attr in ds["look_relative_wind_direction"].ncattrs():
lookrel_metadict[attr] = ds["look_relative_wind_direction"].getncattr(attr)
metaDict.append({
'src': {
'SourceFilename': self.band_vrts["look_relative_wind_direction"].filename,
'SourceBand': 1
},
'dst': lookrel_metadict,
})

wspeed_metadict = {}
for attr in ds["windspeed"].ncattrs():
wspeed_metadict[attr] = ds["windspeed"].getncattr(attr)
metaDict.append({
'src': {
'SourceFilename': self.band_vrts["windspeed"].filename,
'SourceBand': 1
},
'dst': wspeed_metadict,
})

mwspeed_metadict = {}
for attr in ds["model_windspeed"].ncattrs():
mwspeed_metadict[attr] = ds["model_windspeed"].getncattr(attr)
metaDict.append({
'src': {
'SourceFilename': self.band_vrts["model_windspeed"].filename,
'SourceBand': 1
},
'dst': mwspeed_metadict,
})

self.create_bands(metaDict)

self.fix_global_metadata
Loading

0 comments on commit 86fe95f

Please sign in to comment.