GithubHelp home page GithubHelp logo

xgrads.core about xgrads HOT 20 CLOSED

miniufo avatar miniufo commented on June 1, 2024
xgrads.core

from xgrads.

Comments (20)

miniufo avatar miniufo commented on June 1, 2024 1

Maybe you did not install the package. That is also fine. You can:

import sys
sys.path.append('/absolute/path/to/your/xgrads/folder')
from xgrads import open_CtlDataset

from xgrads.

miniufo avatar miniufo commented on June 1, 2024 1

Try this:

dset ^IVT0-Copy.dat
title IVT0 data
undef -9.99e33
xdef 101 linear -20 1
ydef 61 linear -10 1
zdef   1 linear 0 1
tdef   1 linear 01Jan2000 1dy
vars 1
IVT0 0 99 comment
endvars

zdef, tdef, and vars 1 cannot be missing. The rule is that, the ctl and binary data can be opened by GrADS. Sometimes, people write their own (incorrect) ctl may not correctly parsed by GrADS, and hence xgrads.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024 1

xgrads is just for loading data into memory, not fully reproduce GrADS' plot functionalities. But you can use matplotlib for plotting, which is most popular in python.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024 1

Of course yes. If your ctl is associated with a 4D dataset (time, lev, lat, lon), you can open it and play with 4D variables.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024 1

When you load your dataset (end with .ctl) as dset, it is already a xarray.Dataset.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024 1

Yes, you should import xarray as xr and call functions in it to help you. xarray is the data struct you play with, while xgrads is an input/output tool.

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

Thanks a lot. I omitted .core, and it worked for test files.
Now I have a binary file that is 85th percentile of 40 binary files by one variable. I want to open this file and I wrote this ctl file for it, but it does not work or plot it.
ctl:
dset IVT0-Copy.dat
title IVT0 data
undef -9.99e33
xdef 101 linear -20 1
ydef 61 linear -10 1
IVT0 0 99
endvars

from xgrads import open_CtlDataset
dset = open_CtlDataset('E:/dissertation/Code/code2/ivt/Prog/output/IVT0out/IVT0-Copy.ctl')

print all the info in ctl file

print(dset)

for your ctl content, you can plot any variables (e.g.,

first time and level of T) immediately as

dset['IVT0'][-20,-10,...].plot()
13

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

Thanks a lot for your help!
I need a 3d plot for lon, lat and the variable should display in Z. Is it available in xgrads? something like plot_surface on matplotlib.
And for comparing I should put data in a variable. Is there any method to use lon, lat and IVT in diferent times(t) in a array on xgrads?

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

Thanks a million !!!!
How I can use data on memory in a variable?
May I use open-ctldataset to load data in a 3d variable?

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

Many thanks, I opened all of my files by xgrads, and now is there any way to compare these datasets?

I have a threshold in a dataset :
dset ^IVT0-Copy.dat
title IVT0 data
undef -9.99e33
xdef 101 linear -20 1
ydef 61 linear -10 1
zdef 1 linear 0 1
tdef 1 linear 01Jan2000 1dy
vars 1
IVT0 0 99 comment
endvars

and 40 datasets as like as below:
dset E:/dissertation/Code/code2/ivt/Prog/output/IVT0out/IVT_1980.dat
title IVT data
undef -9.99e33
xdef 101 linear -20 1
ydef 61 linear -10 1
zdef 4 linear 0 1
tdef 852 linear 01Nov1979 6hr
vars 1
IVT 0 99
endvars,

I want to compare each tdef with the threshold dataset. Is there any command to compare datasets?
Thank you so much in advance, if you can introduce a method in a library to compare these kinds of datasets?

from xgrads.

miniufo avatar miniufo commented on June 1, 2024

I don't know what you want to do. What do you mean by compare datasets? Compare tdef with a dataset? What does that mean? If you want to compare time steps with a reference time, you can just do

print(tdef[0] > ds_threshold.tdef[0])

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

from xgrads.

miniufo avatar miniufo commented on June 1, 2024

I don't think it is possible to modify all the times of a dataset as 0, because it is a coordinate that should be monotonic increasing or decreasing. But you can assign the whole tdef with a new series of times that you are happy with.

By the way, == is not a valid assignment, should be =.

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

"=" is not accepted.
I have a dataset. It has just one tdef. I call it IVT0.

There is another dataset,IVT , It has 855 tdefs.

Now, in new step, I want to compare each tdef in IVT to IVT0. Grade by grade in the grid (lon and lot).

for p in range(0,855,1):

if dset1['IVT'][p,...,...].any() >= dset['IVT0'][0].any():
dset1['IVT'][p,...,...].any() == dset['IVT'][p].any();
else:
dset1['IVT'][p,...].any()==0
print('dset==0',p)
p=p+1

Overall, I want to make a new dataset that every grade value has changed after 'for', and use the new one.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024

You can do if, and if true, assign new series of tdefs to the coordinates. You may want to search 'how to modify coordinates in xarray' in google.

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

At first step, I should load dataset to xarray in python. How I can open my dataset in xarray. I found "dataset to array" but it didnot work.

from xgrads.

miniufo avatar miniufo commented on June 1, 2024

After a quick look at previous posts, I guess you want to combine 40 datasets into a single one, right? So you have 40 ctls and want to load them all into memory?

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

I think I could not explain it well. I have a dataset that I want to use it as a threshold and I loaded it as "dset".

There are 40 datasets, that every one has 855 tdef. I want to compare the value of each dataset in each tdef with the value of dset and make new dataset to apply more condition.
I think I should open my file in xarray to compare and change some arraies.
How I can load my dataset in xarray?

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

So I should import xarray library and in the following I can use its commands for all of my datasets?

from xgrads.

FaeghPazhooh avatar FaeghPazhooh commented on June 1, 2024

Thanks a million

from xgrads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.