Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix projections in cf writer #307

Merged
merged 20 commits into from Jun 11, 2018
Merged

Fix projections in cf writer #307

merged 20 commits into from Jun 11, 2018

Conversation

mraspaud
Copy link
Member

@mraspaud mraspaud commented May 30, 2018

This PR fixes the cf writer with better support for some projection parameters

@@ -40,7 +40,65 @@
class TestCFWriter(unittest.TestCase):
def test_init(self):
from satpy.writers.cf_writer import CFWriter
w = CFWriter()
import satpy.config
w = CFWriter(config_files=[os.path.join(satpy.config.CONFIG_PATH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F841 local variable 'w' is assigned to but never used
W291 trailing whitespace

import satpy.config
w = CFWriter(config_files=[os.path.join(satpy.config.CONFIG_PATH,
'writers', 'cf.yaml')])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W293 blank line contains whitespace

'writers', 'cf.yaml')])


def test_save_array(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E303 too many blank lines (2)

import xarray as xr
import tempfile
scn = Scene()
scn['test-array'] = xr.DataArray([1,2,3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E231 missing whitespace after ','

scn.save_datasets(filename=filename, writer='cf')
import h5netcdf as nc4
f = nc4.File(filename)
self.assertTrue(all(f['test-array'][:] == [1,2,3]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E231 missing whitespace after ','

dtnp64 = dataarray['time'].data[0]
time_bnds = [(np.datetime64(start_time) - dtnp64),
(np.datetime64(end_time) - dtnp64)]
return xr.DataArray(np.array(time_bnds) / np.timedelta64(1, 's'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E271 multiple spaces after keyword
W291 trailing whitespace

(np.datetime64(end_time) - dtnp64)]
return xr.DataArray(np.array(time_bnds) / np.timedelta64(1, 's'),
dims=['time_bnds'], coords={'time_bnds': [0, 1]})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W293 blank line contains whitespace

datas[new_ds.attrs['name']] = self.da2cf(new_ds,
kwargs.get('epoch',
EPOCH))

dataset = xr.Dataset(datas)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W293 blank line contains whitespace


dataset = xr.Dataset(datas)

dataset = xr.Dataset(datas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

dataset = xr.Dataset(datas)

dataset = xr.Dataset(datas)
dataset['time_bnds'] = make_time_bounds(dataset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

@codecov
Copy link

codecov bot commented May 30, 2018

Codecov Report

Merging #307 into master will increase coverage by 1.34%.
The diff coverage is 92.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #307      +/-   ##
==========================================
+ Coverage   65.98%   67.33%   +1.34%     
==========================================
  Files         119      120       +1     
  Lines       14493    15471     +978     
==========================================
+ Hits         9563    10417     +854     
- Misses       4930     5054     +124
Impacted Files Coverage Δ
satpy/tests/writer_tests/__init__.py 92.3% <100%> (+0.64%) ⬆️
satpy/writers/cf_writer.py 67.18% <80.48%> (+67.18%) ⬆️
satpy/tests/writer_tests/test_cf.py 97.82% <98.7%> (+42.82%) ⬆️
satpy/composites/__init__.py 32.2% <0%> (-0.73%) ⬇️
satpy/tests/test_readers.py 98.09% <0%> (-0.29%) ⬇️
satpy/tests/reader_tests/test_ahi_hsd.py 91.89% <0%> (ø)
satpy/tests/reader_tests/__init__.py 96.66% <0%> (+0.23%) ⬆️
satpy/tests/test_writers.py 97.97% <0%> (+0.49%) ⬆️
satpy/readers/__init__.py 95.28% <0%> (+0.52%) ⬆️
satpy/readers/safe_msi.py 3.07% <0%> (+0.53%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93826db...4047077. Read the comment docs.

@coveralls
Copy link

coveralls commented May 30, 2018

Coverage Status

Coverage increased (+1.8%) to 67.783% when pulling 4047077 on fix-cf-writer into 93826db on master.

@mraspaud mraspaud added enhancement code enhancements, features, improvements component:writers labels May 31, 2018
@mraspaud mraspaud self-assigned this May 31, 2018
@mraspaud mraspaud merged commit 4f7e597 into master Jun 11, 2018
@mraspaud mraspaud deleted the fix-cf-writer branch June 11, 2018 06:47
end_times)
dataset['time'].attrs['bounds'] = "time_bnds"
except KeyError:
logger.warning('No time dimension in datasets, skipping time bounds creation.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be no time coordinate / no time variable? It doesn't seem to be specifically looking for a dimension (and still isn't with the refactoring to how this code is today). I think that having a time dimension is pretty rare in Satpy. The only way I can think of is either from a reader (maybe the GRIB reader?) or from a MultiScene with (mscn.blend(blend_function=timeseries)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:writers enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NetCDF writer doesn't work
4 participants