んだ/のだ /んです/のです is used when the sentence is concerned with another situation.
Example
son: 行<い>ってきます。I go out.
mother: いってらっしゃい。Have a nice day. (The son came back home at once)
mother: どうしたの。What happened?
son: 雨<あめ>が降<ふ>ってきたんだ。It (has) rained.(So I came back home to take an umbrella with me.)
※んだ/のだ /んです/のです expresses that 雨が降ってきた is concerned with my coming back home=reason.
When you noticed the rain, you can not say 雨が降ってきたんだ/のだ /んです/のです. You should say あっ、雨が降ってきた/きました!. Oh, it (has) rained.