Introduction
The Mexican fruit fly, Anastrepha ludens (Loew) (Diptera: Tephritidae), is an economically important pest with a wide range of hosts, some of which are commercial fruit crops such as mango and citrus (Plummer et al., Reference Plummer, McPhail and Monk1941; Thomas, Reference Thomas2003, Reference Thomas2004; Weens et al., Reference Weens, Heppner and Steck2015), and causes significant economic losses to the agricultural sector (Zapata, Reference Zapata2022). It is an invasive species currently distributed from Mexico to Panama with frequent incursions into the USA (Dupuis et al., Reference Dupuis, Ruiz-Arce, Barr, Thomas and Geib2019; Thomas, Reference Thomas2004). Anastrepha ludens is a holometabolous insect that undergoes marked metamorphosis and four different developmental phases (egg, larva, pupa, and adult). The duration of each phase depends on several factors such as humidity, temperature, the physical and chemical characteristics of the soil, and diapause (Bento et al., Reference Bento, Marques, Costa, Walder, Silva and Parra2010; Moraiti et al., Reference Moraiti, Nakas and Papadopoulos2012; Papanastasiou and Papadopoulos, Reference Papanastasiou and Papadopoulos2014; Ragland et al., Reference Ragland, Fuller, Feder and Hahn2009; Shoukry and Hafez, Reference Shoukry and Hafez1979; Telles-Romero et al., Reference Telles-Romero, Toledo, Hernández, Quintero-Fong and Cruz-López2011). Knowledge of its physiological development, which may be different to that of the chronological age when different pupal development temperatures are used, is important to determine when to irradiate the pupa in the Sterile Insect Technique (SIT) (Jing et al., Reference Jing, Zhang, Dou, Jiang and Wang2019; Resilva et al., Reference Resilva, Barnes and Obra2019a, Reference Resilva, Barnes and Obra2019b). The SIT is an environmentally friendly pest control method which consists in the mass-rearing, irradiation, and release of sterile insects in affected areas (Knipling, Reference Knipling1955).
The transformation from larva to pupa is a complex process triggered by significant biochemical changes (Boccaccio and Quesada‐Allué, Reference Boccaccio and Quesada‐Allué1994; Rabossi et al., Reference Rabossi, Boccaccio, Wappner and Quesada‐Allué1991). As the puparium is a rigid structure formed by the integument of the last larval stage, it serves as a protective casing for the developing pupa and pharate adult (Fraenkel and Bhaskaran, Reference Fraenkel and Bhaskaran1973), and has been found to be one of the most tolerant stages to irradiation (Suhana et al., Reference Suhana, Mohd Shamsudin, Sulaiman, Ahmad Zainuri, Hasan and Yaakop2018). The development of the pupae is not visible to the unaided eye and is important for correct timing of irradiation.
Five pupal developmental stages have been described in another tephritid fly, Bactrocera dorsalis (Hendel) (Diptera: Tephritidae): larval–pupal apolysis, cryptocephalic pupa, phanerocephalic pupa, pharate adult, and emergent adult (Jing et al., Reference Jing, Zhang, Dou, Jiang and Wang2019). In Rhagoletis cerasi (L.) (Diptera: Tephritidae), six most representative stages of pupal development are described (Papanastasiou and Papadopoulos, Reference Papanastasiou and Papadopoulos2014) and three in Ceratitis capitata (Wiedemann) (Diptera: Tephritidae) (Rabossi et al., Reference Rabossi, Wappner and Quesada-Allué1992).
In A. ludens, Thomas and Hallman (Reference Thomas and Hallman2011) distinguished six intrapuparial stages: coarctate larva, cryptocephalic pupa, phanerocephalic pupa, early pharate adult, mid-pharate adult, and late pharate adult, and Hallman and Worley (Reference Hallman and Worley1999) described four stages: prepupa, cryptocephalic pupa, phanerocephalic pupa, and pharate adult. Fundamentally, they are the same, except the first study divides the pharate adult into three stages. The prepupa is the stage that immediately follows pupariation and precedes larval-pupal apolysis. It is also called the coarctate larva and lasts approximately one day. The next stage after larval–pupal apolysis is the cryptocephalic pupa, wherein only the thorax and abdomen are visible because the head is still invaginated, and it lasts approximately one day. The phanerocephalic pupa is the next stage, wherein the head of the pupa has completely evaginated, and lasts approximately 3 days. Finally, the pharate adult includes the rest of the development until adult emergence. This stage is further divided into three stages (early, mid, and late pharate adult). In the early pharate adult, the adult integument has developed and separated (apolysis) from the integument of the pupa but the eyes are not pigmented. In the mid stage, the eyes become pigmented but there is no presence of setae on the body. Finally, in the late stage, the body already exhibits melanized setae (Hallman and Worley, Reference Hallman and Worley1999; Thomas and Hallman, Reference Thomas and Hallman2011).
In tephritid flies of economic importance, eye color has been used to describe pupal development and as an indicator of the physiological age to determine the timing of irradiation in the SIT (González-López et al., Reference González-López, Valenzuela-Carrasco, Toledo-Mesa, Juárez-Durán, Tapia-McClung and Pérez-Staples2022; Resilva and Pereira, Reference Resilva and Pereira2014; Resilva et al., Reference Resilva, Barnes and Obra2019a, Reference Resilva, Hernández and Obra2019b; Ruhm and Calkins, Reference Ruhm and Calkins1981). Sterile A. ludens males are irradiated as pupae 48 h before emergence, thus pupal age has been based on eye color differences during this short period of time, which involves sacrificing the pupae for examination (FAO/IAEA/USDA, 2019). In all these studies, the puparium was dissected and some cases the pupa was fixed in different solutions arresting its development (González-López et al., Reference González-López, Valenzuela-Carrasco, Toledo-Mesa, Juárez-Durán, Tapia-McClung and Pérez-Staples2022; Jing et al., Reference Jing, Zhang, Dou, Jiang and Wang2019; Resilva and Pereira, Reference Resilva and Pereira2014; Resilva et al., Reference Resilva, Barnes and Obra2019a, Reference Resilva, Hernández and Obra2019b; Ruhm and Calkins, Reference Ruhm and Calkins1981). However, the development of the insect can be observed through the puparium using infrared light which is a non-destructive technique that allows the daily observation of the development of the living organism and allows the use or study of that same individual as adult. Near-infrared (NIR) images has been used to study the intrapuparial development of other species of flies (Argilés-Herrero et al., Reference Argilés-Herrero, Salvador-Herranz, Parker, Zacarés, Fall, Gaye, Nawaz, Takác, Vreysen and de Beer2023; Moran and Parker, Reference Moran and Parker2016). NIR images (880, 950, and 1060 nm) were used primarily in the tsetse fly to separate females from males before emergence, the wings of females become pigmented before those of males, which allowed irradiating only the males in the SIT (Argilés-Herrero et al., Reference Argilés-Herrero, Salvador-Herranz, Parker, Zacarés, Fall, Gaye, Nawaz, Takác, Vreysen and de Beer2023; Moran and Parker, Reference Moran and Parker2016). Based on this, we hypothesized that by illuminating the pupa with an infrared light (850–1100 nm), we will be able to quantify morphological characteristics in A. ludens. Therefore, the objective here was to describe the morphological changes during the intrapuparial development of A. ludens through the puparium and obtain a model that classifies the physiological age of the pupa and the adult pharate by ranges, using near-infrared (NIR) images without dissecting the puparium.
Materials and methods
Pupae
Pupae were obtained from the Anastrepha ludens colony established in 2024 at the Institute of Biotechnology and Applied Ecology (INBIOTECA). The colony was started with adults reared from infested bitter oranges (Citrus aurantium L.) collected in the field in La Estanzuela (19°27ʹ48.5″ N, 96°51″13.4″ W), Teocelo (19°23′11″ N, 96°58′20″ W), and Briones (19°30′33″N, 96°56′56″ W) in the municipalities of Emiliano Zapata, Teocelo, and Coatepec, respectively, in Veracruz, Mexico. Adults were placed in 30 × 30 × 30 cm cages made with wooden frames covered with tulle and a stocking. The flies were provided with water and a mixture of sugar and yeast hydrolysate enzymatic in a proportion of 3:1 (MP Biomedicals, Solon, OH, USA). The flies were raised on mango (Mangifera indica L.) and pupae of the second generation were used for the photographs. The pupae were kept in a chamber at 26°C, 75–80% relative humidity, and 24 h darkness throughout the study.
Acquisition of photographs
Equipment
Photographs were taken with a Canon EOS 7D camera modified for full spectrum photography (Lifepixel.com) using a 60 mm Laowa lens with an IR filter (range: 850 to 1100 nm; Lifepixel Deep BW). The camera was placed on a tripod and an external infrared photography light was used (Andoer IR49S-2000mAh). A 9.5-cm high with an 8-cm diameter Teflon cylinder was placed around the pupae to diffuse the light.
Photographs
The pupae were placed on an IR flock sheet (Koyo oriental Japan Co. Ltd) using a tiny drop of wax to allow the pupa to remain in the desired positions, dorsal, and ventral (Norrbom et al., Reference Norrbom, Korytkowski, Zucchi, Uramoto, Venable, McCormick and Dallwitz2012) (fig. 1).
(a) Dorsal and (b) ventral position of A. ludens pupa with a chronological age of 15 days that was kept at 26°C.

