Photosynthesis is the process by which plants, algae, and some bacteria use sunlight, water and carbon dioxide to produce oxygen and energy in the form of ATP and NADPH. It takes place in two stages - the light-dependent reactions where energy from sunlight is captured and converted to chemical energy, and the light-independent reactions where carbon dioxide is fixed into organic compounds like glucose. The light reactions take place in the thylakoid membranes inside the chloroplast and use water, light, chlorophyll, and other pigments and proteins to produce ATP and NADPH. These products are then used in the Calvin cycle which occurs in the chloroplast stroma and converts carbon dioxide into carbohydrates like glucose. Many environmental factors