How does a doctor calculation the number of weeks a woman is pregnant?

Multiple ways. There are a few different ways to calculate this. It can be counted at the number of completed weeks after your last menstrual cycle. It can be calculated by the ultrasound measurement of the growing fetus. Once the due date is known (from one of the two methods above), it can be calculated by working backwards from the known due date using a device called a "pregnancy wheel".
Based on LMP. Thje gestational age of a pregnancy is based on the number of weeks from the start of the last normal menstrual period. This also assumes a menstrual cycle of 28 days. The lmp was supposedly chosen as the signficant event a woman could remember, and the date of conception could be variable (and perhaps not very memorable, sorry guys). Or (-3 months + 7 days) works as well for the due date.