Read multiple netCDF4 using Python 3Extract single datapoint from netCDF file in R using ndcfUsing netCDF4 Python climate algorithm?Read HDF4 data using pythonCalculating Climate Suitable Days using netCDF4 and Python?Extracting Multivalues to Points from NETCDF4 Raster using ArcPy seems imprecise?Using python and ArcPy to read multiple files, apply a function and write into new a directryHow can I use GDAL Merge with multiple files in one folder in python 2.7?Combining multiple netcdf in folder in RCan't import shapefile in Pythonpython-netcdf4: Writing file leaves CRS as 'undefined' and extent not correct
How to make particles emit from certain parts of a 3D object?
What is the offset in a seaplane's hull?
Is there a familial term for apples and pears?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Extreme, but not acceptable situation and I can't start the work tomorrow morning
Add an angle to a sphere
COUNT(*) or MAX(id) - which is faster?
Ideas for 3rd eye abilities
What happens when a metallic dragon and a chromatic dragon mate?
Symmetry in quantum mechanics
Could Giant Ground Sloths have been a good pack animal for the ancient Mayans?
aging parents with no investments
"My colleague's body is amazing"
Copycat chess is back
Where to refill my bottle in India?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Is there a name of the flying bionic bird?
How can I add custom success page
Does it makes sense to buy a new cycle to learn riding?
Why is the design of haulage companies so “special”?
Does the average primeness of natural numbers tend to zero?
What causes the sudden spool-up sound from an F-16 when enabling afterburner?
Finding files for which a command fails
extract characters between two commas?
Read multiple netCDF4 using Python 3
Extract single datapoint from netCDF file in R using ndcfUsing netCDF4 Python climate algorithm?Read HDF4 data using pythonCalculating Climate Suitable Days using netCDF4 and Python?Extracting Multivalues to Points from NETCDF4 Raster using ArcPy seems imprecise?Using python and ArcPy to read multiple files, apply a function and write into new a directryHow can I use GDAL Merge with multiple files in one folder in python 2.7?Combining multiple netcdf in folder in RCan't import shapefile in Pythonpython-netcdf4: Writing file leaves CRS as 'undefined' and extent not correct
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to read a multiple netCDF4 files using python 3. The files are in different folder named 2019, 2018 with months and days. And the files have the same variables I use to read and plot it.
I can do that just for one file. How I can read all files and variable IR
in all files in all folder?
path='/home/all/2019/03/25/Mmult_201903250000.nc'
nc = netCDF4.Dataset('/home/all/2019/03/25/Mmult_201903250000.nc')
IR=nc.variables['IR'][:]
plt.pcolormesh(IR)
plt.colorbar()
plt.show()
python netcdf
New contributor
add a comment |
I need to read a multiple netCDF4 files using python 3. The files are in different folder named 2019, 2018 with months and days. And the files have the same variables I use to read and plot it.
I can do that just for one file. How I can read all files and variable IR
in all files in all folder?
path='/home/all/2019/03/25/Mmult_201903250000.nc'
nc = netCDF4.Dataset('/home/all/2019/03/25/Mmult_201903250000.nc')
IR=nc.variables['IR'][:]
plt.pcolormesh(IR)
plt.colorbar()
plt.show()
python netcdf
New contributor
add a comment |
I need to read a multiple netCDF4 files using python 3. The files are in different folder named 2019, 2018 with months and days. And the files have the same variables I use to read and plot it.
I can do that just for one file. How I can read all files and variable IR
in all files in all folder?
path='/home/all/2019/03/25/Mmult_201903250000.nc'
nc = netCDF4.Dataset('/home/all/2019/03/25/Mmult_201903250000.nc')
IR=nc.variables['IR'][:]
plt.pcolormesh(IR)
plt.colorbar()
plt.show()
python netcdf
New contributor
I need to read a multiple netCDF4 files using python 3. The files are in different folder named 2019, 2018 with months and days. And the files have the same variables I use to read and plot it.
I can do that just for one file. How I can read all files and variable IR
in all files in all folder?
path='/home/all/2019/03/25/Mmult_201903250000.nc'
nc = netCDF4.Dataset('/home/all/2019/03/25/Mmult_201903250000.nc')
IR=nc.variables['IR'][:]
plt.pcolormesh(IR)
plt.colorbar()
plt.show()
python netcdf
python netcdf
New contributor
New contributor
edited Apr 4 at 8:28
Kadir Şahbaz
4,60221531
4,60221531
New contributor
asked Apr 4 at 8:12
Sarah TohamiSarah Tohami
11
11
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use the glob.glob module to search all the nc-files in your sub-folder like this (taken from https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module):
import glob
list_of_paths = glob.glob('C:/Users/sam/Desktop/myfolder/**/*.nc', recursive=True)
Then, if there is a dimension in your netcdfs that is unlimited, you can open all the files in one line like this:
import netCDF4
nc = netCDF4.MFDataset(list_of_paths)
After this you will probably want to be carefull, because doing:
IR=nc.variables['IR'][:]
will load the 'IR'-data from ALL your nc-files into your memory at once, which could crash you computer. So it's probably better to load small parts at a time by replacing [:] with, for example, [0:2].
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension
– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
|
show 3 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sarah Tohami is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317735%2fread-multiple-netcdf4-using-python-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the glob.glob module to search all the nc-files in your sub-folder like this (taken from https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module):
import glob
list_of_paths = glob.glob('C:/Users/sam/Desktop/myfolder/**/*.nc', recursive=True)
Then, if there is a dimension in your netcdfs that is unlimited, you can open all the files in one line like this:
import netCDF4
nc = netCDF4.MFDataset(list_of_paths)
After this you will probably want to be carefull, because doing:
IR=nc.variables['IR'][:]
will load the 'IR'-data from ALL your nc-files into your memory at once, which could crash you computer. So it's probably better to load small parts at a time by replacing [:] with, for example, [0:2].
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension
– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
|
show 3 more comments
You can use the glob.glob module to search all the nc-files in your sub-folder like this (taken from https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module):
import glob
list_of_paths = glob.glob('C:/Users/sam/Desktop/myfolder/**/*.nc', recursive=True)
Then, if there is a dimension in your netcdfs that is unlimited, you can open all the files in one line like this:
import netCDF4
nc = netCDF4.MFDataset(list_of_paths)
After this you will probably want to be carefull, because doing:
IR=nc.variables['IR'][:]
will load the 'IR'-data from ALL your nc-files into your memory at once, which could crash you computer. So it's probably better to load small parts at a time by replacing [:] with, for example, [0:2].
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension
– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
|
show 3 more comments
You can use the glob.glob module to search all the nc-files in your sub-folder like this (taken from https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module):
import glob
list_of_paths = glob.glob('C:/Users/sam/Desktop/myfolder/**/*.nc', recursive=True)
Then, if there is a dimension in your netcdfs that is unlimited, you can open all the files in one line like this:
import netCDF4
nc = netCDF4.MFDataset(list_of_paths)
After this you will probably want to be carefull, because doing:
IR=nc.variables['IR'][:]
will load the 'IR'-data from ALL your nc-files into your memory at once, which could crash you computer. So it's probably better to load small parts at a time by replacing [:] with, for example, [0:2].
You can use the glob.glob module to search all the nc-files in your sub-folder like this (taken from https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module):
import glob
list_of_paths = glob.glob('C:/Users/sam/Desktop/myfolder/**/*.nc', recursive=True)
Then, if there is a dimension in your netcdfs that is unlimited, you can open all the files in one line like this:
import netCDF4
nc = netCDF4.MFDataset(list_of_paths)
After this you will probably want to be carefull, because doing:
IR=nc.variables['IR'][:]
will load the 'IR'-data from ALL your nc-files into your memory at once, which could crash you computer. So it's probably better to load small parts at a time by replacing [:] with, for example, [0:2].
answered Apr 4 at 8:52
Bert CoerverBert Coerver
708310
708310
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension
– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
|
show 3 more comments
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension
– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
thanks u but what mean [0:2] my problem that i have a simple application wxpython when i have button this button for select file in directory netcdf file i want to open so after open i want plot it so i will try ... but please what mean [0:2] ? exist method to open the file i want and plot it ?
– Sarah Tohami
Apr 4 at 9:44
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
i have question we can use loop for and loop for for variables keys ?
– Sarah Tohami
Apr 4 at 9:49
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
that is imformations about my variable IR in file netCDF4._netCDF4.Variable'> int16 IR_108(ny, nx) Offset : radiance = offset + CN x slope: -10.456819486590666 Slope : radiance = offset + CN x slope: 0.2050356762076601 unlimited dimensions: current shape = (3712, 3712) filling on
– Sarah Tohami
Apr 4 at 11:33
when i do :
import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension– Sarah Tohami
Apr 5 at 7:15
when i do :
import numpy as np import netCDF4 import matplotlib.pyplot as plt import glob list_of_paths = glob.glob('/home/all/2019/03/25/*.nc', recursive=True)nc = netCDF4.MFDataset(list_of_paths) IR=nc.variables['IR'][0:1]
i had error like : name 'nc' is not defined In [15]: nc = netCDF4.MFDataset(list_of_paths) --------------------------------------------------------------------------- OSError: dataset /homm/all/msg04/all/2019/03/25/Mmulti_201903252000.nc does not have a aggregation dimension– Sarah Tohami
Apr 5 at 7:15
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
ok then you'll have to use "netCDF4.Dataset" instead of "netCDF4.MFDataset" and load a single nc-file at a time. So you need to make a for-loop on the list_of_paths
– Bert Coerver
Apr 5 at 7:30
|
show 3 more comments
Sarah Tohami is a new contributor. Be nice, and check out our Code of Conduct.
Sarah Tohami is a new contributor. Be nice, and check out our Code of Conduct.
Sarah Tohami is a new contributor. Be nice, and check out our Code of Conduct.
Sarah Tohami is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317735%2fread-multiple-netcdf4-using-python-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown