# Earth's CO2 level is increasing. Julia code to plot it yourself

**URL:** https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356
**Category:** Offtopic
**Tags:** plotting
**Created:** [June 8, 2024, 7:32am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356 "2024-06-08T07:32:43Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [June 8, 2024, 7:32am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/1 "2024-06-08T07:32:43Z")

</div>

URL: [Carbon dioxide levels in the atmosphere are surging "faster than ever" to beyond anything humans ever experienced, officials say - CBS News](https://www.cbsnews.com/news/carbon-dioxide-levels-surging-faster-than-ever-noaa-scientists/)

Here is Julia code to plot your own CO2 charts

```julia
using CSV, Plots, Downloads
# using MovingAverage 
using EasyFit

println("Program carbon.jl")

# mainurl: https://gml.noaa.gov/ccgg/trends/data.html
url = "https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.csv"

f = CSV.File(Downloads.download(url),header=0;skipto=42);

yeararr = collect(Float64,f.Column3)
co2arr = collect(Float64,f.Column4)
# normco2arr = f.Column5

# Plot defaults
default(size=(800,600),linewidth=2.0)

plot(yeararr,co2arr,title="Historical CO2",
    legend=false) |> display
#co2MAarr = moving_average(co2arr,12)

# Define our EasyFit.moveavg function
easymovingavg(arr,n)=(EasyFit.movavg(arr,n)).x

co2MAarr2 = easymovingavg(co2arr,12)
plot(yeararr,co2MAarr2,title="Annual Moving Average of CO2",
    legend=false)
#plot!(yeararr,co2MAarr2) |> display
logco2MAarr = map(x->log(10,x),co2MAarr2)
plot(yeararr,logco2MAarr,title="Log10 of Annual Moving Average of CO2",
    legend=false) |> display

plot(yeararr,co2arr)
plot!(yeararr,co2MAarr2,title="Annual CO2",
    legend=false) |> display

# The 11th element of yeararr is the start of year 1959
# June of 1959 is (11+5)th element
# the average co2 value of 1959 is co2MAarr[(11+5)]

# Create array for average yearly co2 concentration
yearly1959co2arr = Float64[]
totalnumofyears = div((length(yeararr)-(11-1)),12)
let k # runs faster in local scope
    for k = 0:(totalnumofyears - 1)
        push!(yearly1959co2arr,co2MAarr2[(11+5)+(k*12)])
    end
end

# Create array for yearly increment of co2
yearlyco2inc = similar(yearly1959co2arr)
let k # runs faster in local scope
    for k = 1:length(yearlyco2inc)
        if k == 1
            yearlyco2inc[k] = 0.0
        else
            yearlyco2inc[k] = yearly1959co2arr[k] - yearly1959co2arr[k-1]
        end
    end
end
plot(1959:(1959+(totalnumofyears-1)),yearlyco2inc,
    title="Annual increment of CO2",legend=false) |> display

yearly1960co2incarr = yearlyco2inc[2:end]

fiveyearincarr = Float64[]
let k
    for k = 0:(div(length(yearly1960co2incarr),5)-1)
        push!(fiveyearincarr,+(yearly1960co2incarr[(1+k*5):(5+k*5)]...))
    end
end
bar(0:(div(length(yearly1960co2incarr),5)-1),fiveyearincarr,
    yrange=(0.0,max(fiveyearincarr...) * 1.1),legend=false,
    title="Five years CO2 increment") |> display

```

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 8, 2024, 9:35am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/2 "2024-06-08T09:35:47Z")

</div>

Thanks for sharing!

The CO2 levels are rising, and extreme weather events are becoming more and more frequent: In Germany we already had the second large flood this year, two dikes broke and four people died. But in poor contries who contributed least to the emmissions these extreme weather events cause a lot more suffering.

In Kenya 267 people died due to floods and thousands lost their homes. There are now more than 281 000 displaced people. I created a fundraiser to support a group of the people who lost their homes: [Fundraiser by Uwe Fechner : Flood in Kenya - Emergency relief](https://gofund.me/ca077210)

Please, support!

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [June 8, 2024, 1:58pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/3 "2024-06-08T13:58:20Z")

</div>

It seems that [scientists using high-resolution satellite images](https://www.pnas.org/doi/full/10.1073/pnas.2011160118) found that fires in sub-Saharan Africa were responsible for emissions accounting for around 15% of global CO2 emissions from the burning of fossil fuels. They concluded that small fires are of crucial importance in characterizing the most important disruptive agent on a global scale.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 8, 2024, 2:21pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/4 "2024-06-08T14:21:45Z")

</div>

Thanks for sharing! A colleague of mine commented:

Fire is an integral part of land management in many areas. Known as shifting cultivation. It’s a way to maintain soil fertility. As long as total area of land under this regime does not increase, this is essentially a net-zero emissions practice on time scales of 5-10 years. Relevant for carbon budgeting, but not relevant as a major driver of climate change

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [June 8, 2024, 4:09pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/5 "2024-06-08T16:09:18Z")

</div>

This is probably a bad assumption, because as the sub-Saharan population increases significantly, the need for land also increases, as does deforestation.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [June 8, 2024, 4:56pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/6 "2024-06-08T16:56:54Z")

</div>

> [@rafael.guerra](#):
>
> It seems that [scientists using high-resolution satellite images](https://www.pnas.org/doi/full/10.1073/pnas.2011160118)

Cool GMT figures.

> [@ufechner7](#):
>
> It’s a way to maintain soil fertility.

In my experience over the years with ashes from my fireplace, this is a myth.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [June 8, 2024, 5:21pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/7 "2024-06-08T17:21:17Z")

</div>

BTW, for many hears that we have [that example](https://docs.generic-mapping-tools.org/dev/gallery/ex45.html) (the keeling curve) in our GMT gallery

The GMT.jl however had some issues with it that I just fixed (still in master only) and now we can also do

```julia
using GMT

D = gmtread(https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.txt, i="2,3");
model = trend1d(D, output=:xmr, model="p2,f1+o1958+l1");
plot(D, ms=0.05, fill=:red)
plot!(model, pen=(0.25,:blue))
text!(mat2ds("m@-5@-(t) = a + b@~\\327@~t + c@~\\327@~t@+2@+ + d@~\\327@~cos(2@~p@~t) + e@~\\327@~sin(2@~p@~t)"),
      font=12, region_justify=:TL, offset=(away=true, shift=0.25), fill=:lightyellow, show=1)

```

 ![GMTjl_j](https://global.discourse-cdn.com/julialang/original/3X/7/f/7f1a20b7254badabedd4f35030cb05a4de8bf4a1.png)

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 8, 2024, 5:34pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/8 "2024-06-08T17:34:08Z")

</div>

Reply to your reply from a friend of me who is prof in Amsterdam:

It’s a matter of perspective. These fire systems are very well adapted to local conditions and replacing them with anything else tends to lead to desertification, erosion, and negative livelihood outcomes for most. Obviously as more people rely on this system, it intensifies and/or expands. But that’s not a problem of shifting cultivation specifically. having worked in these landscapes, I find that the real damage is done by the monocrop plantations that encroach on them. And that’s something we can actually do something meaningful about, while population increase is not and should not be.

---

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [June 8, 2024, 9:00pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/9 "2024-06-08T21:00:45Z")

</div>

And yet [xkcd: Greenhouse Effect](https://xkcd.com/2889/) …

---

<div class="post-metadata">

### Author: ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)
#### Post date: [June 9, 2024, 1:19am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/10 "2024-06-09T01:19:57Z")

</div>

And lest we be too [fearful…](https://alexepstein.substack.com/p/why-you-shouldnt-be-alarmed-about) Cold kills more people each year than heat.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 9, 2024, 4:17am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/11 "2024-06-09T04:17:36Z")

</div>

> [@Jake](#):
>
> Cold kills more people each year than heat.

It is more complicated than that: [Which Kills More People: Extreme Heat or Extreme Cold? | Weather Underground](https://www.wunderground.com/cat6/Which-Kills-More-People-Extreme-Heat-or-Extreme-Cold)

“However, this study [did not control](https://www.skepticalscience.com/open-letter-to-wsj-scientist-response-to-misleading-lomborg.html) for the seasonal cycle in death rates; deaths are always higher in winter, due to influenza and other non-weather-related factors.”

Or read the last message from the UN Secretaries General on this topic: [Leaders ‘Must Step Up and Act — Now’ to Address Climate Change, Says Secretary-General, in Message on Launch of Global Report | Meetings Coverage and Press Releases](https://press.un.org/en/2024/sgsm22168.doc.htm)

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [June 9, 2024, 5:59am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/12 "2024-06-09T05:59:09Z")

</div>

for some reason, I lost connection to government website

```julia
PING gml.noaa.gov (140.172.200.41): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C
--- gml.noaa.gov ping statistics ---
5 packets transmitted, 0 packets received, 100.0% packet loss

$ date -u
Sun 9 Jun 2024 05:59:21 UTC

```

 ![problem](https://global.discourse-cdn.com/julialang/original/3X/0/7/07e77111c2b8e62102c3fa14e321abd9dbb77ebd.jpeg)

---

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [June 9, 2024, 10:41am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/13 "2024-06-09T10:41:49Z")

</div>

> [@ufechner7](#):
>
> deaths are always higher in winter, due to influenza and other non-weather-related factors.

But it is because it is cold in winter - what else? Or should it be the positions of the stars on the sky, which facilitate the virus spread?

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [June 9, 2024, 10:51am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/14 "2024-06-09T10:51:39Z")

</div>

I think that the precise reason is not known at this point. The fact that people breath the same air in closed room is indeed (indirectly) linked to the temperature.

---

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [June 9, 2024, 11:18am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/15 "2024-06-09T11:18:39Z")

</div>

Yes, in most case the cold action is indirect: Hypothermia as the recorded cause of death is probably a rare case. Just there are lot of ways how cold weather may act, be it having to stay at home, be it accidents on ice. Getting a meaningful statistics here is difficult, especially if the topic is highly political (and it is).

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 9, 2024, 5:34pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/16 "2024-06-09T17:34:42Z")

</div>

**Sometimes 50 degree Celsius (122 °Fahrenheit) in India and Pakistan**

How do people cope with this heat?

It feels like living in hell, says a young Pakistani. The sun is burning holes in his back, says an Indian supplier. Scenes from a world that is too hot.

Temperatures of more than 40 °C (104 °F) are not unusual in South Asia at this time of year. Recently, however, heat records have been broken at several locations in the region, with temperatures reaching over 50 °C (122 °F).

During this heat, India recently held its parliamentary elections: Almost one billion people were called to the polls on various days. There were repeated reports of heatstrokes, some of which were fatal: In the state of Uttar Pradesh, _33 election workers died on a single day,_ local media reported, citing official figures.

The authorities called on people to avoid the heat outside as much as possible. But food delivery man Vijay Kumar Singh has no choice. He rides his motorcycle around the Delhi metropolitan region every day in the dry heat. Sometimes the seat heats up so much that he has to put a cloth on it and wrap his hands with scraps of cloth, he says: “When I wait outside doors in the blazing sun, I can feel it burning holes in my back.”

Even at night, the temperature never drops below 30 °C (86 °F) these days. And in his room, which he shares with two other men, there is only one window and a fan. “If the power goes out and the lights go out, we always go outside - then at least there’s some wind. A hot wind.”

In addition, people in some places are complaining about a lack of water: the water level in dozens of reservoirs has fallen to a fraction of their storage capacity, the Indian television station NDTV recently reported, citing the country’s central water authority.

**“This summer it feels like we are living in hell”**

Authorities in India and neighboring Pakistan therefore took measures: Schools were temporarily closed, zoos were told to hose down animals with cool water. In the western Indian city of Ahmedabad, authorities had thousands of roofs in poorer districts painted with paint that reflects the sun’s rays several years ago, according to local media. This has led to a certain reduction in temperature.

In the southern Pakistani city of Dadu, resident Meer Shahdad Laghari reports that authorities are distributing fruit juices and cold water to passers-by due to the current heatwave. "We have experienced such extreme heat before, but never for so long.  
This summer it feels like we’re living in hell,” complains the 29-year-old. He fears that he will soon have to leave his city if it is regularly hit by such extreme temperatures in the future.

Translated from: [Indien und Pakistan: Wie halten Menschen Temperaturen von 50 Grad aus? - DER SPIEGEL](https://www.spiegel.de/ausland/indien-und-pakistan-wie-halten-menschen-temperaturen-von-50-grad-aus-a-4806a0e0-21e8-42b6-a915-ca762778faa8)

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [June 9, 2024, 11:09pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/17 "2024-06-09T23:09:54Z")

</div>

I have put in the code for the relative annual increase in CO2.

```julia
# Create array for yearly increment of co2
yearlyco2pctinc = similar(yearly1959co2arr)
let k # runs faster in local scope
    for k = 1:length(yearlyco2pctinc)
        if k == 1
            yearlyco2pctinc[k] = 1.0
        else
            yearlyco2pctinc[k] = yearly1959co2arr[k] / yearly1959co2arr[k-1]
        end
    end
end
plot(1959:(1959+(totalnumofyears-1)),yearlyco2pctinc,
    title="Annual (relative) increment of CO2",legend=false) |> display
histogram(yearlyco2pctinc, title="Annual (relative) increment of CO2",
label="Annual Gain", 
bins=range(1.0, 1.01, length=11), yrange=(0,310),
xticks=1.0005:0.001:1.0095, yticks=0:25:300,
normalize=:pdf, color=:gray) |> display

```

With the resulting two plots

 ![plot_151](https://global.discourse-cdn.com/julialang/original/3X/a/e/ae0f9125ea84f24e33c7a1558411697a7ab1718e.jpeg)

 ![plot_152](https://global.discourse-cdn.com/julialang/original/3X/9/a/9ac886b5fac99d6bd9c3c39bf4874e60a35539b6.jpeg)

It shows that the most common increase is 0.45% (1.0045) annually

---

<div class="post-metadata">

### Author: ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)
#### Post date: [June 10, 2024, 12:10am UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/18 "2024-06-10T00:10:58Z")

</div>

It’s lower humidity. Keep your RH at 50% in your home in the winter (as long as you don’t get condensation on the windows).

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [June 12, 2024, 7:20pm UTC](https://discourse.julialang.org/t/earths-co2-level-is-increasing-julia-code-to-plot-it-yourself/115356/19 "2024-06-12T19:20:56Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
