Giter Club home page Giter Club logo

xcontour's Introduction

xcontour

DOI GitHub

diagnostic analyses in contour-based coordinate

1. Introduction

xcontour is a python package built on xarray (starts with an x), targeting at performing diagnostic analyses and calculations in contour-based coordinates. The new coordinates are built based on iso-surfaces of any quasi-conservative tracers (passive or active), mostly through a conservative rearrangement (or adiabatic sorting in a particular direction). Such rearrangement allows one to isolate the adiabatic advective process of a fluid and focus on non-conservative processes. Therefore, it simplifies the relavent dynamical view and interpretation of many phenomena.

The most well-known contour-based coordinates are 1) isentropic coordinate used in the atmosphere and 2) isopycnal coordinate used in the ocean, both of which are based on quasi-conservative variables of potential temperature and potential density. However, traditional coordinate transform requires a one-to-one relation between z-coordinate and isentropic/isopycnal surfaces. This can not be ensured in nonhydrostatic regions (heavier fluid is laid over lighter fluid). The adiabatic sorting process used here eliminates such constraint. For example, after the sorting in the vertical plane, the fluid will be completely stably stratified.

Basically, this package is usually used to accomplish the following tasks:

The calculations mostly take advantages of xarray's functionalities rather than writing explicit loops or algorithms, including contour-coordinate expansion, conditional accumulation or integration, coordinate transform and interpolation... One would see that xarray 1) supports multi-dimensional calculations, 2) simplifies a great deal of work in programming the very details, and 3) applies to different cases in a unified fashion.


2. How to install

Requirements xcontour is developed under the environment with numpy (=version 1.15.4), xarray (=version 0.15.1), xgcm(=version 0.5.2), and xhistogram(=version 0.3.0). Older versions of these packages are not well tested.

Install from github

git clone https://github.com/miniufo/xcontour.git

3. Examples

3.1 calculate effective diffusivity in the atmosphere

effective diffusivity

Here is a complete notebook example on Nakamura's effective diffusivity.

3.2 calculate local wave activiy in the atmosphere

local wave activity density

Here is a complete notebook example on local wave activity.

3.3 calculate local APE density in the ocean

local APE density

Here is a complete notebook example on local APE.

3.4 calculate tracer contour length in the ocean

contour length

Here is a complete notebook example on contour length.

xcontour's People

Contributors

mini-dong avatar miniufo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

xcontour's Issues

upper and lower area calculated from mask do not equal

This is raised by @AminFazlKazemi.

well If the equivalent latitude is chosen perfect, you can fill in values painted as light blue in white space below Equivalent Latitude so The resultant Adiabaticcaly sorted filed is produced.
I chose a mask output from your code corresponding e.g. Latitude=45 degrees North. Pixels are reclassied there with -1 ,+1 and zero. I then multiplied each pixel by its corresponding fractional area in squared kilometers.
If The choosing of Equivalent Latitude is perfect, then integrating area over pixels shown with +1 is exactly equals area over pixels shown with -1. Of course the resolution of dataset plays a role here.

I did not check this carefully. Maybe it is related to the discretized grid points or weights calculated in xgcm. But it needs to be double check.

I made a rough estimate as follows. Grid resolution is 0.7016754 degree. So the area of a grid point at 45°N is (0.7016754*111.11)**2*cos(45°), which is about 4297.32km^2. Similarly, area is 3039.13km^2 at 60N and 1029.35km^2 at 80.25N. It is reasonble to take this as the grid-scale error. I guess your unit of km^2 is wrong (should be m^2 for 10^12).

Also, how do you calculate the area? can you post your code snippet here? Maybe the algorithms are also somewhat different.

Error running LWA ipynb

Hi

Thanks for your beneficial repo. I just tried to run LWA jupyter notebook. I face these problems:
No module named 'xcontour.xcontour'
I resolved it by substituting from xcontour.xcontour import ... with from xcontour import ...

by the way when I run

dset, grid = add_latlon_metrics(dset)
I face :
NameError: name 'add_latlon_metrics' is not defined

Could you please help

error importing GeoApps.ConstUtils.deg2m

Hi

I am trying to run the LWA code.
I find it difficult install ing geoapps, even thought it is a great package. It seems only we are trying to convert LatLong grid to meters using GeoApps. Is there any problem to the code if we substitute GeoApps function?

for example:

a=6378137.
b=6356752.3
earth_radius=1000.*numpy.sqrt((numpy.power(a*a*numpy.cos(numpy.radians(lat)),2.)+numpy.power(b*b*numpy.sin(numpy.radians(lat)),2.))/(numpy.power(a*numpy.cos(numpy.radians(lat)),2.)+numpy.power(b*numpy.sin(numpy.radians(lat)),2.)))
deg2m=earth_radius*numpy.cos(numpy.radians(lat)) 

Local wave activity (LWA) v.s. local available potential energy (LAPE)

After a careful reading of those papers, especially Holliday and McIntyre (1981, JFM), McIntyre and Shepherd (1987, JFM), Roullet and Klein (2009, JFM), Kang and Fringer (2010, JPO), and Huang and Nakamura (2016, JAS), I am pretty sure that local available potential energy (LAPE) is an vertical equivalence to impulse-Casimir wave activity (ICWA) in the horizontal plane. In Huang and Nakamura (2016, JAS), ICWA, and hence LAPE, is clearly demonstrated to be different from local wave activity (LWA). However, in the vertical plane where stratification is usually strong enough to suppress vertical displacement, LWA is quite similar to LAPE in this small-amplitude limit.

So I need to change the calculation of local APE from that of LWA. Local APE is conceptually equivalent to ICWA.

isentropic LWA

This is raised by @AminFazlKazemi. Let's resolve it one by one.

Any way, I have also another request.
There is also another method for calculating LWA on isentropic surface :
Local Finite-Amplitude Wave Activity as a Diagnostic for Rossby Wave Packets
PAOLO GHINASSI, GEORGIOS FRAGKOULIDIS, AND VOLKMAR WIRTH
Institute for Atmospheric Physics, Johannes Gutenberg University Mainz,
Mainz, Germany
(Manuscript received 26 February 2018, in final form 20 August 2018)
DOI: 10.1175/MWR-D-18-0068.1.

I tried hard to modify you code to this end but in vain.
First : we need to equipartition dm = sigma * ds m being mass .
eqipartitioning of mass not area!
Second we need to integrate (q-Q) sigmads . It is necessary since
Isentropic coordinates will differ peressure sharply (maybe an isentrope is
very low altitude at equator and very high altitude at poles.
This isentropic calculation will add other properties to the resultant LWA.
I would be thankful if you can add this feature to your code.

I see your concern now. You are trying to find the equivalent latitude encompassing the same mass as associated PV contour. I read the Ghinassi's paper. I guess you can try:

  1. calculate a discretized mass-PV relation using cal_integral_within_contour, denoted as Mi(Qi);
  2. calculate a discretized mass-Lat relation also using cal_integral_within_contour denoted as Mi(Lati) (using latitude contours);
  3. Interpolate to remove Mi and get Lati(Qi).

The second point you raised is straighforward when you find Lati(Qi) through Eq. (8) in 2018 paper.

fractal contour length

It is interesting to integrate a function that calculates the length of tracer contour and the fractal dimension of it.

  • The length of a contour can be calculated using find_contours method in the skimage.measure package, which adopts a marching-cubes algorithm;
  • The fractal dimension can be calculated using box-counting algorithm.

This two methods will certainly enrich the xcontour package. Also, the returned results could be a function of equivalent latitudes.

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.