a) Dorsal position: The pupae were placed with the anterior and posterior spiracles pointing down to view the dorsal surface. The eyes, setae on the thorax, and body markings were visible in this position (fig. 1a).
b) Ventral position: The pupae were placed with the anal lobe pointing up. Viewed from above, this position showed the ventral surface where the wings, legs, and eyes were visible (fig. 1b).
The day the puparium was formed (one day after the third-instar larvae), 50 pupae were photographed daily. The first age range was delimited during the first 4 days. As adult emergence was only 12% due to handling, another sample of 30 pupae were photographed daily from day 4 to emergence (83% emergence). The same pupae were always photographed and kept separately in individual boxes until emergence. Each pupa was assigned the physiological age counting backwards from adult emergence. The puparium was not dissected. In addition, a sample of 100 pupae that were not photographed were used as a control to determine adult emergence.
Image processing and application of machine learning
Each photograph contained 10 pupae, each of which was segmented and labeled according to its chronological and physiological age using the open source software Labelme (Wada, Reference Wada2018). Each image of a pupa was individualized and labeled according to its physiological age using Wolfram Mathematica version 14.1 (Wolfram, 2024). A classifier was then trained using transfer learning using as a pre-trained model EfficientNet (trained on ImageNet a database with thousands of images (Muñoz-Amezcua et al., Reference Muñoz-Amezcua, Tapia-McClung and Rao2023; Tan and Le, Reference Tan and Le2019). This convolutional neural network was used to obtain a model that could classify the physiological age of the pupae from the formation of the puparium to the emergence of the adult. An average accuracy of 55.14% was obtained in the training; to increase accuracy, the images were grouped into ranges according to age.
Four chronological/physiological age ranges were established: Range 1 (R1): 1 to 4 d; −17 to −14 d; Range 2 (R2): 5 to 9 d; −13 to −9 d; Range 3 (R3): 10 to 13 d; −8 to −5 d and Range 4 (R4): 14 to 17 d; −4 to −1 d, where −1 corresponds to one day before emergence. Class balancing was carried out by choosing the lowest number of images (1309 which was that of R3), then 1309 images were selected from each range, using 5236 images in total to train the model, including both dorsal and ventral images.
Of the total images, 90% were used to train the network (1178 of each range, 1178 × 4 = 4712 images) and 10% of the images were used to test it (131 × 4 = 524 images). Subsequently, 20 random tests were performed (1 test = 1 model) and each validated with a total of 2740 images independent of those used in the training.
Statistical analysis
The total number of validation images per age range (685) and the coincidences of the model were analyzed by a Generalized Linear Models (GLM) with a Poisson distribution and a log link function, where the response variable was the number of correct images and the independent variable was the physiological age range followed by a post-hoc comparisons test. To determine if there were differences in emergence between the pupae photographed and those that were not a Mann Whitney U test was performed. Analysis were carried out in Jamovi version 2.4.14.
Results
According to the established chronological and physiological age ranges the following morphological characteristics were observed through images taken with NIR.
Range 1 (1–4 d)
Days 1–3: Very soft puparium, small movements still visible, and no structures visible. A bubble-like cavity full of hair appears in the middle part of the dorsal area that is more noticeable than in the ventral position (fig. 2).
Dorsal and ventral position of the Intrapuparial development of A. ludens. The time and morphological characteristics described by Hallman and Worley (Reference Hallman and Worley1999) and Thomas and Hallman (Reference Thomas and Hallman2011) were used as a reference.

Day 4: The head, thorax, and abdomen were observed in the dorsal view of all puparia. A connection between the posterior spiracles and the abdomen was also observed. The legs, wings, and eyes are visible in the ventral position (fig. 2).
Range 2–3 (5–13 d)
Days 5–11: No morphological changes are observed through the images (fig. 3a).
Pupal development of A. ludens. (a, b, e) Dorsal and (c, d) ventral position.

Days 12–13: Darkening of the eyes (fig. 3b).
Range 4 (14–17 d)
Day 14: Darkening of the wings begins (6.6%) (fig. 3c).
Day 15: Darkening of the legs and presence melanized setae on the thorax (fig. 3d and 3e).
Day 18: 83% of adults emerged and emergence ended the following day, 17% of adults did not emerge (fig. 2).
In the case of the pupae that were not photographed, emergence occurred between the 17th and 19th day (94 % of adults emerged). There were no significant differences in the emergence of pupae photographed from the fourth day onwards and those not photographed (Mann Whitney U = 1355, P = 0.111, n1 = 30, n2 = 100).
The machine learning model’s average accuracy was 71.77% over 20 models that were trained. A confusion matrix was elaborated, indicating the number of successes and errors of the trained model. Each row represents the physiological age range. The diagonal cells correspond to images correctly labeled by the model, while the other entries indicate the number of images that were misclassified according to age range. For example, out of the total of 685 images in R1, the model correctly classified 593 images and incorrectly classified 92 in R2 (fig. 4). The model with maximum accuracy was of 73.4%. Although there were significant differences between the correct identification of the age ranges (χ2 = 159, df = 3, P < 0.001), the range with the highest successes was R1 (1–4 d), which corresponds to the first four days of chronological age (table 1). There were significant differences between R1 and R3 (z = 10.89, P < 0.001), R2 and R3 (z = 9.90, P < 0.001) and R3 and R4 (z = −9.71, P < 0.001).
Confusion matrix of trained network using NIR images of A. ludens, indicating number of successes and errors of the trained model. Each row represents the physiological age range. The diagonal cells correspond to images correctly labeled by the model, while the other entries indicate the number of images that were misclassified according to age range.

Successful identification by the machine learning model for each physiological age range of Anastrepha ludens. Percentage success indicates accuracy of the model in identifying the age of the pupa

Discussion
In this study, we trained a machine learning model that classify a pupa or a pharate adult in a physiological age range using images taken with NIR light with an average 71.77% accuracy. This percentage is close to results obtained by analyzing the late pharate adult, which was 76.5% (González-López et al., Reference González-López, Valenzuela-Carrasco, Toledo-Mesa, Juárez-Durán, Tapia-McClung and Pérez-Staples2022). However, that study only used the last 5 days before emergence, based on eye color as a reference and an invasive procedure by opening the puparium.
The age range with the highest accuracy was R1 (1–4 d), which corresponds to the first 4 days. However, the differentiation of the head, thorax and abdomen, both dorsal and ventral between days 1 and 3 was not observed. During this period the prepupa and cryptocephalic pupa develop (Hallman and Worley, Reference Hallman and Worley1999). We could not differentiate these early stages through the images used. While they describe a phanerocephalic pupa on the third day, we can observe it on the fourth day.
Subsequently, R2 (5–9 d) and R4 (14–17 d) age ranges have very similar accuracies, 81% and 80%, respectively, which means that the model can differentiate between the mid and late pharate adult (Hallman and Worley, Reference Hallman and Worley1999; Thomas and Hallman, Reference Thomas and Hallman2011). The late pharate adult has more noticeable morphological characteristics than the mid pharate adult, such as the eyes, setae, and wings, because these structures have become pigmented (Hallman and Worley, Reference Hallman and Worley1999; Thomas and Hallman, Reference Thomas and Hallman2011). R3 (10–13 d) is the range where the model presented the most errors, with an accuracy of only 38.68%. The majority of errors were misclassified in the R2 range instead of R3, which may be due to similarities of the pharate adult in both ranges. In R2 no notable characteristics were observed.
The emergence of adults began on day 18 in photographed pupae, 2 days after that reported by Resilva et al. (Reference Resilva, Hernández and Obra2019b) at the same temperature (26°C). This difference may be attributed to differences in strains, as that study was carried out with pupae from a 10-year-old laboratory colony, while the pupae we used were from a recently established wild colony (approximately 6 months old). Furthermore, larvae from the laboratory colonies were fed on protein-rich artificial diets (torula yeast, sugar, preservatives and bulking agents) as opposed to mango which was used in this study. Differences in development between laboratory colonies and wild strains can also be due to the host, habitat, and geographical region (Vargas and Carey, Reference Vargas and Carey1989). This difference could also be due to the daily handling of the pupae throughout the intrapuparial period. We observed that the puparium in the first 3 days is very soft, and its handling should be avoided, since it is very likely that the phanerocephalic pupa will not develop. In this study, 88% of the pupae photographed in the first 4 days of pupation did not emerge. Likewise, photographed pupae of Anastrepha fraterculus (Wiedemann) (Diptera: Tephritidae) had high mortality during early pupal development (approximately 90 %); this could be due to handling or to sensitivity to light as pupae generally remain buried in the soil (Jahnke et al., Reference Jahnke, Gebbers, Zanotta and Intreβ2021). Thus, one caveat of the method proposed here is the low resolution at the early pupal stages, and possible non-emergence of the adult if pupae are handled during the first four days of development. Photographing pupae at later stages had no discernable detrimental effects, as there were no significant differences in the emergence of photographed pupae and those that were not photographed. Without exposing the pupa or the pharate adult, we determined key morphological characteristics during development using NIR images. For example, the phanerocephalic pupa (R1, 4 d); the darkening of the eyes (mid pharate adult) (R3, 12–13 d), and the presence of setae on the thorax and the pigmentation of the wings (late pharate adult) (R4, 14–15 d). The wing pigmentation allowed us to estimate the percentage of emergence, since the pharate adult that were not pigmented did not emerge. This technique also allows us to detect non-viable pupae on the 4th day because they appear empty.
The implementation of machine learning methods and NIR images based on morphological characteristics (melanization of organs) has allowed the separation of sexes in the Tsetse fly (Argilés-Herrero et al., Reference Argilés-Herrero, Salvador-Herranz, Parker, Zacarés, Fall, Gaye, Nawaz, Takác, Vreysen and de Beer2023). This leads to a reduction in the time invested in manual separation, in the damage caused by chilling at the time of separation and transportation and in general in the loss of biological material, very important advantages in the programs of the SIT (Argilés-Herrero et al., Reference Argilés-Herrero, Salvador-Herranz, Parker, Zacarés, Fall, Gaye, Nawaz, Takác, Vreysen and de Beer2023). Machine learning algorithms are increasingly used in various fields, but in entomology, they have been applied to insect identification as well as the estimation of age, instar stage, and in the differentiation between sterile laboratory and fertile wild Tsetse flies using NIRs (Gao et al., Reference Gao, Xue, Qin, Li, Liu, Zhang and Li2024; Johari et al., Reference Johari, Khairunniza-Bejo, Shariff, Husin, Basri and Kamarudin2022; Pagabeleguem et al., Reference Pagabeleguem, Da, Somé, Avelessi, Djegbe, Yoda, Bagayogo, Maïga, Churcher and Dabiré2025; Salifu et al., Reference Salifu, Ibrahim and Tonnang2022; Zhang et al., Reference Zhang, Qu, Zhou, Chen, Ngando, Yang, Xiao, Guo, Cai and Zhang2024). NIRs is another non-invasive and non-destructive technique that provides information of the chemical composition of the sample (Dowell et al., Reference Dowell, Parker, Benedict, Robinson, Broce and Wirtz2005; Johnson and Naiker, Reference Johnson and Naiker2020; Ntamatungiro et al., Reference Ntamatungiro, Mayagaya, Rieben, Moore, Dowell and Maia2013). However, in A. ludens further studies are needed on the last four days of development to determine the appropriate physiological age to be able to irradiate in the SIT without opening the puparium.
The use of machine learning methods and infrared images can be useful to determine the physiological age of insects. The error levels in image interpretation depend on the degree of development of the pharate adult. The technique depends heavily on the appearance of melanized or pigmented organs or structures, but it provides us with a method that does not require opening the puparium. The advantage of using this technology is that the pupa or the pharate adult are not killed and thus individuals can be followed, studied or released as adults, thus this methodology could be an alternative to minimizing invasive techniques. In forensic entomology, the duration of the intrapuparial period, the intrapupal development time, and the morphological characteristics of each stage are studied to determine the species of fly found on human corpses. The age of the immature stage and the fly species are used to estimate the postmortem interval known as PMI (Barros-Cordeiro et al., Reference Barros-Cordeiro, Pujol-Luz and Báo2021; Li et al., Reference Li, Zhang, Chen, Guo, Wang, Hu, Kang, Wang and Wang2023; Pujol-Luz et al., Reference Pujol-Luz, Francez, Ururahy-Rodrigues and Constantino2008). This technique would allow for the specific study of pigmented macromorphological structures and the chronology of intrapupal development as an additional tool in forensic science.
In the future, this methodology could also be applied in mass-rearing to determine viability of pupae at different time points, that is pupae capable of developing favorably, without the need to wait until emergence. It remains to be seen if this technology can be used with pupae of different colours such as the genetically sexed strain of A. ludens (Tapachula-7) where for example, the male pupae are brown and females black or the Temperature Sensitive Lethal strain (TSL) in C. capitata. It could also be used to study the intrapuparial period in species that enter diapause, about which little is known (Norrbom et al., Reference Norrbom, Castillo-Meza, García-Chávez, Aluja and Rull2014). In addition, this technique could be used in other lines of research, such as determining the age of the pupae for the optimal development of pupal parasitoids used in biological control. It would also allow us to know if a pupa is parasitized or super-parasitized.
Acknowledgements
We thank Raúl Márquez Luján, Abraham Moreno Mejía, Betzabé Verónica Murrieta, and Ana M. Salazar Suárez for their technical assistance and Zully Pelayo Rivera (Fondo de Empresas de la Universidad Veracruzana A.C.) for administrative support. GCG thanks SECIHTI for a postdoctoral scholarship (5973309). This study was funded by the International Atomic Energy Agency, Individual Research Contract (28219) awarded to H.T.M.
Competing interests
None.