From 79377696a8472d95ac7d50bab33010972a8ec77e Mon Sep 17 00:00:00 2001 From: jacques Grelet <jacques.grelet@gmail.com> Date: Sun, 31 Mar 2019 22:11:44 +0000 Subject: [PATCH] don't work --- code_roscop.csv | 2 +- netcdf.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/code_roscop.csv b/code_roscop.csv index 1df8004..44a1172 100644 --- a/code_roscop.csv +++ b/code_roscop.csv @@ -4,7 +4,7 @@ PRLF;int32;profile number;;1;;;;;;%4d;99999;;;Station number, a station could be PROFILE;int32;profile number;;1;;;;;;%4d;99999;;;Station number, a station could be have more than one cast;;;;; LATITUDE;float32;latitude of measurement;latitude;degrees_north;;;;;;;;Y;;;;;;WGS84;urn:ogc:crs:EPSG::4326 LONGITUDE;float32;longitude of measurement;longitude;degrees_east;;;;;;;;X;;;;;;WGS84;urn:ogc:crs:EPSG::4327 -TIME;float64;time of measurement;time;days since 1950-01-01T00:00:00Z;Relative julian days with decimal part (as parts of the day);;;0;90000;%6.6d;;T;;;;;;; +TIME;float64;time of measurement;time;days since 1950-01-01T00:00:00Z;Relative julian days with decimal part (as parts of the day);;;0.0;90000.0;%6.6f;;T;;;;;;; ETDD;float32;ellapsed time;;1;;;;0;90000;%9.5f;;;;;;;;; DEPH;float32;depth of measurement;depth;meter;;;down;0;9000;%7.2f;1E+36;Z;;;;;;;urn:ogc:crs:EPSG::5831 DEPTH;float32;depth of measurement;depth;meter;;;down;0;9000;%7.2f;1E+36;Z;;;;;;;urn:ogc:crs:EPSG::5831 diff --git a/netcdf.py b/netcdf.py index c257828..5517fa3 100644 --- a/netcdf.py +++ b/netcdf.py @@ -7,8 +7,10 @@ from physicalParameter import Roscop def writeNetCDF(fileName, fe): data = {} - dims = ['TIME', 'LATITUDE', 'LONGITUDE', 'DEPTH'] - vars = dims.copy() + dims = ['TIME', 'LATITUDE', 'LONGITUDE'] + variables = dims.copy() + dims_4d = dims.copy() + dims_4d = dims_4d.append('DEPTH') # move to main after tests r = Roscop("code_roscop.csv") @@ -30,8 +32,10 @@ def writeNetCDF(fileName, fe): # create variables # add dimensions before variables list for k in fe.keys: - vars.append(k) - for key in vars: + variables.append(k) + # variables.extend(fe.keys()) + print(variables) + for key in variables: # for each variables get the attributes list hash = r.returnCode(key) # _FillValue attribute must be set when variable is created @@ -43,8 +47,13 @@ def writeNetCDF(fileName, fe): else: fillvalue = None # create the variable - data[key] = nc.createVariable( - key, dtype(hash['types']).char, dims, fill_value=fillvalue) + print(key) + if any(key in item for item in dims): + data[key] = nc.createVariable( + key, dtype(hash['types']).char, (key,), fill_value=fillvalue) + else: + data[key] = nc.createVariable( + key, dtype(hash['types']).char, dims_4d, fill_value=fillvalue) # remove from the dictionary hash.pop('types') # create dynamically variable attributes @@ -52,5 +61,5 @@ def writeNetCDF(fileName, fe): setattr(data[key], k, hash[k]) # debug - for key in vars: + for key in variables: print(data[key]) -- GitLab