⚲
Project
General
Profile
Sign in
Register
Home
Projects
Imprint + Privacy Policy
Help
Search
:
CDO
All Projects
CDO
Overview
Activity
News
Wiki
Forums
Files
Documentation
Download (640 Bytes)
RE: Need help converting ascii to netcdf files
» txt2nc.py
python script to create the nc file -
Ralf Mueller
, 2015-09-11 12:19
import
numpy
as
np
from
netCDF4
import
Dataset
root
=
Dataset
(
'
fromTxt.nc
'
,
'
w
'
,
format
=
'
NETCDF4
'
)
root
.
description
=
'
Example text input via numpy and netCDF4
'
root
.
createDimension
(
'
lon
'
,
866
)
root
.
createDimension
(
'
lat
'
,
654
)
latitudes
=
root
.
createVariable
(
'
lat
'
,
'
f4
'
,
(
'
lat
'
,))
langitudes
=
root
.
createVariable
(
'
lon
'
,
'
f4
'
,
(
'
lon
'
,))
temp
=
root
.
createVariable
(
'
temp
'
,
'
f4
'
,
(
'
lat
'
,
'
lon
'
,),
fill_value
=-
9999
)
lats
=
np
.
arange
(
-
90
,
90
,
0.2
)
len
(
lats
)
lons
=
np
.
arange
(
-
180
,
180
,
0.4
)
len
(
lons
)
len
(
lats
[
0
:
700
])
latitudes
[:]
=
lats
[
0
:
654
]
langitudes
[:]
=
lons
[
0
:
866
]
f
=
open
(
"
in.txt
"
)
a
=
np
.
loadtxt
(
f
)
temp
[:,:]
=
a
[:,:]
root
.
close
()
latitudes
« Previous
1
2
3
Next »
(3-3/3)
Loading...