mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
support crs in ncwrite, convert2nc functions
This commit is contained in:
parent
029fd0e63f
commit
260a7f20d6
@ -623,6 +623,13 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
|
||||
ucar.nc2.Variable pVar = null;
|
||||
int pvIdx = -1;
|
||||
for (ucar.nc2.Variable aVarS : ncVariables) {
|
||||
if (aVarS.getShortName().equalsIgnoreCase("crs")) {
|
||||
if (aVarS.findAttribute("proj4") != null) {
|
||||
pVar = aVarS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ucar.nc2.Attribute att = aVarS.findAttribute("grid_mapping_name");
|
||||
if (att != null) {
|
||||
pVar = aVarS;
|
||||
|
||||
@ -1,32 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\geotiff">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\geoshow"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\hdf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\awx"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grads"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
|
||||
<Path OpenPath="D:\Run\emips\run_chengdu">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\model"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\geotiff"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\hdf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\data_process"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\ascii"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataset"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
|
||||
<RecentFolder Folder="D:\Run\emips\run_chengdu"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\geoshow\geoshow_2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\Line2D_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_4.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\netcdf\ncwrite_crs_1.py"/>
|
||||
<OpenedFile File="D:\Run\emips\run_chengdu\run_pollutants_test_crs.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\map\geoshow\geoshow_2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\Line2D_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_4.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\netcdf\ncwrite_crs_1.py"/>
|
||||
<RecentFile File="D:\Run\emips\run_chengdu\run_pollutants_test_crs.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
|
||||
Binary file not shown.
@ -436,13 +436,14 @@ class DimDataFile(object):
|
||||
"""
|
||||
self.ncfile.create()
|
||||
|
||||
def nc_define(self, dims, gattrs, vars, write_dimvars=True):
|
||||
def nc_define(self, dims, gattrs, vars, write_dimvars=True, proj=None):
|
||||
"""
|
||||
Define dimensions, global attributes, variables of the netcdf file
|
||||
:param dims: (*list of Dimension*) The dimensions
|
||||
:param gattrs: (*list of Attribute*) The global attributes
|
||||
:param vars: (*list of DimVariable*) The variables
|
||||
:param write_dimvars: (*bool*) Write dimension variables value or not. Default is ``True``
|
||||
:param proj: (*ProjectionInfo*) Projection info.
|
||||
"""
|
||||
#Add dimensions
|
||||
ncdims = []
|
||||
@ -454,6 +455,12 @@ class DimDataFile(object):
|
||||
for key in gattrs:
|
||||
self.addgroupattr(key, gattrs[key])
|
||||
|
||||
#Add grid map variable
|
||||
if proj is not None:
|
||||
if not proj.isLonLat():
|
||||
var = self.addvar('crs', 'int', [])
|
||||
var.addattr('proj4', proj.toProj4String())
|
||||
|
||||
#Add dimension variables
|
||||
dimvars = []
|
||||
wdims = []
|
||||
|
||||
Binary file not shown.
@ -16,6 +16,7 @@ from org.meteoinfo.data.meteodata.bufr import BufrDataInfo
|
||||
from org.meteoinfo.data.meteodata.netcdf import NetCDFDataInfo
|
||||
from org.meteoinfo.data import TableUtil
|
||||
from org.meteoinfo.ndarray.math import ArrayUtil
|
||||
from org.meteoinfo.projection import ProjectionNames
|
||||
from ucar.nc2 import NetcdfFileWriter
|
||||
from ucar.nc2.iosp.bufr.tables import BufrTables
|
||||
|
||||
@ -654,7 +655,13 @@ def convert2nc(infn, outfn, version='netcdf3', writedimvar=False, largefile=Fals
|
||||
#Add global attributes
|
||||
for attr in f.attributes():
|
||||
ncfile.addgroupattr(attr.getName(), f.attrvalue(attr))
|
||||
|
||||
|
||||
#Add grid map variable
|
||||
if f.proj is not None:
|
||||
if not f.proj.isLonLat():
|
||||
var = ncfile.addvar('crs', 'int', [])
|
||||
var.addattr('proj4', proj.toProj4String())
|
||||
|
||||
#Add dimension variables
|
||||
tvar = None
|
||||
if writedimvar:
|
||||
@ -868,7 +875,7 @@ def dimension(dimvalue, dimname='null', dimtype=None):
|
||||
dim.setShortName(dimname)
|
||||
return dim
|
||||
|
||||
def ncwrite(fn, data, varname, dims=None, attrs=None, gattrs=None, largefile=False,
|
||||
def ncwrite(fn, data, varname, dims=None, attrs=None, gattrs=None, proj=None, largefile=False,
|
||||
version='netcdf3'):
|
||||
"""
|
||||
Write a netCDF data file from an array.
|
||||
@ -879,12 +886,14 @@ def ncwrite(fn, data, varname, dims=None, attrs=None, gattrs=None, largefile=Fal
|
||||
:param dims: (*list of dimensions*) Dimension list.
|
||||
:param attrs: (*dict*) Variable attributes.
|
||||
:param gattrs: (*dict*) Global attributes.
|
||||
:param proj: (*ProjectionInfo*) Projection info. Default is `None`, means long/lat projection.
|
||||
:param largefile: (*boolean*) Create netCDF as large file or not.
|
||||
:param version: (*str*) NetCDF version [netcdf3 | netcdf4].
|
||||
"""
|
||||
if dims is None:
|
||||
if isinstance(data, DimArray):
|
||||
dims = data.dims
|
||||
proj = data.proj
|
||||
else:
|
||||
dims = []
|
||||
for s in data.shape:
|
||||
@ -904,6 +913,13 @@ def ncwrite(fn, data, varname, dims=None, attrs=None, gattrs=None, largefile=Fal
|
||||
if not gattrs is None:
|
||||
for key in gattrs:
|
||||
ncfile.addgroupattr(key, gattrs[key])
|
||||
|
||||
#Add grid map variable
|
||||
if proj is not None:
|
||||
if not proj.isLonLat():
|
||||
var = ncfile.addvar('crs', 'int', [])
|
||||
var.addattr('proj4', proj.toProj4String())
|
||||
|
||||
#Add dimension variables
|
||||
dimvars = []
|
||||
wdims = []
|
||||
|
||||
@ -51,7 +51,7 @@ public enum ProjectionNames {
|
||||
|
||||
/**
|
||||
* Get proj4 name
|
||||
* @return Porj4 name
|
||||
* @return Proj4 name
|
||||
*/
|
||||
public String getProj4Name() {
|
||||
return this.proj4Name;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user